Hiding git ignored files

Some projects that I work with tend to autogenerate a lot of files, autotools projects in particular are very good at that. Most gnome software correctly adds all the autogenerated files to .gitignore files automatically, so git nicely ignores them and you don’t get distracted from the files that actually matter. I like that. What I don’t like is that when I go in the terminal and type ‘ls’ I see all the cruft again. It would be nice if I could hide all gitignored files from ls, and I can! Put the following script somewhere (e.g. ~/.local/bin/hidefiles.sh).

#!/bin/bash
# Hide all files specified in the file .lshide, if it exist if test -f .lshide;
then
 cat .lshide 2>/dev/null | while read line; do
 echo -n "--hide $line "
 done
fi
# Hide all files which git ignores git ls-files --others -i --exclude-standard 2>/dev/null | grep -v / | while read line; do  echo -n "--hide $line "; done

And in your .bashrc add a line like:

alias ls='ls --color $(hidefiles.sh)'

Me no see stupid files no more!

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Hiding git ignored files

Leave a Reply

Your email address will not be published. Required fields are marked *