diff --git a/home/.config/fish/config.fish b/home/.config/fish/config.fish new file mode 100644 index 0000000..d1ad8aa --- /dev/null +++ b/home/.config/fish/config.fish @@ -0,0 +1,89 @@ +fish_add_path "$HOME/go/bin" "$HOME/.bun/bin" + +set -gx EDITOR nvim +set -gx VISUAL nvim +set -gx PAGER less +set -gx MANPAGER "sh -c 'col -bx | bat -l man -p'" + +set -g fish_greeting + +function __prepend_sudo + set -l buffer (commandline) + if test -z "$buffer" + commandline -f up-line + set buffer (commandline) + end + + if test -n "$buffer" + if not string match -qr '^sudo\b' -- "$buffer" + commandline -r "sudo $buffer" + end + commandline -f end-of-line repaint + end +end + +bind \e\e __prepend_sudo +bind \c@ accept-autosuggestion + +set -gx FZF_DEFAULT_OPTS '--height=50% --layout=reverse --border --preview-window=right:60%' +set -gx FZF_DEFAULT_COMMAND 'fd --type f --hidden --follow --exclude .git' +set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND" +set -gx FZF_ALT_C_COMMAND 'fd --type d --hidden --follow --exclude .git' + +alias ..='cd ..' +alias ...='cd ../..' + +function ls + command eza --icons --group-directories-first --git $argv +end + +function l + command eza -la --icons --group-directories-first --git $argv +end + +function ll + command eza -l --icons --group-directories-first --git $argv +end + +function la + command eza -lA --icons --group-directories-first --git $argv +end + +function lt + command eza --tree --level=2 --icons --group-directories-first --git $argv +end + +alias cat='bat --paging=never' +alias rm='gomi' +alias lg='lazygit' +alias vi='nvim' +alias x='ouch decompress' + +if set -q WSL_DISTRO_NAME + alias pbcopy='clip.exe' + alias pbpaste='powershell.exe -noprofile -c Get-Clipboard' + + function keep_current_path --on-event fish_prompt + printf '\e]9;9;%s\e\\' (wslpath -w "$PWD") + end +end + +if status is-interactive + zoxide init fish --cmd cd | source + mise activate fish | source + + set -g direnv_fish_mode eval_after_arrow + direnv hook fish | source + + fzf --fish | source + + set -gx ATUIN_NOBIND true + atuin init fish | source + bind \cr _atuin_search + + starship init fish | source +end + +if test -f ~/.config/fish/config.local.fish + source ~/.config/fish/config.local.fish +end diff --git a/home/.config/fish/functions/yy.fish b/home/.config/fish/functions/yy.fish new file mode 100644 index 0000000..8a2ae35 --- /dev/null +++ b/home/.config/fish/functions/yy.fish @@ -0,0 +1,12 @@ +function yy + set -l tmp (mktemp -t yazi-cwd.XXXXXX) + command yazi $argv --cwd-file="$tmp" + + if set -l cwd (command cat -- "$tmp") + if test -n "$cwd" -a "$cwd" != "$PWD" + builtin cd -- "$cwd" + end + end + + command rm -f -- "$tmp" +end diff --git a/modules/fish.py b/modules/fish.py new file mode 100644 index 0000000..a7af41a --- /dev/null +++ b/modules/fish.py @@ -0,0 +1,45 @@ +import subprocess + +import decman +from decman import File, Module +from decman.plugins.pacman import packages as pacman_packages + + +class FishModule(Module): + def __init__(self, user: str): + super().__init__("fish") + self.user = user + + def files(self) -> dict[str, File]: + return { + f"/home/{self.user}/.config/fish/config.fish": File( + source_file="./home/.config/fish/config.fish", + owner=self.user, + ), + f"/home/{self.user}/.config/fish/functions/yy.fish": File( + source_file="./home/.config/fish/functions/yy.fish", + owner=self.user, + ), + } + + @pacman_packages + def pacman_packages(self) -> set[str]: + return { + "fish", + "fzf", + } + + def after_update(self, store: object) -> None: + result = subprocess.run( + ["getent", "passwd", self.user], + capture_output=True, + text=True, + check=False, + ) + if result.returncode != 0: + decman.error(f"无法读取用户 {self.user} 的 passwd 信息") + return + # passwd 格式: name:x:uid:gid:gecos:home:shell + shell = result.stdout.strip().split(":")[-1] + if shell != "/usr/bin/fish": + decman.prg(["chsh", "-s", "/usr/bin/fish", self.user]) diff --git a/source.py b/source.py index 6c512b6..fb6f7db 100644 --- a/source.py +++ b/source.py @@ -6,7 +6,7 @@ import modules.base import modules.dev import modules.docker import modules.locale -import modules.zsh +import modules.fish USERNAME = os.environ.get("SUDO_USER") if not USERNAME: @@ -17,5 +17,5 @@ decman.modules += [ modules.dev.DevModule(USERNAME), modules.docker.DockerModule(USERNAME), modules.locale.LocaleModule(), - modules.zsh.ZshModule(USERNAME), + modules.fish.FishModule(USERNAME), ]