RSS Comments for bash programmable completion

02 Jan 2004 02:50 romildo

~ completion
I have noticed that with the bash-completion package loadead, the completion of "~" differs from the original bash completion, in that it is replaced by what it means (the user home directory). I would like to keep the original "~" character in the command line, instead of replacing it with the actual directory it represents, when running bash-completion. Is that possible? How?

Regards.

31 Dec 2003 17:06 ianmacd

Re: Ant Completion

> The ant completion code presumes that
> the first XML parameter to the
> "target" tag will be
> "name".
>
> Some of my build.xml files don't have
> this order (if you use NetBeans to edit
> the build.xml using the ant tools, the
> "name" will be the last
> parameter).
>
> Below a path that works for me (I know
> it's not as good as it could be):
>
> --- /tmp/bash_completion.old
> 2003-12-26 21:37:11.000000000 -0300
> +++ /etc/bash_completion
> 2003-12-26 21:35:20.000000000 -0300
> @@ -2768,6 +2768,8 @@
> COMPREPLY=( $( awk
> -F'"' '/<target name="/
> {print $2}' \
>
> $buildfile | grep "^$cur" )
> $( awk
> -F"'" "/<target
> name='/ "'{print $2}' \
> +
> $buildfile | grep "^$cur" )
> + $( awk
> -F'"' '/<target [^n]/ {if ($1 ~
> /name=/) { print $2 } else if ($3 ~
> /name=/) {print $4} else if ($5 ~
> /name=/) {print $6}}' \
>
> $buildfile | grep "^$cur" ) )
> fi
> }
>

Can you please send this to me directly as a unified diff?

Cheers,

Ian

26 Dec 2003 16:44 itamarc Thumbs up

Ant Completion
The ant completion code presumes that the first XML parameter to the "target" tag will be "name".

Some of my build.xml files don't have this order (if you use NetBeans to edit the build.xml using the ant tools, the "name" will be the last parameter).

Below a path that works for me (I know it's not as good as it could be):

--- /tmp/bash_completion.old 2003-12-26 21:37:11.000000000 -0300
+++ /etc/bash_completion 2003-12-26 21:35:20.000000000 -0300
@@ -2768,6 +2768,8 @@
COMPREPLY=( $( awk -F'"' '/<target name="/ {print $2}' \
$buildfile | grep "^$cur" )
$( awk -F"'" "/<target name='/ "'{print $2}' \
+ $buildfile | grep "^$cur" )
+ $( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \
$buildfile | grep "^$cur" ) )
fi
}

10 Dec 2003 23:16 jidar

Re: cd does not add trailing slashes if going thru CDPATH

> This is very bizarre. Does 'complete -r
> cd' fix it, too? The completion system
> should have nothing to do with a
> non-interactive command like make.

>make
make all-recursive
make[1]: Entering directory `/home/jidar/src/gaim'
Making all in sounds
/bin/sh: line 1: cd: sounds: No such file or directory

>complete -r cd
>make
make all-recursive
make[1]: Entering directory `/home/jidar/src/gaim'
Making all in sounds
/bin/sh: line 1: cd: sounds: No such file or directory

short answer: no. Oddly, this has caused more problems and Its something I comment out for general use. Although, its a feature I'd very much like to use.

20 Nov 2003 19:38 ianmacd

Re: cd does not add trailing slashes if going thru CDPATH

>
> %
> % %
> % % % I'm running 2.05b; I'm behind
> % % already?
> % %
> % %
> % % You need to install the official
> % patches
> % % to 2.05b. That will fix the lack of
> % % trailing slash issue.
> %
> %
> %
> % I'm not sure why, but for some reason
> % when I try and compile code with my
> % $CDPATH variables set, I often get
> % errors where it can't 'cd' to the
> % correct directory, and bails saying
> that
> % dir dosen't exist. This is the
> correct
> % response:
> %
> % user@host> make
> % cd lib/ && make lib
> % make[1]: Entering directory
> % `/home/jidar/src/proftpd-1.2.9/lib'
> %
> % and with CDPATH and bash_completion
> % loaded..
> % user@host> . /etc/bash_completion
> % user@host> export
> % CDPATH=/var/www/htdocs
> % user@host> make
> % cd lib/ && make lib
> % /bin/sh: line 1: cd: lib/: No such
> file
> % or directory
> %
> % I just compiled my own version of
> bash,
> % and applied all 7 patches.
> %
>
>
>
> I think a simple fix to this might be,
> alias make='unset CDPATH && make && .
> ~/.bash_profile'

This is very bizarre. Does 'complete -r cd' fix it, too? The completion system should have nothing to do with a non-interactive command like make.

14 Nov 2003 19:40 jidar

Re: cd does not add trailing slashes if going thru CDPATH

>
> %
> % % I'm running 2.05b; I'm behind
> % already?
> %
> %
> % You need to install the official
> patches
> % to 2.05b. That will fix the lack of
> % trailing slash issue.
>
>
>
> I'm not sure why, but for some reason
> when I try and compile code with my
> $CDPATH variables set, I often get
> errors where it can't 'cd' to the
> correct directory, and bails saying that
> dir dosen't exist. This is the correct
> response:
>
> user@host> make
> cd lib/ && make lib
> make[1]: Entering directory
> `/home/jidar/src/proftpd-1.2.9/lib'
>
> and with CDPATH and bash_completion
> loaded..
> user@host> . /etc/bash_completion
> user@host> export
> CDPATH=/var/www/htdocs
> user@host> make
> cd lib/ && make lib
> /bin/sh: line 1: cd: lib/: No such file
> or directory
>
> I just compiled my own version of bash,
> and applied all 7 patches.
>

