[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-482-g099b47c

Ville Skyttä ville.skytta at iki.fi
Wed Oct 26 18:02:11 UTC 2011


The following commit has been merged in the master branch:
commit 099b47c66d48537311d53493dca67017c2493f84
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Wed Oct 26 21:01:18 2011 +0300

    kill, killall: Add some option and argument completions, simplify _signals.

diff --git a/bash_completion b/bash_completion
index b550153..6d119ec 100644
--- a/bash_completion
+++ b/bash_completion
@@ -777,20 +777,12 @@ _parse_usage()
     done
 }
 
-# This function completes on signal names
-#
+# This function completes on signal names (minus the SIG prefix)
+# @param $1 prefix
 _signals()
 {
-    local i
-
-    # standard signal completion is rather braindead, so we need
-    # to hack around to get what we want here, which is to
-    # complete on a dash, followed by the signal name minus
-    # the SIG prefix
-    COMPREPLY=( $( compgen -A signal SIG${cur#-} ))
-    for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
-        COMPREPLY[i]=-${COMPREPLY[i]#SIG}
-    done
+    local -a sigs=( $( compgen -P "$1" -A signal "SIG${cur#$1}" ) )
+    COMPREPLY+=( "${sigs[@]/#${1}SIG/${1}}" )
 }
 
 # This function completes on known mac addresses
diff --git a/completions/kill b/completions/kill
index d3c5fbe..150f211 100644
--- a/completions/kill
+++ b/completions/kill
@@ -5,9 +5,20 @@ _kill()
     local cur prev words cword
     _init_completion || return
 
+    case $prev in
+        -s)
+            _signals
+            return
+            ;;
+        -l)
+            return
+            ;;
+    esac
+
     if [[ $cword -eq 1 && "$cur" == -* ]]; then
         # return list of available signals
-        _signals
+        _signals -
+        COMPREPLY+=( $( compgen -W "-s -l" -- "$cur" ) )
     else
         # return list of available PIDs
         _pids
diff --git a/completions/killall b/completions/killall
index 8d05d13..9a17ec2 100644
--- a/completions/killall
+++ b/completions/killall
@@ -2,11 +2,27 @@
 
 _killall()
 {
-    local cur prev words cword
-    _init_completion || return
+    local cur prev words cword split
+    _init_completion -s || return
+
+    case $prev in
+        -Z|--context|-o|--older-than|-y|--younger-than|-V|--version)
+            return
+            ;;
+        -s|--signal)
+            [[ $1 == *killall ]] && _signals
+            return
+            ;;
+        -u|--user)
+            _allowed_users
+            return
+            ;;
+    esac
+
+    $split && return
 
     if [[ $cword -eq 1 && "$cur" == -* ]]; then
-        _signals
+        _signals -
     else
         _pnames
     fi
diff --git a/test/lib/completions/kill.exp b/test/lib/completions/kill.exp
index 1e80fe6..bc07bc4 100644
--- a/test/lib/completions/kill.exp
+++ b/test/lib/completions/kill.exp
@@ -12,14 +12,16 @@ setup
 
 
 assert_complete_any "kill 1"
-
-
 sync_after_int
 
 
-assert_complete [get_signals] "kill -"
+assert_complete [get_signals] "kill -s "
+sync_after_int
 
 
+set expected [get_signals -]
+lappend expected "-l" "-s"
+assert_complete [lsort -unique $expected] "kill -"
 sync_after_int
 
 
diff --git a/test/lib/completions/killall.exp b/test/lib/completions/killall.exp
index ae8b3d6..1ee3ade 100644
--- a/test/lib/completions/killall.exp
+++ b/test/lib/completions/killall.exp
@@ -17,7 +17,7 @@ assert_complete_any "killall "
 sync_after_int
 
 
-assert_complete [get_signals] "killall -"
+assert_complete [get_signals -] "killall -"
 
 
 sync_after_int
diff --git a/test/lib/library.exp b/test/lib/library.exp
index 4ff2885..35eddf8 100644
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@ -659,8 +659,9 @@ proc get_hosts_avahi {} {
 # Get signals
 # This function is written in analogy to the bash function `_signals()' in
 # `bash_completion'.
+# @param prefix
 # @return list  Signals starting with `SIG', but with the `SIG' prefix removed.
-proc get_signals {} {
+proc get_signals {{prefix ""}} {
     set signals {}
     foreach signal [exec bash -c {compgen -A signal}] {
             # Does signal start with `SIG'?
@@ -668,7 +669,7 @@ proc get_signals {} {
                 # Remove `SIG' prefix
             set signal [string range $signal 3 end]
                 # Add signal (with dash (-) prefix) to list
-            lappend signals -$signal
+            lappend signals $prefix$signal
         }
     }
     return $signals

-- 
bash-completion



More information about the Bash-completion-commits mailing list