From b0646ff2d2ea06bfc30f15f7205450002ff574b0 Mon Sep 17 00:00:00 2001 From: David Paleino Date: Sat, 17 Jan 2009 00:31:39 +0100 Subject: [PATCH] * Added _parse_help() to try to parse options listed in $command --help * Fixed gzip completion to use _parse_help(), since the available options vary with distributions --- bash_completion | 24 ++++++++++++++++-------- debian/changelog | 7 +++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bash_completion b/bash_completion index 736c4eb6..cc148359 100644 --- a/bash_completion +++ b/bash_completion @@ -303,6 +303,18 @@ _filedir() COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" ) } +# This function tries to parse the output of $command --help +# +_parse_help() { + local cmd + cmd=$1 + $cmd --help | \ + grep -- "^[[:space:]]*-" | \ + tr "," " " | \ + awk '{print $1; if ($2 ~ /-.*/) { print $2 } }' | \ + sed -e "s:=.*::g" +} + # This function completes on signal names # _signals() @@ -3357,20 +3369,16 @@ complete -F _mysqladmin mysqladmin have gzip && _gzip() { - local cur prev xspec + local cur prev xspec helpopts COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} + helpopts=`_parse_help gzip` if [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W '-c -d -f \ - -h -l -L -n -N -q -r -S -t -v -V \ - -1 -2 -3 -4 -5 -6 -7 -8 -9 \ - --stdout --decompress --force --help --list \ - --license --no-name --name --quiet --recursive \ - --suffix --test --verbose --version --fast \ - --best --rsyncable' -- $cur ) ) + COMPREPLY=( $( compgen -W "$helpopts -2 -3 -4 -5 -6 -7 -8" \ + -- "$cur" ) ) return 0 fi diff --git a/debian/changelog b/debian/changelog index 9f76e6b4..d5018c02 100644 --- a/debian/changelog +++ b/debian/changelog @@ -54,6 +54,10 @@ bash-completion (200811xx) UNRELEASED; urgency=low (Closes: #272660) * Fix dpkg completion bug: it listed only non-Essential packages (Closes: #511790) + * Added _parse_help() to try to parse options listed in $command + --help + * Fixed gzip completion to use _parse_help(), since the available + options vary with distributions * Merge from Gentoo: - fix 'find' completion so that it properly completes on -?(i)whilename. Patch by Ciaran McCreesh. @@ -92,9 +96,8 @@ bash-completion (200811xx) UNRELEASED; urgency=low * Add lzma completion (Per Øyvind Karlsen, Ville Skyttä). * Add .mp2 and .vdr to mplayer completion (RHBZ: #444467). * Add .mkv, .mp2 and .vdr to *xine completion (RHBZ: #444467). - * Add --rsyncable to gzip completion. - -- David Paleino Fri, 16 Jan 2009 23:03:01 +0100 + -- David Paleino Sat, 17 Jan 2009 00:28:42 +0100 bash-completion (20080705) unstable; urgency=low