From b074e1d55a5acaeaaf6402a87e0cb45de16a8911 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 23:31:50 +1300 Subject: Break bash/bashrc.d/completion.bash inline lists Break the sometimes long list of target keywords after the `complete` builtin and its options into newline-separated lists. This should make reading these lists a little easier, and also confuses Vim's syntax highlighting somewhat less. --- bash/bashrc.d/completion.bash | 85 +++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash index 51de24b8..eaf6c5f5 100644 --- a/bash/bashrc.d/completion.bash +++ b/bash/bashrc.d/completion.bash @@ -4,53 +4,100 @@ # If COMP_WORDBREAKS has a value, strip all colons from it; this allows # completing filenames correctly, since a colon is not a shell metacharacter: # (E13) -[[ -n $COMP_WORDBREAKS ]] && COMP_WORDBREAKS=${COMP_WORDBREAKS//:} +if [[ -n $COMP_WORDBREAKS ]] ; then + COMP_WORDBREAKS=${COMP_WORDBREAKS//:} +fi # If ~/.hosts exists, use that as the host completion file rather than # /etc/hosts, so I can populate the list myself -[[ -f $HOME/.hosts ]] && HOSTFILE=$HOME/.hosts +if [[ -f $HOME/.hosts ]] ; then + HOSTFILE=$HOME/.hosts +fi # Aliases -complete -A alias unalias +complete -A alias \ + unalias # Bash builtins -complete -A builtin builtin -complete -A enabled disable -complete -A disabled enable +complete -A builtin \ + builtin +complete -A enabled \ + disable +complete -A disabled \ + enable # Bash options -complete -A setopt set +complete -A setopt \ + set # Commands -complete -A command alias command complete compopt coproc exec if hash time \ - type until while +complete -A command \ + alias \ + command \ + complete \ + compopt \ + coproc \ + exec \ + if \ + hash \ + time \ + type \ + until \ + while # Directories -complete -A directory cd pushd mkdir rmdir +complete -A directory \ + cd \ + pushd \ + mkdir \ + rmdir # Functions and variables -complete -A function function -complete -A function -A variable declare export local readonly typeset unset -complete -A variable for getopts let read select +complete -A function \ + function +complete -A function -A variable \ + declare \ + export \ + local \ + readonly \ + typeset \ + unset +complete -A variable \ + for \ + getopts \ + let \ + read \ + select # Help topics complete -A helptopic help # Jobspecs -complete -P '%' -A job disown fg jobs -complete -P '%' -A stopped bg +complete -P '%' -A job \ + disown \ + fg \ + jobs +complete -P '%' -A stopped \ + bg # Readline bindings -complete -A binding bind +complete -A binding \ + bind # Shell options -complete -A shopt shopt +complete -A shopt \ + shopt # Signal names -complete -A signal trap +complete -A signal \ + trap # The `mapfile` builtin in Bash >= 4.0 -((BASH_VERSINFO[0] >= 4)) && complete -A arrayvar mapfile readarray +if ((BASH_VERSINFO[0] >= 4)) ; then + complete -A arrayvar \ + mapfile \ + readarray +fi # If we have dynamic completion loading (Bash>=4.0), use it if ((BASH_VERSINFO[0] >= 4)) ; then -- cgit v1.2.3 From 05a5347ee0bcb634fe706c3f522769a35fe245fb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 23:34:36 +1300 Subject: Add "do", "then" keywords to Bash completion The Bash keywords "do" and "then" will be followed by another command. Adding them to this list means that pressing tab after "if foo ; then b" will complete for all command names beginning with "b". I was actually a little surprised that this worked, but there isn't really any reason to be; they're shell words just like everything else, not metasyntactic characters or anything like that. --- bash/bashrc.d/completion.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash index eaf6c5f5..eb01dda2 100644 --- a/bash/bashrc.d/completion.bash +++ b/bash/bashrc.d/completion.bash @@ -37,9 +37,11 @@ complete -A command \ complete \ compopt \ coproc \ + do \ exec \ if \ hash \ + then \ time \ type \ until \ -- cgit v1.2.3