I think a simple fix to this might be,
alias make='unset CDPATH && make && . ~/.bash_profile'

14 Nov 2003 19:14 jidar

Re: cd does not add trailing slashes if going thru CDPATH

>
> % I'm running 2.05b; I'm behind
> already?
>
>
> You need to install the official patches
> to 2.05b. That will fix the lack of
> trailing slash issue.

I'm not sure why, but for some reason when I try and compile code with my $CDPATH variables set, I often get errors where it can't 'cd' to the correct directory, and bails saying that dir dosen't exist. This is the correct response:

user@host> make
cd lib/ && make lib
make[1]: Entering directory `/home/jidar/src/proftpd-1.2.9/lib'

and with CDPATH and bash_completion loaded..
user@host> . /etc/bash_completion
user@host> export CDPATH=/var/www/htdocs
user@host> make
cd lib/ && make lib
/bin/sh: line 1: cd: lib/: No such file or directory

I just compiled my own version of bash, and applied all 7 patches.

07 Oct 2003 00:12 ianmacd

Re: Wonderful... but...

> I LOVE bash_completion, but I think that
> it is growing
> just a tad too big... and a little
> unmanageable.
> Spesific gripes:
> 1) If $UNAME isn't tested explicitly for
> an OS that
> doesn't return xyz then feature abc
> which worx, is not
> completed upon. I'm not sure how this is
> fixable, its just
> a comment. :-)
> 2) some of the functions and completions
> seem to be
> slightly more complex than neccessary.
> What I mean is
> that I don't see the need to redefine
> the builtin
> completions if the builtin ones work.
> 3) It seems to be very linux spesific,
> although almost all
> worx on freeBSD it checks vigorously for
> linux in
> $UNAME.
>
> Thanx, keep up the good work!

I'll deal with your numbered comments in turn. First, though, I'll respond to your remark that the project is becoming too big and unmanageable.

This is a fair comment. There is some inconsistency in coding style throughout the file, which is the result of the fact that bash completion these days is the work of many different people. As far as formatting is concerned, a version of indent(1) for Bourne shell code would be great, but doesn't exist.

I think I'm doing a reasonable job of managing the code in the file, but I will agree that the file as a whole is unwieldy. It would definitely be better if it could be split into multiple files, but I don't see a great enough benefit to doing this until such time that bash supports loadable functions.

Otherwise, there's some administrative gain, but the extra overhead of parsing dozens and dozens of small files.

Now to your numbered comments:

1. $UNAME is there to ensure that certain commands that are known to work differently on different platforms behave as expected when the completion routine is written primarily for one or two specific operating systems.

If you know of specific instances of over-conservative code, where programmable completion is excluded for a platform that you know it would work with, please let me know about it and preferably send a patch.

2. A lot of the functions need to be more complex than you might at first think. _cd() is a good example of this. Standard completion doesn't offer you a lot of features, but in the case of _cd(), you get to complete on directories defined in $CDPATH. If you don't use $CDPATH, this might seem like overkill, but to other people, it's invaluable.

3. Please send me a list of commands for which there are completions that currently default to doing nothing on FreeBSD, but which would work absolutely fine if enabled. In other words, I'd like to know about cases where the code for FreeBSD is identical to the Linux code.

07 Oct 2003 00:00 ianmacd

Re: cd does not add trailing slashes if going thru CDPATH

> I'm running 2.05b; I'm behind already?

You need to install the official patches to 2.05b. That will fix the lack of trailing slash issue.

05 Oct 2003 02:14 Avatar gaelicWizard Thumbs up

Wonderful... but...
I LOVE bash_completion, but I think that it is growing
just a tad too big... and a little unmanageable.
Spesific gripes:
1) If $UNAME isn't tested explicitly for an OS that
doesn't return xyz then feature abc which worx, is not
completed upon. I'm not sure how this is fixable, its just
a comment. :-)
2) some of the functions and completions seem to be
slightly more complex than neccessary. What I mean is
that I don't see the need to redefine the builtin
completions if the builtin ones work.
3) It seems to be very linux spesific, although almost all
worx on freeBSD it checks vigorously for linux in
$UNAME.

Thanx, keep up the good work!

Screenshot

Project Spotlight

Vrapper

An Eclipse plugin which provides a Vim-like input scheme for text editors.

Screenshot

Project Spotlight

PHP Mini SQL Admin

A standalone script for accessing MySQL databases.