aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-10-16 20:43:38 +1300
committerTom Ryder <tom@sanctum.geek.nz>2013-10-16 20:43:38 +1300
commit601936246d321a3a59f9edeb0a8e682dc35c4cea (patch)
tree20a22a777683c231bd6f69e336ff114228aefa8c /bash
parentStart versioning all bashrc.d files (diff)
downloaddotfiles-601936246d321a3a59f9edeb0a8e682dc35c4cea.tar.gz
dotfiles-601936246d321a3a59f9edeb0a8e682dc35c4cea.zip
Add completion for pass(1)
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/pass.bash50
1 files changed, 50 insertions, 0 deletions
diff --git a/bash/bashrc.d/pass.bash b/bash/bashrc.d/pass.bash
new file mode 100644
index 00000000..05e3032b
--- /dev/null
+++ b/bash/bashrc.d/pass.bash
@@ -0,0 +1,50 @@
+# Completion for pass(1), adapted from source package; still needs some tweaking
+_pass()
+{
+ # Get current word, prefix, and suffix
+ local word=${COMP_WORDS[COMP_CWORD]}
+ local prefix=${PASSWORD_STORE_DIR:-$HOME/.password-store}
+ local suffix=.gpg
+
+ # Iterate through possible completions
+ local IFS=$'\n'
+ local items=( $(compgen -f "$prefix"/"$word") )
+ local item
+ for item in "${items[@]}"; do
+ if [[ $item == "$prefix"/.* ]]; then
+ continue
+ fi
+
+ # If there is a unique match, and it is a directory with one entry, then
+ # recursively autocomplete the subentry as well
+ if ((${#items[@]} == 1)); then
+ local subitems
+ while [[ -d $item ]]; do
+ subitems=( $(compgen -f "$item"/) )
+ if ((${#subitems[@]} == 1)); then
+ item=${subitems[0]}
+ else
+ break
+ fi
+ done
+ fi
+
+ # Append slash to directories
+ if [[ -d $item ]]; then
+ item=$item/
+ fi
+
+ # Add item to possible completions
+ item=${item%$suffix}
+ item=${item#$prefix/}
+ COMPREPLY=("${COMPREPLY[@]}" "$item")
+ done
+}
+
+# Completion only has -o nospace in Bash >=3.0
+if ((${BASH_VERSINFO[0]} >= 3)); then
+ complete -o filenames -o nospace -F _pass pass
+else
+ complete -o filenames -F _pass pass
+fi
+