On 26/04/15 21:57, Denis Pithon wrote: > 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 ?
Thanks for the considered suggestion. Points 1 and 3 above could probably be handled with: ls -l $(sed "s/'/_/g; s/.*/--hide '&'/" .lsignore | tr '\n' ' ') Point 2 (--recursive) is the main reason one might consider this as a new option. I'm 60:40 against adding it, since I've rarely needed the --hide option, and much less with --recursive. thanks, Pádraig.
