add fish config
This commit is contained in:
@@ -80,15 +80,28 @@ end
|
|||||||
|
|
||||||
## 让 sudo 能够识别自定义 bin 下的脚本
|
## 让 sudo 能够识别自定义 bin 下的脚本
|
||||||
function sudo --description "Replacement for sudo that preserves custom PATH commands"
|
function sudo --description "Replacement for sudo that preserves custom PATH commands"
|
||||||
# 获取命令的完整路径(比如输入 zp,它会返回 /home/user/.flinty/bin/zp)
|
# 1. 如果没有任何参数,直接运行原始 sudo (通常显示帮助)
|
||||||
set -l command_path (type -p $argv[1])
|
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"
|
if test -n "$command_path"
|
||||||
# 如果找到了完整路径,就用完整路径调用真正的 sudo
|
# 找到了完整路径,调用真正的 sudo 运行该绝对路径
|
||||||
# $argv[2..-1] 表示把剩下的参数原样传递
|
|
||||||
command sudo $command_path $argv[2..-1]
|
command sudo $command_path $argv[2..-1]
|
||||||
else
|
else
|
||||||
# 如果找不到(比如 sudo apt),就按原样执行
|
# 没找到路径(可能是内建命令或拼写错误),直接交给真正的 sudo 处理
|
||||||
command sudo $argv
|
command sudo $argv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user