coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Enhancement to ls: introducing .lsignore file


From: Denis Pithon
Subject: Enhancement to ls: introducing .lsignore file
Date: Sun, 26 Apr 2015 22:57:23 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Hello,

I looked for a way to ignore files on a per directory basis with `ls` command.
For example: in some directories (not all) I want to hide __pycache__ / *.pyc
items. In other ones, I would like not to list object files *.o and so on...
How could I provide --hide option dynamically, depending of the directory `ls`
is processing ?

One could imagine .lsignore files "a la" .gitignore. Each time `ls` process a
directory (say dir/), it looks for dir/.lsignore file and temporarily update
the --hide options with its content.

I first tried with an alias (100% shell, no sed/cat) :

alias lsi='ls $([ -e .lsignore ] && while read file ; do printf -- "--hide %s " 
"$file" ; done < .lsignore)'

But:
1. It is very shell dependant (work on bash, but not on csh/ksh not tried with
   sh/zsh).
2. It looks .lsignore only once (in the current directory) and applied
   it globally. 
3. Moreover, I'm not sure it is very secure (ie: malicious code in .lsignore)

So, I checkout coreutils source code, and append a few line of codes to ls.c to
provide such a feature. It is activated by a new option '--hide-lsignore' and
could be used alongside --hide. It updates (if needed) hide_patterns when
entering print_dir() and restore it on leaving.

Is there any interest for a patch or any suggestions ?

Regards
denis



reply via email to

[Prev in Thread] Current Thread [Next in Thread]