summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2011-11-14 22:12:15 +0200
committerVille Skyttä <ville.skytta@iki.fi>2011-11-14 22:12:15 +0200
commit87d31eb85d5f3d4f603dccc9d9afe8853457d4fa (patch)
tree9940764c2e04d37cfc50dc230dcf45b660c4bfff
parentb9069afa55526aeb6d53a7c1baeae4f9498d3feb (diff)
downloadbash-completion-87d31eb85d5f3d4f603dccc9d9afe8853457d4fa.tar.gz
_command_offset: Simplify dynamic loading of completions we don't have yet.
-rw-r--r--bash_completion29
1 files changed, 12 insertions, 17 deletions
diff --git a/bash_completion b/bash_completion
index 1782bc6d..114140e6 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1638,24 +1638,17 @@ _command_offset()
else
local cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]}
local cspec=$( complete -p $cmd 2>/dev/null )
+
+ # If we have no completion for $cmd yet, see if we have for basename
+ if [[ ! $cspec && $cmd == */* ]]; then
+ cspec=$( complete -p ${cmd##*/} 2>/dev/null )
+ [[ $cspec ]] && compcmd=${cmd##*/}
+ fi
+ # If still nothing, just load it for the basename
if [[ ! $cspec ]]; then
- if [[ $cmd == */* ]]; then
- # Load completion for full path
- _completion_loader $cmd
- if [[ $? -eq 124 ]]; then
- # Success, but we may now have the full path completion...
- cspec=$( complete -p $cmd 2>/dev/null )
- if [[ ! $cspec ]]; then
- # ...or just the basename one.
- compcmd=${cmd##*/}
- cspec=$( complete -p $compcmd 2>/dev/null )
- fi
- fi
- else
- # Simple, non-full path case.
- _completion_loader $cmd
- [[ $? -eq 124 ]] && cspec=$( complete -p $cmd 2>/dev/null )
- fi
+ compcmd=${cmd##*/}
+ _completion_loader $compcmd
+ cspec=$( complete -p $compcmd 2>/dev/null )
fi
if [[ -n $cspec ]]; then
@@ -1690,6 +1683,8 @@ _command_offset()
COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) )
fi
elif [[ ${#COMPREPLY[@]} -eq 0 ]]; then
+ # XXX will probably never happen as long as completion loader loads
+ # *something* for every command thrown at it ($cspec != empty)
_minimal
fi
fi