summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2011-10-26 20:44:22 +0300
committerVille Skyttä <ville.skytta@iki.fi>2011-10-26 20:44:22 +0300
commit22f88858ee658693c4cb2a76c49634360290c5b8 (patch)
treecc50cfce2c4b786ce50a5835efeabfa4af322758
parent802a72fd8f39c37c09458bdb224fd3c07f9c15a4 (diff)
downloadbash-completion-22f88858ee658693c4cb2a76c49634360290c5b8.tar.gz
_command_offset: Load undefined completions on demand.
-rw-r--r--bash_completion27
1 files changed, 21 insertions, 6 deletions
diff --git a/bash_completion b/bash_completion
index 233616f1..db1d15db 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1593,13 +1593,28 @@ _command_offset()
compopt -o filenames
COMPREPLY=( $( compgen -d -c -- "$cur" ) )
else
- local cspec 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 )
+ local cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]}
+ local cspec=$( complete -p $cmd 2>/dev/null )
+ 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
fi
+
if [[ -n $cspec ]]; then
if [ "${cspec#* -F }" != "$cspec" ]; then
# complete -F <function>