[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-69-g7c34b56

Ville Skyttä ville.skytta at iki.fi
Tue Apr 12 17:29:38 UTC 2011


The following commit has been merged in the master branch:
commit 7c34b562677b9c8b8075cee0f080bcbca34d484e
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Tue Apr 12 20:28:08 2011 +0300

    Try both full path and basename completions for sudo etc (Alioth: #313065).

diff --git a/CHANGES b/CHANGES
index 8e405a0..6eaa824 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ bash-completion (2.x)
   * Load and general speedups.
   * Install only full path (no basename) completions for /etc/init.d/*.
   * Install full path /etc/rc.d/init.d/* completions.
+  * Try both full path and basename completions for sudo etc (Alioth: #313065).
 
   [ Guillaume Rousse ]
   * added puppet completion, using work from Mathieu Parent (sathieudebian.org)
diff --git a/bash_completion b/bash_completion
index 2b89abf..589016b 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1464,7 +1464,7 @@ _command()
 #
 _command_offset()
 {
-    local cur func cline cspec noglob cmd i char_offset word_offset \
+    local cur func cline cspec noglob cmd compcmd i char_offset word_offset \
         _COMMAND_FUNC _COMMAND_FUNC_ARGS
 
     word_offset=$1
@@ -1500,9 +1500,14 @@ _command_offset()
         _compopt_o_filenames
         COMPREPLY=( $( compgen -c -- "$cur" ) )
     else
-        cmd=${COMP_WORDS[0]}
-        if complete -p ${cmd##*/} &>/dev/null; then
-            cspec=$( complete -p ${cmd##*/} )
+        cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]}
+        # Do we have full path completion for $cmd?
+        if ! cspec=$( complete -p $cmd 2>/dev/null ) && [[ $cmd == */* ]]; then
+            # Nope, what about the basename?
+            compcmd=${cmd##*/}
+            cspec=$( complete -p $compcmd 2>/dev/null )
+        fi
+        if [[ -n $cspec ]]; then
             if [ "${cspec#* -F }" != "$cspec" ]; then
                 # complete -F <function>
 
@@ -1528,9 +1533,9 @@ _command_offset()
                         _compopt_o_filenames
                     fi
                 fi
-            elif [ -n "$cspec" ]; then
+            else
                 cspec=${cspec#complete};
-                cspec=${cspec%%${cmd##*/}};
+                cspec=${cspec%%$compcmd};
                 COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
             fi
         elif [ ${#COMPREPLY[@]} -eq 0 ]; then

-- 
bash-completion



More information about the Bash-completion-commits mailing list