aris aris - 4 months ago 13x
Bash Question

How to hide files with certain extensions in the fish shell?

I don't want to see .pyc files when I do the ls command from within the fish shell. With bash I could do an alias. With fish I tried putting the following into ~/.config/fish/

function ls
command ls --hide="*.pyc"

But it doesn't work. I get

ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]


The problem is that you're apparently using the BSD ls command. On Mac OS X I get the same error because /bin/ls doesn't recognize any long options. On OS X do brew install coreutils to get the GNU ls which does support --hide.

Also, you probably want the body of your function to be

command ls --hide="*.pyc" $argv

You can also have your function behave differently depending on such things as whether or not the output is going to a tty. Here's my function:

function ls --description 'List contents of directory'
    set -l param --color=auto
    if isatty 1
        set param $param --indicator-style=classify
    command ls $param $argv