Comments for bash programmable completion
26 Jan 2007 09:24
svn mod: listing targets of imported build files
in bash_completion _ant()
change:
local cur prev buildfile i
to:
local cur prev buildfile imports i f
add:
imports=(
$( awk -F'"' '/<import file="/ {print $2}' \
$buildfile )
$( awk -F"'" "/<target name='/ "'{print $2}' \
$buildfile )
)
for f in ${imports[@]}; do
if [[ -e $f ]]; then
COMPREPLY=( ${COMPREPLY[@]} \
$( awk -F'"' '/<target name="/ {print $2}' \
$f | grep "^$cur" | grep -v '^-' )
$( awk -F"'" "/<target name='/ "'{print $2}' \
$f | grep "^$cur" | grep -v '^-' )
$( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \
$f | grep "^$cur" | grep -v '^-' ) )
fi
done
change:
have complete-ant-cmd.pl && \
complete -C complete-ant-cmd.pl -F _ant $filenames ant || \
complete -F _ant $filenames ant
}
to:
have complete-ant-cmd.pl && \
complete -C complete-ant-cmd.pl -F _ant $filenames ant || \
complete -F _ant ant
}
26 Jan 2007 09:21
cd mod allowing ignore directories
Allows one not to have to deal with '.svn' and
'CVS' directories.
in .bashrc
cdignore=( CVS .svn )
in bash_completion _cd() add:
if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then
_filedir -d
if [[ -n "$cdignore" ]]; then
k=0
a=()
for f in ${COMPREPLY[@]}; do
i=0
for v in ${cdignore[@]}; do
if [[ "$f" == "$v" ]]; then
i=1
fi
done
if [[ $i -eq 0 ]]; then
a[k++]=$f
fi
done
COMPREPLY=( ${a[@]} )
fi
return 0
fi
30 Dec 2006 01:32
Re: Example of broken completion (mixing env variable and path)
A bit more work on it to get rid of the redunant loop yields:
%_cd()
%{
> local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k
%
%# (start of changes)
> if [[ "$cur" == ?(\\)\$* ]]; then
> local v vars
> vars=($(for v in $(compgen -v -X !${cur#?(\\)$}*); do if [ -d "$(eval echo \$$v)" ]; then echo \$$v; fi; done))
> if (( ${#vars[*]} == 1 )); then
> # A single completion. Expand it.
> COMPREPLY=($(eval echo $vars))
> return 0
> fi
> # No single completion. Then just list the variables being directories.
> COMPREPLY=(${vars[*]});
> return 0
> fi
>
%# old stuff ...
%# # try to allow variable completion
%# if [[ "$cur" == ?(\\)\$* ]]; then
%# COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
%# return 0
%# fi
%# (unchanged from here)
22 Dec 2006 23:24
Re: Example of broken completion (mixing env variable and path)
Working a bit more on it, the follwoing code does the same more elegantly:
_cd()
{
local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k
# Start of modifications
if [[ "$cur" == ?(\\)\$* ]]; then
local v vars=$(compgen -v -X !${cur#?(\\)$}*)
COMPREPLY=(`for v in $vars; do if [ -d "$(eval echo \\$$v)" ]; then eval echo \\$$v; fi; done`)
if (( ${#COMPREPLY[*]} == 1 )); then
return 0
fi
# No single completion. Then just list the variables being directories.
COMPREPLY=(`for v in $vars; do if [ -d "$(eval echo \\$$v)" ]; then echo \\$$v; fi; done`);
return 0
fi
# old stuff removed
# # try to allow variable completion
# if [[ "$cur" == ?(\\)\$* ]]; then
# COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
# return 0
# fi
#
# (unchanged from here)
22 Dec 2006 03:46
Re: Example of broken completion (mixing env variable and path)
Having experienced the same problem, I hacked the _cd function in bash completion:
cd()
{
local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k
# Hack start
if [[ "$cur" == ?(\\)\$* ]]; then
local v cur1=${cur#?(\\)$}
# "set -o posix" makes "set" only show variables, not functions
local envs=`set -o posix; for v in $(set | /bin/sed 's/^\(.*\)=.*/\1/g' | /bin/grep "^$cur1"); do if [ -d "$(eval echo \\$$v)" ]; then eval echo \\$$v; fi; done`
COMPREPLY=($( compgen -W "$envs" ));
if (( ${#COMPREPLY[*]} == 1 )); then
return 0
fi
fi
# Hack end
# try to allow variable completion
if [[ "$cur" == ?(\\)\$* ]]; then
COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
return 0
fi
(... rest as before)
While this certainly isn't perfect, it will complete unique variables. I know the code is horrible, and anyone with more insight in using "compgen", "sed" etc. are hereby encouraged to make a better solution.
> WIth a traditional bash, it often
> happens that I type :
> cd $PWD/ [and press TAB]
> so that it completes into
> cd /my/current/path
> and then I quit the shell.
>
> Now the directory where I left the shell
> is in the history.
> When starting a new shell, a Ctrl-R cd
> (or even up arrow)
> brings me back to the dir I was working
> before. I can open
> many terminals and jump right into the
> without editing any
> cdpath or the like. This is standard
> bash behavior.
>
> With bash_completion activated,
> cd $PWD/ [TAB]
> "fails" (it flashed and does
> nothing),
> so the happy behaviour used for years is
> broken.
>
> Any idea how to modify bash_completion
> so that this
> appreciated behaviour still works ?
> Thanks.
>
> Regards,
23 Jun 2006 04:21
xine completion
Hi there,
I did a small file for xine completion, that can be downloaded here (talkerspt.no-ip.org/~m.... If you're interested, it would be cool if you could put that file on the contrib directory of bash-completion...
Best regards.
04 Jan 2006 14:31
Very useful idea, but am experiencing too many difficulties
First off, I want to thank the author for developing this extension to bash. When it works, it really makes working at the command line much more pleasant and enhances productivity.
I am using bash 3.00.16 and bash-completion version 20050721.
It mostly works for me, but I am encountered some difficulties and decided to uninstall it.
1. The yum completion didn't know of the new 'localinstall' command token. To get past this I manually typed 'localinstall'. But then when I pressed TAB to do a filename completion on the .rpm file I was trying to install, the completion choices where still offering yum's sub-command tokens instead of filename completions. How do I inform bash-completion about the new 'localinstall' token?
2. The Yum situation became worse when I tried to use it with sudo.
3. Glob expansion when pressing TAB stopped working. That is, I used to be able to type:
$ ls *.c<TAB>
and this would change to:
$ ls myfile.c
This useful behavior returned when I uninstalled bash-completion.
4. It seems under-documented. Documentation at website didn't help me figure out where the yum completions where coming from. I don't know if this is a yum bug or a bash-completion bug. Is there a man page for it?
5. I would urge the author to move the project to a site that allowed better collaboration and bug tracking.
Allen Halsey
04 Aug 2005 13:25
apachectl
i found that i've been using the apachectl command pretty often, and it's possible commands are real simple: start, stop, restart, etc
well, this is perfect for complete -W , but i'm lazy, so i wrote a regexp to extract the command list from the help screen (using sed, it could probably be done entirely in bash, but i think comfortably in pipes and filters rather than bash-syntax functions)
complete -W "`apachectl help | sed -n 's/^\([a-zA-Z1-9_]\{1,\}\)[ ].*/\1/p'`" apachectl
11 Jul 2005 17:39
Re: Variable-name completion bug
> When I tab out an environment variable
> during a cd, the $(dollar sign) sign is
> escaped so although the tab completion
> happens the cd doesn't work. e.g
>
> cd $JA[hit tab] and this lines becomes
> cd \$JAVA_HOME[hit enter] and I get
> -bash: cd: $JAVA_HOME: No such file or
> directory
>
> If I comment out the bash-completion
> line in .bashrc this doesn't happen -
> the tab completion works correctly.
>
> I'm using
> bash-2.05b-r9
> bash-completion 20040526
>
> I started this thread on the gentoo
> forums
>
> and mhodak has tried the latest version
> available 20040704-r1, and reports the
> bug is still there.
To get the behaviour you desire. you have to change this line:
complete -v -F _cd $nospace $filenames cd
Remove '$filenames', which will cause bash to no longer treat the
variable name as a filename, so it won't escape it.
Unfortunately, it will now also no longer append a slash to a path.
These are the kinds of trade-offs that bash's programmable completion
implementation requires, I'm afraid.
A simple wrapper for cross-browser usage of the JavaScript Fullscreen API.
Hi, you might wanna have a look at ClearCase completion script. jan.tomka.name/project...