aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:46:21 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:46:21 +1300
commit527b544538e7309ee0bd6a2108755bfd8e3c2bca (patch)
tree0d0d99b80c5821bd24d269625b8da15528121144
parent9af93d72284d22b24e27080e38231f32c2e45f54 (diff)
downloaddotfiles-527b544538e7309ee0bd6a2108755bfd8e3c2bca.tar.gz
Overhaul and expand abook address Bash completion
-rw-r--r--bash/bash_completion.d/_abook_addresses.bash37
1 files changed, 30 insertions, 7 deletions
diff --git a/bash/bash_completion.d/_abook_addresses.bash b/bash/bash_completion.d/_abook_addresses.bash
index 8e341172..e79eef42 100644
--- a/bash/bash_completion.d/_abook_addresses.bash
+++ b/bash/bash_completion.d/_abook_addresses.bash
@@ -1,10 +1,33 @@
# Email addresses from abook(1)
_abook_addresses() {
- while IFS=$'\t' read -r address _ ; do
- case $address in
- "${COMP_WORDS[COMP_CWORD]}"*)
- COMPREPLY[${#COMPREPLY[@]}]=$address
- ;;
- esac
- done < <(abook --mutt-query \@)
+
+ # Needs abook(1)
+ hash abook 2>/dev/null || return
+
+ # Iterate through words produced by subshell
+ local word
+ while read -r word ; do
+ [[ -n $word ]] || continue
+ COMPREPLY[${#COMPREPLY[@]}]=$word
+ done < <(
+
+ # Set case-insensitive matching if appropriate
+ while read -r _ setting ; do
+ case $setting in
+ ('completion-ignore-case on')
+ shopt -s nocasematch 2>/dev/null
+ break
+ ;;
+ esac
+ done < <(bind -v)
+
+ # Generate list of email addresses from abook(1)
+ while IFS=$'\t' read -r address _ ; do
+ case $address in
+ ("${COMP_WORDS[COMP_CWORD]}"*)
+ printf '%s\n' "$address"
+ ;;
+ esac
+ done < <(abook --mutt-query \@)
+ )
}