shell - fish shell : append argument to an existing function

标签 shell fish

我想将 --group-directories-first 添加到 ls 命令。如果在 ~/.config/fish/config.fish 中,我可以定义一个像这样的别名:

alias ls "ls --group-directories-first"

但它覆盖了 Fish shell 的 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

我可以重新定义 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

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

最佳答案

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

functions --copy ls __fish_ls

然后在您的函数中使用它:

alias ls '__fish_ls --group-directories-first'

关于shell - fish shell : append argument to an existing function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48251960/

相关文章:

bash - 将bash转换为fish函数(在fish中使用rga-fzf)

terminal - 如何测试命令的结果是否包含 fish shell 中的字符串?

gnu-screen - fish shell -在 screen 的窗口标题中显示当前命令

linux - fish 中的配置

linux - 创建多个子进程时出现问题

bash - CSV 复制/复制第一行到表格

bash - 提示用户选择带有 bash 脚本的目录并读取结果

linux - Shell 脚本 - 如何合并两个文本文件而不重复行

linux - 引用参数字符串 Shell

shell - 使用fish shell修改PATH