mdesantis
mdesantis

Reputation: 8517

Fish shell: append argument to an existing function

I want to add --group-directories-first to ls command. If in ~/.config/fish/config.fish I can define an alias like this one:

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

but it overwrites fish shell's ls function definition:

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

I can redefine ls function in order to add the needed argument:

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

But I don't like this solution: what I want is to redefine ls in order to call the previous ls function with an argument. Is there a way to accomplish it?

Upvotes: 3

Views: 356

Answers (2)

user5920427
user5920427

Reputation:

abbr ls "ls --group-directories-first"

??

Upvotes: 2

glenn jackman
glenn jackman

Reputation: 246799

You could rename copy fish's ls function:

functions --copy ls __fish_ls

Then use that in your function:

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

Upvotes: 6

Related Questions