Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending `ls` function

Tags:

fish

Normally on Windows, I alias ls to

alias ls="ls -hNFCs --color=auto -I NTUSER.DAT\* -I ntuser.dat\*"

This removes the NTUSER.DAT files from my view when I ls my home directory along with setting some reasonable defaults.

However, doing the same with fish, I noticed my .dircolors are not being read. It is because ls.fish loads up .dircolors but when I override it with the alias it loses that capability.

So my question is, how do I extend the default ls.fish just to add my extra parameters?

The closest thing I can do is copy the ls.fish file and modify the relevant portion

  function ls --description "List contents of directory" -V opt
            isatty stdout
            and set -a opt -F
            and set -a opt -hNFCs -I NTUSER.DAT\* -I ntuser.dat\*
            command ls $opt $argv
        end
like image 820
Archimedes Trajano Avatar asked Sep 14 '26 15:09

Archimedes Trajano


1 Answers

Just copying the function is indeed the thing to do. funced ls can help with this.

Adding a way to extend functions is much too easy to break - where do you allow extensions, how do you ensure arbitrary extensions don't break when you make a change,...

So just copying is nice and simple, especially for a function that's unlikely to be called anywhere else like ls (because you don't want to parse ls' output)

like image 126
faho Avatar answered Sep 17 '26 16:09

faho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!