aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/keep.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-02 18:03:15 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-02 18:03:15 +1300
commit693fc13bb98b17938f2208fbadaec1996822fc5e (patch)
tree4a9cc6179f521528c663c8ab5f3bbc59dc57eaa0 /bash/bash_completion.d/keep.bash
parentMerge branch 'release/v2.6.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-693fc13bb98b17938f2208fbadaec1996822fc5e.tar.gz
dotfiles-693fc13bb98b17938f2208fbadaec1996822fc5e.zip
Merge branch 'release/v2.7.0'v2.7.0
* release/v2.7.0: (22 commits) Bump VERSION Make separate install-bash-completion target Overhaul Bash completion scripts Reduce ud() completion to just dirnames Upgrade uncap_ex.vim plugin to v0.3.0 Apply syntax fixes to last _text_filenames specs Rearrange _text_filenames completion a little Remove prompt() completion Throw away chgrp completion Throw away Git Bash completion Remove mysql(1) completion Use consistent temp names for shell subfile vars Overhaul pass(1) completion Adjust syntax of two more completion loads Remove ftp(1) completion Remove `kill` completion Use the positional parameter aliases for words Overhaul bd() completion again Remove unneeded -q option to shopt -s commands Don't include dotfiles in keep() names ...
Diffstat (limited to 'bash/bash_completion.d/keep.bash')
-rw-r--r--bash/bash_completion.d/keep.bash45
1 files changed, 23 insertions, 22 deletions
diff --git a/bash/bash_completion.d/keep.bash b/bash/bash_completion.d/keep.bash
index 00b1469e..c7144684 100644
--- a/bash/bash_completion.d/keep.bash
+++ b/bash/bash_completion.d/keep.bash
@@ -1,3 +1,8 @@
+# Load _completion_ignore_case helper function
+if ! declare -F _completion_ignore_case >/dev/null ; then
+ source "$HOME"/.bash_completion.d/_completion_ignore_case.bash
+fi
+
# Complete calls to keep() with variables and functions, or if -d is given with
# stuff that's already kept
_keep() {
@@ -7,16 +12,17 @@ _keep() {
mode=keep
if ((COMP_CWORD > 1)) ; then
case ${COMP_WORDS[1]} in
+ # Help; no completion
-h) return 1 ;;
+ # Deleting; change mode
-d) mode=delete ;;
esac
fi
# Collect words from an appropriate type of completion
- local word
- while read -r word ; do
- [[ -n $word ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=$word
+ local ci comp
+ while read -r comp ; do
+ COMPREPLY[ci++]=$comp
done < <(
# Switch on second word; is it a -d option?
@@ -24,32 +30,27 @@ _keep() {
# Keepable names: all functions and variables
(keep)
- compgen -A function -A variable \
- -- "${COMP_WORDS[COMP_CWORD]}"
+ compgen -A function -A variable -- "$2"
;;
# Kept names: .bash-suffixed names in keep dir
(delete)
+
# Make globs behave correctly
+ shopt -u dotglob
shopt -s nullglob
- while read -r _ setting ; do
- case $setting in
- ('completion-ignore-case on')
- shopt -s nocaseglob
- break
- ;;
- esac
- done < <(bind -v)
+ if _completion_ignore_case ; then
+ shopt -s nocaseglob
+ fi
# 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[@]}"
+ bashkeep=${BASHKEEP:-"$HOME"/.bashkeep.d}
+ for keep in "$bashkeep"/"$2"*.bash ; do
+ ! [[ -d $keep ]] || continue
+ keep=${keep##*/}
+ keep=${keep%.bash}
+ printf '%s\n' "$keep"
+ done
;;
esac
)