summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Paleino <d.paleino@gmail.com>2009-02-17 09:07:04 +0100
committerDavid Paleino <d.paleino@gmail.com>2009-02-17 09:07:04 +0100
commit82dd3837e7901ce62994c6de16aaecdf57cdf98d (patch)
tree43cfc44f0152db75308052733881c20109cc2534
parent104f0c7b77ad39708f9eff9d1c418aa6875ad7c6 (diff)
parent05d1c4ab9980d7434031a1ba770794bc8cb66efe (diff)
downloadbash-completion-changelog-handling.tar.gz
Merge branch 'master' into changelog-handlingchangelog-handling
-rw-r--r--bash_completion208
-rw-r--r--[-rwxr-xr-x]bash_completion.sh0
-rw-r--r--contrib/brctl2
-rw-r--r--contrib/hg135
-rw-r--r--contrib/rdesktop (renamed from to_review/rdesktop)9
-rw-r--r--debian/changelog9
-rw-r--r--to_review/vncviewer57
7 files changed, 175 insertions, 245 deletions
diff --git a/bash_completion b/bash_completion
index 9283e23b..614a7edb 100644
--- a/bash_completion
+++ b/bash_completion
@@ -428,6 +428,33 @@ _pgids()
COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur ))
}
+# This function completes on process names.
+# AIX and SunOS prefer X/Open, all else should be BSD.
+[ $UNAME = SunOS -o $UNAME = AIX ] &&
+_pnames()
+{
+ COMPREPLY=( $( compgen -W '$( command ps -efo comm | \
+ sed -e 1d -e "s:.*/::" -e "s/^-//" \
+ -e "s/^<defunct>$//")' \
+ -- $cur ) )
+} ||
+_pnames()
+{
+ # FIXME: completes "[kblockd/0]" to "0". Previously it was completed
+ # to "kblockd" which isn't correct either. "kblockd/0" would be
+ # arguably most correct, but killall from psmisc 22 treats arguments
+ # containing "/" specially unless -r is given so that wouldn't quite
+ # work either. Perhaps it'd be best to not complete these to anything
+ # for now.
+ # Not using "ps axo comm" because under some Linux kernels, it
+ # truncates command names (see e.g. http://bugs.debian.org/497540#19)
+ COMPREPLY=( $( compgen -W '$( command ps axo command | \
+ sed -e "1d; s/ .*//; s:.*/::; s/:$//;" \
+ -e "s/^[[(-]//; s/[])]$//" \
+ -e "s/^<defunct>$//")' \
+ -- $cur ) )
+}
+
# This function completes on user IDs
#
_uids()
@@ -522,6 +549,22 @@ _count_args()
done
}
+# This function complete on PCI IDs
+#
+_pci_ids()
+{
+ COMPREPLY=( ${COMPREPLY[@]:-} \
+ $( compgen -W "$( lspci -n | awk '{print $3}')" -- $cur ) )
+}
+
+# This function complete on USB IDs
+#
+_usb_ids()
+{
+ COMPREPLY=( ${COMPREPLY[@]:-} \
+ $( compgen -W "$( lsusb | awk '{print $6}')" -- $cur ) )
+}
+
# start of section containing completion functions for bash built-ins
# bash alias completion
@@ -535,7 +578,7 @@ _alias()
case "$COMP_LINE" in
*[^=])
- COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) )
+ COMPREPLY=( $( compgen -A alias -- $cur ) )
;;
*=)
COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \
@@ -999,9 +1042,9 @@ _kill()
}
complete -F _kill kill
-# Linux and FreeBSD killall(1) completion.
+# killall(1) (Linux and FreeBSD) and pkill(1) completion.
#
-[ $UNAME = Linux -o $UNAME = FreeBSD ] &&
+[ $UNAME = Linux -o $UNAME = FreeBSD ] || have pkill &&
_killall()
{
local cur
@@ -1012,19 +1055,17 @@ _killall()
if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
_signals
else
- COMPREPLY=( $( compgen -W '$( command ps axo command | \
- sed -e "1d; s/ .*//g; s:^/.*/::g; s/:$//g;" \
- -e "s/^-//g; s/^\[//g; s/\]$//g; s:/.*::g")' \
- -- $cur ) )
+ _pnames
fi
return 0
}
-[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill
+[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall
+have pkill && complete -F _killall pkill
-# Linux and FreeBSD pgrep(1) completion.
+# pgrep(1) completion.
#
-[ $UNAME = Linux -o $UNAME = FreeBSD ] &&
+[ $UNAME = Linux ] || have pgrep &&
_pgrep()
{
local cur
@@ -1032,13 +1073,12 @@ _pgrep()
COMPREPLY=()
cur=`_get_cword`
- COMPREPLY=( $( compgen -W '$( command ps axo command | \
- sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
- sed -e "s/.*\///" )' -- $cur ) )
+ _pnames
return 0
}
-[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep
+have pgrep && complete -F _pgrep pgrep
+
# Linux pidof(8) completion.
[ $UNAME = Linux ] && complete -F _pgrep pidof
@@ -3172,35 +3212,20 @@ else
complete -F _cd $nospace cd
fi
-_remove_comp_word()
-{
- if [[ COMP_CWORD -eq 0 ]]; then
- return
- elif [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
- local old_cw0="${COMP_WORDS[0]}"
- local new_cw0="${COMP_WORDS[1]}"
- local old_length="${#COMP_LINE}"
- COMP_LINE=${COMP_LINE#${old_cw0}}
- local head=${COMP_LINE:0:${#new_cw0}}
- local i=1
- while [[ $head != $new_cw0 ]]; do
- COMP_LINE=${COMP_LINE:1}
- head=${COMP_LINE:0:${#new_cw0}}
- if (( ++i > 10 )); then
- break
- fi
- done
- local new_length="${#COMP_LINE}"
- COMP_POINT=$(( COMP_POINT + new_length - old_length ))
-
- COMP_CWORD=$(( COMP_CWORD - 1 ))
- for (( i=0; i < ${#COMP_WORDS[@]} - 1; ++i )); do
- COMP_WORDS[i]="${COMP_WORDS[i+1]}"
- done
- unset COMP_WORDS[${#COMP_WORDS[@]}-1]
- else
- return
- fi
+# a wrapper method for the next one, when the offset is unknown
+_command()
+{
+ local offset i
+
+ # find actual offset, as position of the first non-option
+ offset=1
+ for (( i=1; i <= COMP_CWORD; i++ )); do
+ if [[ "${COMP_WORDS[i]}" != -* ]]; then
+ offset=$i
+ break
+ fi
+ done
+ _command_offset $offset
}
# A meta-command completion function for commands like sudo(8), which need to
@@ -3208,38 +3233,48 @@ _remove_comp_word()
# completion definition - currently not quite foolproof (e.g. mount and umount
# don't work properly), but still quite useful.
#
-_command()
+_command_offset()
{
- local cur func cline cspec noglob cmd done i \
+ local cur func cline cspec noglob cmd i char_offset word_offset \
_COMMAND_FUNC _COMMAND_FUNC_ARGS
- _remove_comp_word
+ word_offset=$1
+
+ # rewrite current completion context before invoking
+ # actual command completion
+
+ # find new first word position, then
+ # rewrite COMP_LINE and adjust COMP_POINT
+ local first_word=${COMP_WORDS[$word_offset]}
+ for (( i=0; i <= ${#COMP_LINE}; i++ )); do
+ if [[ "${COMP_LINE:$i:${#first_word}}" == "$first_word" ]]; then
+ char_offset=$i
+ break
+ fi
+ done
+ COMP_LINE=${COMP_LINE:$char_offset}
+ COMP_POINT=$(( COMP_POINT - $char_offset ))
+
+ # shift COMP_WORDS elements and adjust COMP_CWORD
+ for (( i=0; i <= COMP_CWORD - $word_offset; i++ )); do
+ COMP_WORDS[i]=${COMP_WORDS[i+$word_offset]}
+ done
+ for (( i; i <= COMP_CWORD; i++ )); do
+ unset COMP_WORDS[i];
+ done
+ COMP_CWORD=$(( $COMP_CWORD - $word_offset ))
+
COMPREPLY=()
cur=`_get_cword`
- # If the the first arguments following our meta-command-invoker are
- # switches, get rid of them. Most definitely not foolproof.
- done=
- while [ -z $done ] ; do
- cmd=${COMP_WORDS[0]}
- if [[ "$cmd" == -* ]] && [[ $COMP_CWORD -ge 1 ]]; then
- _remove_comp_word
- elif [[ "$cmd" == -* ]] && [[ $COMP_CWORD -eq 0 ]]; then
- return
- else
- done=1
- fi
- done
if [[ $COMP_CWORD -eq 0 ]]; then
COMPREPLY=( $( compgen -c -- $cur ) )
- elif complete -p $cmd &>/dev/null; then
+ else
+ cmd=${COMP_WORDS[0]}
+ if complete -p $cmd &>/dev/null; then
cspec=$( complete -p $cmd )
if [ "${cspec#* -F }" != "$cspec" ]; then
# complete -F <function>
- #
- # COMP_CWORD and COMP_WORDS() are not read-only,
- # so we can set them before handing off to regular
- # completion routine
# get function name
func=${cspec#*-F }
@@ -3266,11 +3301,12 @@ _command()
cspec=${cspec%%$cmd};
COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
fi
+ fi
fi
[ ${#COMPREPLY[@]} -eq 0 ] && _filedir
}
-complete -F _command $filenames nohup exec nice eval strace time ltrace then \
+complete -F _command $filenames nohup exec nice eval time ltrace then \
else do vsound command xargs tsocks
_root_command()
@@ -5360,16 +5396,12 @@ _perl()
;;
esac
- # handle case where first parameter is not a dash option
- if [[ "`_get_cword`" != -* ]]; then
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d \
+ -D -p -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) )
+ else
_filedir
- return 0
fi
-
- # complete using basic options
- COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d -D -p \
- -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) )
- return 0
}
complete -F _perl $nospace $filenames perl
@@ -5426,21 +5458,15 @@ _perldoc()
;;
esac
- case $cur in
- -*)
+ if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- $cur ))
- return 0
- ;;
- */*)
- return 0
- ;;
- *)
- _perlmodules
- COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '$( PAGER=/bin/cat man perl | sed -ne "/perl.*Perl overview/,/perlwin32/p" | awk "\$NF=2 { print \$1}" | grep perl )' -- $cur ) )
-
- return 0
- ;;
- esac
+ else
+ # return available modules (unless it is clearly a file)
+ if [[ "$cur" != */* ]]; then
+ _perlmodules
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '$( PAGER=/bin/cat man perl | sed -ne "/perl.*Perl overview/,/perlwin32/p" | awk "\$NF=2 { print \$1}" | grep perl )' -- $cur ) )
+ fi
+ fi
}
complete -F _perldoc $default perldoc
}
@@ -6322,7 +6348,7 @@ complete -F _dict $default dict rdict
# cdrecord(1) completion
#
-have cdrecord &&
+(have cdrecord || have wodim) &&
_cdrecord()
{
local cur prev i generic_options track_options track_mode
@@ -6395,11 +6421,11 @@ _cdrecord()
fi
} &&
-complete -F _cdrecord $filenames cdrecord
+complete -F _cdrecord $filenames cdrecord wodim
# mkisofs(8) completion
#
-have mkisofs &&
+(have mkisofs || have genisoimage) &&
_mkisofs()
{
local cur prev
@@ -6467,7 +6493,7 @@ _mkisofs()
fi
} &&
-complete -F _mkisofs $filenames mkisofs
+complete -F _mkisofs $filenames mkisofs genisoimage
# mc(1) completion
#
diff --git a/bash_completion.sh b/bash_completion.sh
index e14378a6..e14378a6 100755..100644
--- a/bash_completion.sh
+++ b/bash_completion.sh
diff --git a/contrib/brctl b/contrib/brctl
index 6fd7b6e5..1ecdc127 100644
--- a/contrib/brctl
+++ b/contrib/brctl
@@ -1,7 +1,7 @@
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
#
-# bash completion for brtcl
+# bash completion for brctl
have brctl &&
_brctl()
diff --git a/contrib/hg b/contrib/hg
deleted file mode 100644
index c053aa22..00000000
--- a/contrib/hg
+++ /dev/null
@@ -1,135 +0,0 @@
-# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
-# ex: ts=8 sw=8 noet filetype=sh
-#
-# Mercurial completion by Alexis S. L. Carvalho <alexis@cecm.usp.br>
-#
-# See: http://www.selenic.com/pipermail/mercurial/2005-August/003378.html
-
-_hg_commands()
-{
- local commands="$(hg -v help | sed -e '1,/^list of commands:/d' \
- -e '/^global options:/Q' \
- -e '/^ [^ ]/!d; s/[,:]//g;')"
-
- # hide debug commands from users, but complete them if
- # specifically asked for
- if [[ "$cur" == de* ]]; then
- commands="$commands debugcheckstate debugstate debugindex"
- commands="$commands debugindexdot debugwalk"
- fi
- COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$commands" -- "$cur") )
-}
-
-_hg_paths()
-{
- local paths="$(hg paths | sed -e 's/ = .*$//')"
- COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" ))
-}
-
-_hg_tags()
-{
- local tags="$(hg tags | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')"
- COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$tags" -- "$cur") )
-}
-
-# this is "kind of" ugly...
-_hg_count_non_option()
-{
- local i count=0
- local filters="$1"
-
- for (( i=1; $i<=$COMP_CWORD; i++ )); do
- if [[ "${COMP_WORDS[i]}" != -* ]]; then
- for f in $filters; do
- if [[ ${COMP_WORDS[i-1]} == $f ]]; then
- continue 2
- fi
- done
- count=$(($count + 1))
- fi
- done
-
- echo $(($count - 1))
-}
-
-_hg()
-{
- local cur prev cmd opts i
-
- COMPREPLY=()
- cur="$2"
- prev="$3"
-
- # searching for the command
- # (first non-option argument that doesn't follow -R/--repository)
- for (( i=1; $i<=$COMP_CWORD; i++ )); do
- if [[ ${COMP_WORDS[i]} != -* ]] \
- && [ "${COMP_WORDS[i-1]}" != -R ] \
- && [ "${COMP_WORDS[i-1]}" != --repository ]; then
- cmd="${COMP_WORDS[i]}"
- break
- fi
- done
-
- if [[ "$cur" == -* ]]; then
- opts="$(hg -v help | sed -e '1,/^global options/d; /^ -/!d')"
-
- if [ -n "$cmd" ]; then
- opts="$opts $(hg help "$cmd" | sed -e '/^ -/!d; s/ [^-][^ ]*//')"
- fi
-
- COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") )
- return
- fi
-
- if [ "$prev" = -R ] || [ "$prev" = --repository ]; then
- COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
- return
- fi
-
- if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
- _hg_commands
- return
- fi
-
- if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then
- _hg_tags
- return
- fi
-
- case "$cmd" in
- help)
- _hg_commands
- ;;
- export|manifest|update|checkout|up|co)
- _hg_tags
- ;;
- pull|push)
- _hg_paths
- COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
- ;;
- paths)
- _hg_paths
- ;;
- clone)
- local count=$(_hg_count_non_option)
- if [ $count = 1 ]; then
- _hg_paths
- fi
- COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
- ;;
- cat)
- local count=$(_hg_count_non_option -o --output)
- if [ $count = 2 ]; then
- _hg_tags
- else
- COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
- fi
- ;;
- *)
- COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
- ;;
- esac
-
-}
-complete -o filenames -F _hg hg
diff --git a/to_review/rdesktop b/contrib/rdesktop
index a3a6394c..ba941eec 100644
--- a/to_review/rdesktop
+++ b/contrib/rdesktop
@@ -34,16 +34,17 @@ _rdesktop()
return 0
;;
-r)
+ # FIXME: should do $nospace for the colon options
COMPREPLY=( $( compgen -W 'comport: disk: lptport: \
- printer: sound: lspc scard' -- $cur ) )
+ printer: sound: lspci scard' -- $cur ) )
return 0
;;
esac
if [[ "$cur" == -* ]]; then
- COMPREPLY=( $( compgen -W '-u -d -s -c -p -n -k -g -f -b -A -B \
- -e -E -m -C -D -K -S -T -N -X -a -z -X -P -r -0 -4 -5' \
- -- $cur ) )
+ COMPREPLY=( $( compgen -W '-u -d -s -c -p -n -k -g -f -b -L \
+ -A -B -e -E -m -C -D -K -S -T -N -X -a -z -x -P -r \
+ -0 -4 -5' -- $cur ) )
else
_known_hosts
fi
diff --git a/debian/changelog b/debian/changelog
index a7142f58..66107ac3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,6 +10,7 @@ bash-completion (200902xx) UNRELEASED; urgency=low
* Added net-tools (mii-tool and mii-diag) completions
* Added minicom completion
* Added quota-tools completion
+ * Added rdesktop completion
[ David Paleino ]
* Added .kar to Timidity completion.
@@ -122,6 +123,14 @@ bash-completion (200902xx) UNRELEASED; urgency=low
* Fix awk error in "modprobe -r /" completion (Closes: #512556).
* Expand ~foo to dir name more eagerly to avoid quoting issues.
* Fix -sourcepath handling in javadoc packages completion.
+ * Extract process name completion from _killall to _pnames, make it work
+ for others than Linux and FreeBSD.
+ * Fix process name completion with relative paths (RHBZ: #484578).
+ * Use improved process name completion in pgrep in addition to killall.
+ * Enable pgrep and pkill completion if the commands are available, not just
+ on Linux and FreeBSD.
+ * Drop hg completion, an improved version is shipped with Mercurial
+ (contrib/bash_completion in the tarball).
[ Freddy Vulto ]
* Restored `_display()' completion for `display' by removing
diff --git a/to_review/vncviewer b/to_review/vncviewer
index 02c91051..24d90124 100644
--- a/to_review/vncviewer
+++ b/to_review/vncviewer
@@ -1,8 +1,11 @@
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
#
-# bash completion for vncviewer
+# bash completion for vncviewer (4.1.1)
+
+# NOTE: - VNC Viewer options are case-insensivite. Preferred case is taken from -help.
+# - Both single dash (-) and double dash (--) are allowed as option prefix
have vncviewer &&
_vncviewer()
{
@@ -12,29 +15,55 @@ _vncviewer()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
- case $prev in
- -passwd)
+ # Convert double dash to single dash
+ case ${prev/#--/-} in
+ # -passwd, -PasswordFile
+ -[pP][aA][sS][sS][wW][dD]|-[pP][aA][sS][sS][wW][oO][rR][dD][fF][iI][lL][eE])
_filedir
return 0
;;
- -encodings)
- COMPREPLY=( $( compgen -W 'copyrect tight hextile zlib \
- corre rre raw' -- $cur ) )
+ # -PreferredEncoding
+ -[pP][rR][eE][fF][eE][rR][rR][eE][dD][eE][nN][cC][oO][dD][iI][nN][gG])
+ COMPREPLY=( $( compgen -W 'zrle hextile raw' -- $cur ) )
return 0
;;
- -via)
+ # -via
+ -[vV][iI][aA])
_known_hosts
return 0
;;
esac
-
- if [[ "$cur" == -* ]]; then
- COMPREPLY=( $( compgen -W '-help -listen -via -shared -noshared\
- -viewonly -fullscreen -noraiseonbeep -passwd -encodings\
- -bgr233 -owncmap -truecolour -truecolor -depth \
- -compresslevel -quality -nojpeg -nocursorshape \
- -x11cursor' -- $cur ) )
+ if [[ "$cur" == -* || "$cur" == --* ]]; then
+ # Default to vncviewer camelcase options, see `vncviewer -help'
+ local dash options=( \
+ AcceptClipboard AutoSelect DebugDelay display \
+ DotWhenNoCursor FullColor FullColour FullScreen \
+ geometry help listen Log \
+ LowColourLevel MenuKey name Parent \
+ passwd PasswordFile PointerEventInterval PreferredEncoding \
+ SendClipboard SendPrimary Shared UseLocalCursor \
+ via ViewOnly WMDecorationHeight WMDecorationWidth \
+ ZlibLevel \
+ )
+ [[ "$cur" == --* ]] && dash=-- || dash=-
+ # Is a `nocasematch' variable available (bash > v3.1)?
+ if shopt nocasematch 2> /dev/null | grep -q ^nocasematch; then
+ # Variable `nocasematch' is available
+ # Use vncviewer camelcase options
+ local option oldNoCaseMatch=$(shopt -p nocasematch)
+ shopt -s nocasematch
+ COMPREPLY=( $( for option in "${options[@]}"; do
+ [[ $dash$option == "$cur"* ]] && echo $dash$option
+ done ) )
+ eval "$oldNoCaseMatch" 2> /dev/null
+ else
+ # Variable 'nocasematch' isn't available;
+ # Convert completions to lowercase
+ COMPREPLY=( $( compgen -W "$(
+ echo ${options[@]/#/$dash} | tr [:upper:] [:lower:]
+ )" -- "$(echo "$cur" | tr [:upper:] [:lower:])" ) )
+ fi
else
_known_hosts
fi