aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/keep.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:48:02 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:48:02 +1300
commit32ca9ad0fa8d7691022a44989c1832672fb51548 (patch)
tree9ef3779f21a9f2c500d62ca3a31ec37aec930af8 /bash/bash_completion.d/keep.bash
parentMerge branch 'release/v2.5.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-32ca9ad0fa8d7691022a44989c1832672fb51548.tar.gz
dotfiles-32ca9ad0fa8d7691022a44989c1832672fb51548.zip
Merge branch 'release/v2.6.0'v2.6.0
* release/v2.6.0: (26 commits) Bump VERSION Overhaul and expand abook address Bash completion Restore correct completion function for mutt(1) Use simpler keyword complete for `path` subcommand Break up a couple of long lines Remove unneeded local array declaration Remove unneeded empty result short circuit Remove redundant error code in short circuits Adjust loop short circuits and pattern matches Remove unneeded quoting in case statement Remove needless line breaks from git completion Use inverting exclam mark outside conditional Remove stray comment no longer applicable Use array+=() syntax in two Bash completion files Remove null-result guard from completion gens Use simpler method of no case completion check Overhaul `keep` completion Simplify an array operation in `bd` completion Overhaul text filename generation Use full `if` condition for SSH hostname comp src ...
Diffstat (limited to 'bash/bash_completion.d/keep.bash')
-rw-r--r--bash/bash_completion.d/keep.bash101
1 files changed, 43 insertions, 58 deletions
diff --git a/bash/bash_completion.d/keep.bash b/bash/bash_completion.d/keep.bash
index 77b37059..00b1469e 100644
--- a/bash/bash_completion.d/keep.bash
+++ b/bash/bash_completion.d/keep.bash
@@ -2,71 +2,56 @@
# stuff that's already kept
_keep() {
- # Default is to complete with function and variable names
+ # Determine what we're doing based on first completion word
local mode
- mode=names
-
- # Iterate through the words up to the previous word to figure out how to
- # complete this one
- local i
- for ((i = 0; i < COMP_CWORD; i++)) ; do
- case ${COMP_WORDS[i]} in
- --)
- mode=names
- break
- ;;
- -d)
- mode=kept
- break
- ;;
+ mode=keep
+ if ((COMP_CWORD > 1)) ; then
+ case ${COMP_WORDS[1]} in
+ -h) return 1 ;;
+ -d) mode=delete ;;
esac
- done
+ fi
- # Complete with appropriate mode
- case $mode in
- names)
- local word
- while IFS= read -r word ; do
- [[ -n $word ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=$word
- done < <(compgen -A function -A variable \
- -- "${COMP_WORDS[COMP_CWORD]}")
- ;;
- kept)
- local word
- while IFS= read -r word ; do
- [[ -n $word ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=$word
- done < <(
- shopt -s dotglob nullglob
+ # Collect words from an appropriate type of completion
+ local word
+ while read -r word ; do
+ [[ -n $word ]] || continue
+ COMPREPLY[${#COMPREPLY[@]}]=$word
+ done < <(
- # Make globbing case-insensitive if appropriate; is there a cleaner way
- # to find this value?
- while read -r _ option value ; do
- case $option in
- (completion-ignore-case)
- case $value in
- (on)
- shopt -s nocaseglob
- break
- ;;
- esac
+ # Switch on second word; is it a -d option?
+ case $mode in
+
+ # Keepable names: all functions and variables
+ (keep)
+ compgen -A function -A variable \
+ -- "${COMP_WORDS[COMP_CWORD]}"
+ ;;
+
+ # Kept names: .bash-suffixed names in keep dir
+ (delete)
+ # Make globs behave correctly
+ shopt -s nullglob
+ while read -r _ setting ; do
+ case $setting in
+ ('completion-ignore-case on')
+ shopt -s nocaseglob
+ break
;;
esac
done < <(bind -v)
- keep=${BASHKEEP:-"$HOME"/.bashkeep.d}
- declare -a keeps
- keeps=("$keep"/"${COMP_WORDS[COMP_CWORD]}"*.bash)
- keeps=("${keeps[@]##*/}")
- keeps=("${keeps[@]%.bash}")
- if ((${#keeps[@]})) ; then
- printf '%s\n' "${keeps[@]}"
- else
- printf '\n'
- fi
- )
- ;;
- esac
+ # Build list of kept names
+ dir=${BASHKEEP:-"$HOME"/.bashkeep.d}
+ cword=${COMP_WORDS[COMP_CWORD]}
+ kept=("$dir"/"$cword"*.bash)
+ kept=("${kept[@]##*/}")
+ kept=("${kept[@]%.bash}")
+
+ # Print kept names
+ printf '%s\n' "${kept[@]}"
+ ;;
+ esac
+ )
}
complete -F _keep keep