diff --git a/fish/add-on.fish b/fish/add-on.fish index 56a026e..e56f02e 100644 --- a/fish/add-on.fish +++ b/fish/add-on.fish @@ -110,34 +110,6 @@ function restore_cursor --on-event fish_postexec tput cnorm end -## 让 sudo 能够识别自定义 bin 下的脚本 -function sudo --description "Replacement for sudo that preserves custom PATH commands" - # 1. 如果没有任何参数,直接运行原始 sudo (通常显示帮助) - if not set -q argv[1] - command sudo - return - end - - # 2. 如果第一个参数是以 "-" 开头的选项 (比如 -i, -s, -u, -E) - # 我们直接把所有参数原样传给真正的 sudo,不做路径解析 - if string match -q -- "-*" $argv[1] - command sudo $argv - return - end - - # 3. 如果第一个参数是普通的命令名 (比如 zp, apt, vim) - # 使用 type -p 获取其完整路径。使用 -- 防止命令名本身带杠导致 type 报错 - set -l command_path (type -p -- $argv[1] 2>/dev/null) - - if test -n "$command_path" - # 找到了完整路径,调用真正的 sudo 运行该绝对路径 - command sudo $command_path $argv[2..-1] - else - # 没找到路径(可能是内建命令或拼写错误),直接交给真正的 sudo 处理 - command sudo $argv - end -end - function portcheck # 设置起始端口,如果没有传入参数则默认为 8840 set -l port 8840