coreutils
[Top][All Lists]
Advanced

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

Re: Enhancement to ls: introducing .lsignore file


From: Pádraig Brady
Subject: Re: Enhancement to ls: introducing .lsignore file
Date: Mon, 27 Apr 2015 12:34:24 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

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.



reply via email to

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