鱼壳:将参数附加到现有函数

mde*_*tis 2 shell fish

我想添加--group-directories-firstls命令。如果~/.config/fish/config.fish我可以定义这样的别名:

alias ls "ls --group-directories-first"
Run Code Online (Sandbox Code Playgroud)

但它会覆盖鱼壳的ls函数定义:

function ls --description 'List contents of directory'
    set -l param --color=auto
    if isatty 1
        set param $param --indicator-style=classify
    end
    command ls $param $argv
end
Run Code Online (Sandbox Code Playgroud)

我可以重新定义ls函数以添加所需的参数:

function ls --description 'List contents of directory'
    set -l param --color=auto --group-directories-first
    if isatty 1
        set param $param --indicator-style=classify
    end
    command ls $param $argv
end
Run Code Online (Sandbox Code Playgroud)

但是我不喜欢这种解决方案:我想要的是重新定义ls以便ls使用参数调用前一个函数。有办法做到吗?

gle*_*man 5

您可以重命名 copy fish的ls函数:

functions --copy ls __fish_ls
Run Code Online (Sandbox Code Playgroud)

然后在函数中使用它:

alias ls '__fish_ls --group-directories-first'
Run Code Online (Sandbox Code Playgroud)