summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2011-11-26 22:01:09 +0200
committerVille Skyttä <ville.skytta@iki.fi>2011-11-26 22:01:09 +0200
commitba24f209cafa2e7493ea08ea08c24d581b9cf39b (patch)
tree13fd6ee399f7e034d2a48da653c67c1bc4eb4f3e
parent56672db701da5e5e263090eaf37b4b708db3c63b (diff)
downloadbash-completion-ba24f209cafa2e7493ea08ea08c24d581b9cf39b.tar.gz
_variables: New function split from _init_completion.
-rw-r--r--bash_completion21
1 files changed, 15 insertions, 6 deletions
diff --git a/bash_completion b/bash_completion
index b8017d34..eaee91e0 100644
--- a/bash_completion
+++ b/bash_completion
@@ -614,6 +614,20 @@ _split_longopt()
return 1
}
+# Complete variables.
+# @return True (0) if variables were completed,
+# False (> 0) if not.
+_variables()
+{
+ if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then
+ [[ $cur == *{* ]] && local suffix=} || local suffix=
+ COMPREPLY+=( $( compgen -P ${BASH_REMATCH[1]} -S "$suffix" -v -- \
+ "${BASH_REMATCH[2]}" ) )
+ return 0
+ fi
+ return 1
+}
+
# Initialize completion and deal with various general things: do file
# and variable completion where appropriate, and adjust prev, words,
# and cword as if no redirections exist so that completions do not
@@ -654,12 +668,7 @@ _init_completion()
_get_comp_words_by_ref -n "$exclude<>&" cur prev words cword
# Complete variable names.
- if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then
- [[ $cur == *{* ]] && local suffix=} || local suffix=
- COMPREPLY=( $( compgen -P ${BASH_REMATCH[1]} -S "$suffix" -v -- \
- "${BASH_REMATCH[2]}" ) )
- return 1
- fi
+ _variables && return 1
# Complete on files if current is a redirect possibly followed by a
# filename, e.g. ">foo", or previous is a "bare" redirect, e.g. ">".