# Fast commands management function ff # 定义命令和描述(格式:命令|描述) set -l commands \ "reload|Reload fish configuration" \ "edit|Edit custom fish configuration" \ "fish|Change to fish config directory" \ "dotfile|Change to dotfile directory" \ "pon|Enable proxy (proxy on)" \ "poff|Disable proxy (proxy off)" \ "pst|Show proxy status" \ "make|Run dotfile Makefile commands" \ "script|Run script from script directory" \ "s|Alias for script" \ "update|Update dotfile" \ "region|Toggle or set CN_REGION (mirror/proxy region)" \ "ssh|SSH init, copy key + add host config, or copy config to remote" \ "dirsize|Show directory sizes (du wrapper)" \ "pouch|Clone and install pouch to ~/.pouch" \ "help|Show this help message" # 确保 execute-script 可用(在 fish 自动加载前手动引入一次) if not functions -q execute-script set -l execute_script_path ~/.dotfile/fish/functions/execute-script.fish if test -f $execute_script_path source $execute_script_path end end switch $argv[1] case reload # autoload 会缓存函数定义,先清掉 dotfile 里的函数再重载 for __f in ~/.dotfile/fish/functions/*.fish functions -e (basename $__f .fish) 2>/dev/null end source ~/.config/fish/config.fish # fish 对已加载过的 autoload 函数不会在 functions -e 后重新加载, # 必须显式 source 一遍,否则函数(含 ff 自身)会丢失 for __f in ~/.dotfile/fish/functions/*.fish source $__f end set -e __f echo "Fish configuration reloaded!" case edit vim ~/.config/fish/custom.fish case fish cd ~/.config/fish/ case dotfile cd ~/.dotfile case pon set -gx https_proxy http://127.0.0.1:7890 set -gx http_proxy http://127.0.0.1:7890 set -gx all_proxy socks5://127.0.0.1:7890 echo "✓ Proxy enabled" export | grep -i proxy case poff set -e http_proxy set -e https_proxy set -e ftp_proxy set -e all_proxy set -e HTTP_PROXY set -e HTTPS_PROXY set -e FTP_PROXY set -e ALL_PROXY echo "✓ Proxy disabled" export | grep -i proxy case pst export | grep -i proxy case make # 切换到 dotfile 目录执行脚本管理 makefile set -l dotfile_dir ~/.dotfile if test -d $dotfile_dir make -f $dotfile_dir/Makefile.scripts -C $dotfile_dir $argv[2..-1] else echo "Error: Dotfile directory not found at $dotfile_dir" end case script s if not functions -q execute-script source ~/.dotfile/fish/functions/execute-script.fish end execute-script $argv[2..-1] case help echo "Usage: ff " echo "" echo "Commands:" # 自动生成帮助信息 for cmd in $commands set -l parts (string split '|' $cmd) printf " %-10s %s\n" $parts[1] $parts[2] end case update set -l dotfile_dir ~/.dotfile if not test -d $dotfile_dir echo "Error: Dotfile directory not found at $dotfile_dir" return 1 end set -l prev_dir (pwd) cd $dotfile_dir if git pull origin main cd $prev_dir echo "Reloading fish configuration..." ff reload else cd $prev_dir echo "Error: git pull failed, skip reload" return 1 end case ssh # 每次都重新 source,避免 autoload 缓存旧定义 source ~/.dotfile/fish/functions/ff-ssh.fish ff_ssh $argv[2..-1] case dirsize set -l script_path ~/.dotfile/script/dirsize.sh if test -f $script_path bash $script_path $argv[2..-1] else echo "Error: dirsize script not found at $script_path" return 1 end case pouch set -l script_path ~/.dotfile/script/pouch-install.sh if test -f $script_path bash $script_path $argv[2..-1] else echo "Error: pouch-install script not found at $script_path" return 1 end case region if not functions -q region_toggle source ~/.dotfile/fish/functions/region.fish end set -l sub toggle if test (count $argv) -ge 2 set sub $argv[2] end switch $sub case toggle region_toggle case '*' echo "Usage: ff region [toggle]" echo "Unknown subcommand: $sub" end case '*' if test -z "$argv[1]" echo "Error: No command specified" else echo "Error: Unknown command '$argv[1]'" end echo "Run 'ff help' for usage information" end end