From 6aecdb5f4cf0fe8b44ee6a3a6442898141185711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 5 Feb 2011 12:06:53 +0200 Subject: [PATCH 1/9] Avoid some unnecessary stat calls. --- completions/java | 2 +- completions/mutt | 7 +++++-- completions/service | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/completions/java b/completions/java index eacd85e3..b8bbb79e 100644 --- a/completions/java +++ b/completions/java @@ -60,7 +60,7 @@ _java_classes() cur=${cur//.//} # parse each classpath element for classes for i in ${classpath//:/ }; do - if [[ -r $i && "$i" == *.@(jar|zip) ]]; then + if [[ "$i" == *.@(jar|zip) && -r $i ]]; then if type zipinfo &>/dev/null; then COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \ "$i" "$cur*" 2>/dev/null | \ diff --git a/completions/mutt b/completions/mutt index a753a652..e5e9d289 100644 --- a/completions/mutt +++ b/completions/mutt @@ -37,8 +37,11 @@ _muttrc() done if [ -z "$muttrc" ]; then - [ -f ~/.${muttcmd}/${muttcmd}rc ] && muttrc="~/.${muttcmd}/${muttcmd}rc" - [ -f ~/.${muttcmd}rc ] && muttrc="~/.${muttcmd}rc" + if [ -f ~/.${muttcmd}rc ]; then + muttrc="~/.${muttcmd}rc" + elif [ -f ~/.${muttcmd}/${muttcmd}rc ]; then + muttrc="~/.${muttcmd}/${muttcmd}rc" + fi fi printf "%s" "$muttrc" } # _muttrc() diff --git a/completions/service b/completions/service index ffd24366..1a36f59b 100644 --- a/completions/service +++ b/completions/service @@ -19,11 +19,11 @@ _service() # don't complete past 2nd token [ $COMP_CWORD -gt 2 ] && return 0 - [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d - if [[ $COMP_CWORD -eq 1 && $prev == "service" ]]; then _services else + [ -d /etc/rc.d/init.d ] && \ + sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \ -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \ $sysvdir/${prev##*/} 2>/dev/null`' -- "$cur" ) ) From 56c12d5570699ecd4059379b64cc630832691ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 5 Feb 2011 12:14:42 +0200 Subject: [PATCH 2/9] Clean up some redundant code. --- bash_completion | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/bash_completion b/bash_completion index 0b5005ee..b53091a5 100644 --- a/bash_completion +++ b/bash_completion @@ -1244,12 +1244,10 @@ _known_hosts_real() [ -r "$configfile" ] && config=( "${config[@]}" "$configfile" ) else - [ -r /etc/ssh/ssh_config ] && - config=( "${config[@]}" "/etc/ssh/ssh_config" ) - [ -r "${HOME}/.ssh/config" ] && - config=( "${config[@]}" "${HOME}/.ssh/config" ) - [ -r "${HOME}/.ssh2/config" ] && - config=( "${config[@]}" "${HOME}/.ssh2/config" ) + for i in /etc/ssh/ssh_config "${HOME}/.ssh/config" \ + "${HOME}/.ssh2/config"; do + [ -r $i ] && config=( "${config[@]}" "$i" ) + done fi # Known hosts files from configs @@ -1271,28 +1269,16 @@ _known_hosts_real() IFS=$OIFS fi - # Global known_hosts files if [ -z "$configfile" ]; then - [ -r /etc/ssh/ssh_known_hosts ] && - kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts ) - [ -r /etc/ssh/ssh_known_hosts2 ] && - kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 ) - [ -r /etc/known_hosts ] && - kh=( "${kh[@]}" /etc/known_hosts ) - [ -r /etc/known_hosts2 ] && - kh=( "${kh[@]}" /etc/known_hosts2 ) - [ -d /etc/ssh2/knownhosts ] && - khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub ) - fi - - # User known_hosts files - if [ -z "$configfile" ]; then - [ -r ~/.ssh/known_hosts ] && - kh=( "${kh[@]}" ~/.ssh/known_hosts ) - [ -r ~/.ssh/known_hosts2 ] && - kh=( "${kh[@]}" ~/.ssh/known_hosts2 ) - [ -d ~/.ssh2/hostkeys ] && - khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub ) + # Global and user known_hosts files + for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 \ + /etc/known_hosts /etc/known_hosts2 ~/.ssh/known_hosts \ + ~/.ssh/known_hosts2; do + [ -r $i ] && kh=( "${kh[@]}" $i ) + done + for i in /etc/ssh2/knownhosts ~/.ssh2/hostkeys; do + [ -d $i ] && khd=( "${khd[@]}" $i/*pub ) + done fi # If we have known_hosts files to use From 80312be9afd77307dd8eecf4bc1a2408949ed58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 5 Feb 2011 12:24:49 +0200 Subject: [PATCH 3/9] (testsuite) Use get_hosts() in xhost tests. --- test/lib/completions/xhost.exp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/lib/completions/xhost.exp b/test/lib/completions/xhost.exp index d4098ade..82e2e9c6 100644 --- a/test/lib/completions/xhost.exp +++ b/test/lib/completions/xhost.exp @@ -13,12 +13,7 @@ setup set test "Tab should complete hostnames" - # Build string list of hostnames -set hosts {} -foreach h [exec bash -c "compgen -A hostname"] { - lappend hosts $h -} -assert_complete $hosts "xhost " $test +assert_complete [get_hosts] "xhost " $test sync_after_int @@ -28,7 +23,7 @@ set test "Tab should complete partial hostname" # Build string list of hostnames, starting with the character of the first hostname set hosts {} set char "" -foreach h [exec bash -c "compgen -A hostname"] { +foreach h [get_hosts] { if {$char == ""} {set char [string range $h 0 0]} # Only append hostname if starting with $char if {[string range $h 0 0] == "$char"} { @@ -44,7 +39,7 @@ sync_after_int set test "Tab should complete hostnames prefixed with +" # Build string list of hostnames, prefixed with plus (+) set hosts {} -foreach h [exec bash -c "compgen -A hostname"] { +foreach h [get_hosts] { lappend hosts "+$h" } assert_complete $hosts "xhost \+" $test @@ -56,7 +51,7 @@ sync_after_int set test "Tab should complete partial hostname prefixed with +" # Build string list of hostnames, starting with character of first host. set hosts {} -foreach h [exec bash -c "compgen -A hostname"] { +foreach h [get_hosts] { if {$char == ""} {set char [string range $h 0 0]} # Only append hostname if starting with $char if {[string range $h 0 0] == "$char"} { @@ -72,7 +67,7 @@ sync_after_int set test "Tab should complete hostnames prefixed with -" # Build string list of hostnames, prefix with minus (-) set hosts {} -foreach h [exec bash -c "compgen -A hostname"] { +foreach h [get_hosts] { lappend hosts "-$h" } assert_complete $hosts "xhost -" $test @@ -84,7 +79,7 @@ sync_after_int set test "Tab should complete partial hostname prefixed with -" # Build list of hostnames, starting with character of first host set hosts {} -foreach h [exec bash -c "compgen -A hostname"] { +foreach h [get_hosts] { if {$char == ""} {set char [string range $h 0 0]} # Only append hostname if starting with $char if {[string range $h 0 0] == "$char"} { From 81794a9dcf71b408b1a1a4cc7b1888725921291e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 5 Feb 2011 12:27:35 +0200 Subject: [PATCH 4/9] (testsuite) Avoid duplicates in get_hosts() return value. --- test/lib/library.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/library.exp b/test/lib/library.exp index 61b3f409..491da212 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -636,7 +636,7 @@ proc get_known_hosts {{cword ''}} { # @return list Hostnames # @see get_known_hosts() proc get_hosts {} { - set hosts [exec bash -c "compgen -A hostname"] + set hosts [exec bash -c "compgen -A hostname | sort -u"] # NOTE: Circumventing var `avahi_hosts' and appending directly to `hosts' # causes an empty element to be inserted in `hosts'. # -- FVu, Fri Jul 17 23:11:46 CEST 2009 From 3123e2ac4c7a5f7b562426d12d7d417d2a8ad25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 5 Feb 2011 16:54:48 +0200 Subject: [PATCH 5/9] Add gendiff completion. --- CHANGES | 6 +++--- completions/rpm | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 86ee3582..de7954bf 100644 --- a/CHANGES +++ b/CHANGES @@ -14,9 +14,9 @@ bash-completion (2.x) [ Ville Skyttä ] * Activate hping2 completion also for hping and hping3. * Add badblocks, compgen, crontab, dumpe2fs, e2freefrag, e2label, ether-wake, - filefrag, growisofs, iftop, ip (Debian: #600617), lrzip, lsof, mktemp, - portecle, POSIX sh, sha{,224,256,384,512}sum, sysbench, tune2fs, xmodmap, - and xrdb completions. + filefrag, gendiff, growisofs, iftop, ip (Debian: #600617), lrzip, lsof, + mktemp, portecle, POSIX sh, sha{,224,256,384,512}sum, sysbench, tune2fs, + xmodmap, and xrdb completions. * Add *.gif (Alioth: #312512), *.m2t (Alioth: #312770), *.3gpp, *.3gpp2, *.awb, and *.iso (Alioth: #311420) to mplayer filename completions. * Add "short" tarball extensions to unxz, unlzma etc completions. diff --git a/completions/rpm b/completions/rpm index f07ba7de..bbab0368 100644 --- a/completions/rpm +++ b/completions/rpm @@ -290,6 +290,16 @@ _rpm() complete -F _rpm rpm rpmbuild } +have gendiff && +_gendiff() +{ + COMPREPLY=() + local cur cword + _get_comp_words_by_ref cur cword + [[ $cword != 1 ]] || _filedir -d +} && +complete -F _gendiff gendiff + # Local variables: # mode: shell-script # sh-basic-offset: 4 From ca9405710e424527b73f41961eebc934f3e93247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Feb 2011 14:46:52 +0200 Subject: [PATCH 6/9] Add kid3 filename completion. --- CHANGES | 6 +++--- bash_completion | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index de7954bf..642f124c 100644 --- a/CHANGES +++ b/CHANGES @@ -14,9 +14,9 @@ bash-completion (2.x) [ Ville Skyttä ] * Activate hping2 completion also for hping and hping3. * Add badblocks, compgen, crontab, dumpe2fs, e2freefrag, e2label, ether-wake, - filefrag, gendiff, growisofs, iftop, ip (Debian: #600617), lrzip, lsof, - mktemp, portecle, POSIX sh, sha{,224,256,384,512}sum, sysbench, tune2fs, - xmodmap, and xrdb completions. + filefrag, gendiff, growisofs, iftop, ip (Debian: #600617), kid3, lrzip, + lsof, mktemp, portecle, POSIX sh, sha{,224,256,384,512}sum, sysbench, + tune2fs, xmodmap, and xrdb completions. * Add *.gif (Alioth: #312512), *.m2t (Alioth: #312770), *.3gpp, *.3gpp2, *.awb, and *.iso (Alioth: #311420) to mplayer filename completions. * Add "short" tarball extensions to unxz, unlzma etc completions. diff --git a/bash_completion b/bash_completion index b53091a5..9d997cb0 100644 --- a/bash_completion +++ b/bash_completion @@ -123,6 +123,7 @@ complete -f -X '!*.ly' lilypond ly2dvi complete -f -X '!*.@(dif?(f)|?(d)patch)?(.@([gx]z|bz2|lzma))' cdiff complete -f -X '!*.lyx' lyx complete -f -X '!@(*.@(ks|jks|jceks|p12|pfx|bks|ubr|gkr|cer|crt|cert|p7b|pkipath|pem|p10|csr|crl)|cacerts)' portecle +complete -f -X '!*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)' kid3 kid3-qt # FINISH exclude -- do not remove this line # start of section containing compspecs that can be handled within bash From 1b0e17c2a3a4831ba52435c360b34b5e1dca10c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Feb 2011 14:53:55 +0200 Subject: [PATCH 7/9] Define needed utility functions for javac and javadoc even if java is not installed. --- completions/java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/completions/java b/completions/java index b8bbb79e..999e6bfc 100644 --- a/completions/java +++ b/completions/java @@ -1,13 +1,14 @@ # bash completion for java, javac and javadoc # available path elements completion -have java && { +have java || have javac || have javadoc && _java_path() { cur=${cur##*:} _filedir '@(jar|zip)' } +have java || have javadoc && { # exact classpath determination _java_find_classpath() { @@ -113,9 +114,11 @@ _java_packages() # convert path syntax to package syntax cur=${COMPREPLY[@]//\//.} } +} # java completion # +have java && _java() { local cur prev words cword i @@ -230,9 +233,8 @@ _java() type compopt &>/dev/null && compopt -o nospace __ltrim_colon_completions "$cur" -} +} && complete -F _java java -} have javadoc && _javadoc() From 558920aecbce226d7eb8aea8bf1c9c2290ec3f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Feb 2011 15:13:45 +0200 Subject: [PATCH 8/9] Truncate _parse_help() output options on <. --- bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion b/bash_completion index 9d997cb0..98fe3393 100644 --- a/bash_completion +++ b/bash_completion @@ -688,7 +688,7 @@ _split_longopt() # _parse_help() { $1 ${2:---help} 2>&1 | sed -e '/^[[:space:]]*-/!d' -e 's|[,/]| |g' | \ - awk '{ print $1; if ($2 ~ /^-/) { print $2 } }' | sed -e 's|=.*||' + awk '{ print $1; if ($2 ~ /^-/) { print $2 } }' | sed -e 's|[<=].*||' } # This function completes on signal names From cb01d8ea5434c2c9f4826b35f5f687d7723102e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Feb 2011 15:15:20 +0200 Subject: [PATCH 9/9] Add javaws completion. --- CHANGES | 6 +++--- completions/java | 30 ++++++++++++++++++++++++++++++ test/completion/javaws.exp | 1 + test/lib/completions/javaws.exp | 20 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 test/completion/javaws.exp create mode 100644 test/lib/completions/javaws.exp diff --git a/CHANGES b/CHANGES index 642f124c..d54844c6 100644 --- a/CHANGES +++ b/CHANGES @@ -14,9 +14,9 @@ bash-completion (2.x) [ Ville Skyttä ] * Activate hping2 completion also for hping and hping3. * Add badblocks, compgen, crontab, dumpe2fs, e2freefrag, e2label, ether-wake, - filefrag, gendiff, growisofs, iftop, ip (Debian: #600617), kid3, lrzip, - lsof, mktemp, portecle, POSIX sh, sha{,224,256,384,512}sum, sysbench, - tune2fs, xmodmap, and xrdb completions. + filefrag, gendiff, growisofs, iftop, ip (Debian: #600617), javaws, kid3, + lrzip, lsof, mktemp, portecle, POSIX sh, sha{,224,256,384,512}sum, + sysbench, tune2fs, xmodmap, and xrdb completions. * Add *.gif (Alioth: #312512), *.m2t (Alioth: #312770), *.3gpp, *.3gpp2, *.awb, and *.iso (Alioth: #311420) to mplayer filename completions. * Add "short" tarball extensions to unxz, unlzma etc completions. diff --git a/completions/java b/completions/java index 999e6bfc..460ae285 100644 --- a/completions/java +++ b/completions/java @@ -494,6 +494,36 @@ _jarsigner() } && complete -F _jarsigner jarsigner +have javaws && +_javaws() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -help|-license|-about|-viewer|-arg|-param|-property|-update|-umask) + return 0 + ;; + -basedir|-codebase) + _filedir -d + return 0 + ;; + -uninstall|-import) + _filedir jnlp + return 0 + ;; + esac + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W "$( _parse_help "$1" -help ) " -- "$cur" ) ) + return 0 + fi + + _filedir jnlp +} && +complete -F _javaws javaws + # Local variables: # mode: shell-script # sh-basic-offset: 4 diff --git a/test/completion/javaws.exp b/test/completion/javaws.exp new file mode 100644 index 00000000..c1c6b106 --- /dev/null +++ b/test/completion/javaws.exp @@ -0,0 +1 @@ +assert_source_completions javaws diff --git a/test/lib/completions/javaws.exp b/test/lib/completions/javaws.exp new file mode 100644 index 00000000..cb29c65a --- /dev/null +++ b/test/lib/completions/javaws.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "javaws " + + +sync_after_int + + +teardown