diff --git a/dot_config/fish/config.fish b/dot_config/fish/config.fish index 6085b02..f45bbf8 100644 --- a/dot_config/fish/config.fish +++ b/dot_config/fish/config.fish @@ -1,37 +1,35 @@ if status is-interactive - # ========= 命令缩写(仅当目标命令存在)========= - # ls:优先 eza,其次 exa - if type -q eza - abbr ls eza - abbr ll eza -l - abbr la eza -a - abbr lal eza -la - else if type -q exa - abbr ls exa - abbr ll exa -l - abbr la exa -a - abbr lal exa -la - end + # ========= 编辑器环境变量设置 ========== + set -l editor_cmd (if type -q vim; echo vim; else if type -q vi; echo vi; else; end) + test -n "$editor_cmd"; and set -gx EDITOR $editor_cmd + test -n "$editor_cmd"; and set -gx VISUAL $editor_cmd - # cat/cap:优先 bat;仅 batcat 时补 bat 缩写(与其它环境一致) - if type -q bat - abbr cat bat - abbr cap bat -p - else if type -q batcat - abbr cat batcat - abbr cap batcat -p - abbr bat batcat - end - # find:优先 fd;仅存在 fdfind 时(如 Debian/Ubuntu)用其并补 fd 缩写 - if type -q fd - abbr find fd - else if type -q fdfind - abbr find fdfind - abbr fd fdfind - end + # ========= Bash 常用命令增强/替代 ========== + # 工具选择 + set -l ls_cmd (if type -q eza; echo eza; else if type -q exa; echo exa; else; end) + set -l cat_cmd (if type -q bat; echo bat; else if type -q batcat; echo batcat; else; end) + set -l find_cmd (if type -q fd; echo fd; else if type -q fdfind; echo fdfind; else; end) + + # 处理特殊情况:根据选择的工具添加缩写 + test "$cat_cmd" = "batcat"; and abbr bat batcat + test "$find_cmd" = "fdfind"; and abbr fd fdfind + + # 使用 --cmd=cd:让 cd 也具备 zoxide 的跳转能力(交互式对应 cdi) + type -q zoxide; and zoxide init --cmd=cd fish | source + + # 命令缩写配置 + test -n "$ls_cmd"; and abbr ls $ls_cmd + test -n "$ls_cmd"; and abbr ll "$ls_cmd -l" + test -n "$ls_cmd"; and abbr la "$ls_cmd -a" + test -n "$ls_cmd"; and abbr lal "$ls_cmd -la" + test -n "$cat_cmd"; and abbr cat $cat_cmd + test -n "$cat_cmd"; and abbr cap "$cat_cmd -p" + test -n "$find_cmd"; and abbr find $find_cmd type -q rg; and abbr grep rg type -q btop; and abbr top btop type -q tldr; and abbr help tldr + + # ========= 其他工具配置 ========== type -q chezmoi; and abbr cz chezmoi type -q tmux; and abbr tm tmux type -q tmux; and abbr tmn 'tmux new' @@ -41,22 +39,8 @@ if status is-interactive # ========= thefuck:自动命令纠错 ========= type -q thefuck; and thefuck --alias | source - # ========= zoxide:智能目录跳转 ========= - # 使用 --cmd=cd:让 cd 也具备 zoxide 的跳转能力(交互式对应 cdi) - type -q zoxide; and zoxide init --cmd=cd fish | source - - # ========= 编辑器/查看器(优先 vim,否则 vi)========= - # SUDO_EDITOR:供 visudo / sudoedit 等使用;若仍打开 nano,需在 sudoers 中加 Defaults env_keep += "SUDO_EDITOR" - if type -q vim - set -gx EDITOR vim - set -gx VISUAL vim - set -gx SUDO_EDITOR vim - else if type -q vi - set -gx EDITOR vi - set -gx VISUAL vi - set -gx SUDO_EDITOR vi + # ========= fastfetch:启动信息显示(仅在第一次打开 shell 时) ========= + if status --is-login; and type -q fastfetch + fastfetch end - - # ========= fastfetch:启动信息显示 ========= - type -q fastfetch; and fastfetch end