From ff8e52c9605fa0a40d642d1ddb57ada11213ac3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 23 Oct 2011 11:02:46 +0300 Subject: _init_completion: Complete variable names. --- bash_completion | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bash_completion b/bash_completion index 4bfa4de8..716c3aaa 100644 --- a/bash_completion +++ b/bash_completion @@ -605,11 +605,11 @@ _split_longopt() return 1 } -# Initialize completion and deal with redirections: do file completion where -# appropriate, and adjust prev, words, and cword as if no redirections exist -# so that completions do not need to deal with them. Before calling this -# function, make sure cur, prev, words, and cword are local, ditto split if -# you use -s. +# 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 +# need to deal with them. Before calling this function, make sure +# cur, prev, words, and cword are local, ditto split if you use -s. # # Options: # -n EXCLUDE Passed to _get_comp_words_by_ref -n with redirection chars @@ -644,6 +644,12 @@ _init_completion() local redir="@(?([0-9])<|?([0-9&])>?(>)|>&)" _get_comp_words_by_ref -n "$exclude<>&" cur prev words cword + # Complete variable names. + if [[ $cur == \$* ]]; then + COMPREPLY=( $( compgen -P '$' -v -- "${cur#\$}" ) ) + return 1 + fi + # Complete on files if current is a redirect possibly followed by a # filename, e.g. ">foo", or previous is a "bare" redirect, e.g. ">". if [[ $cur == $redir* || $prev == $redir ]]; then -- cgit v1.2.1