[Bash-completion-devel] Bug#521407: bash-completion: no completion for ls with variables

David Paleino d.paleino at gmail.com
Sat Apr 4 20:49:26 UTC 2009

On Fri, 27 Mar 2009 12:50:52 +0100, debian at ginguppin.de wrote:

> Package: bash-completion
> Version: 20080705
> Severity: normal
> echo $OL<TAB>
> expands to
> echo $OLDPWD
> ls $OL<TAB>
> does nothing

Raising this here before acting :)

Currently (i.e. commit 9f05078), ls completion is being defined at line 4274,
together with other commands:

for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \
         bison diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \
         touch vdir awk gperf grep grub indent less m4 sed shar date \
         tee who texindex cat csplit cut expand fmt fold head \
         md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \
         uniq wc ldd bash id irb mkdir rmdir; do
  have $i && complete -F _longopt $filenames $i

Now, to fix the quoted bug, we have two ways of handling it:

1) assume that the user can set whatever she wants in an environment variable
   (and that's true! -- I mean, files, directories, options, [..]), the fix
   would then be adding "-v" handling to _longopt();

2) specially treat ls(1) (but then again, I can't see why one can't do "diff
   $one $two", having defined those variables before), and make a _ls()
   function, which has -v.

3) do nothing, and leave the bug as wontfix.

I'm /slightly/ in favour of 3 -- but if we want to complete, I'd vote for 1.
That "slightly" means that I just don't want the completion to be cluttered by
env vars. A quick example I have in mind:

_longopt() {
  if [[ "$cur" == -* ]]; then
  elif [[ $(dequote "$cur") == "\$"* ]]; then
    COMPREPLY=( $( compgen -v -P '$' -- "${cur//\$/}" ) )
  elif [[ "$1" == rmdir ]]; then

that doesn't work because the $ gets escaped, so one ends up with "ls
\$OLDPWD", which doesn't work (obviously). I'm too tired to dig into the code,
so if someone knows the reason why, is welcome :)

However, I'd wait for some discussion on this. Your opinions? :)

 . ''`.  Debian maintainer | http://wiki.debian.org/DavidPaleino
 : :'  : Linuxer #334216 --|-- http://www.hanskalabs.net/
 `. `'`  GPG: 1392B174 ----|---- http://snipr.com/qa_page
   `-   2BAB C625 4E66 E7B8 450A C3E1 E6AA 9017 1392 B174
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20090404/60aa90ba/attachment.pgp 

More information about the Bash-completion-devel mailing list