summaryrefslogtreecommitdiff
path: root/src/completion
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-03-22 12:01:52 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2014-03-22 12:03:12 -0600
commit47fed2c5d47a03fad7b91bfb890eed257e9c1b2d (patch)
tree46666ba401340524ab9c217a062c366f6e5ec818 /src/completion
parent414bab7d973b50431854496811608c549fb541e1 (diff)
downloadpass-47fed2c5d47a03fad7b91bfb890eed257e9c1b2d.tar.gz
pass-47fed2c5d47a03fad7b91bfb890eed257e9c1b2d.tar.bz2
pass-47fed2c5d47a03fad7b91bfb890eed257e9c1b2d.zip
Makefile: do not use recursion and organize
Diffstat (limited to 'src/completion')
-rw-r--r--src/completion/pass.bash-completion87
-rw-r--r--src/completion/pass.fish-completion104
-rw-r--r--src/completion/pass.zsh-completion116
3 files changed, 307 insertions, 0 deletions
diff --git a/src/completion/pass.bash-completion b/src/completion/pass.bash-completion
new file mode 100644
index 0000000..d0ef012
--- /dev/null
+++ b/src/completion/pass.bash-completion
@@ -0,0 +1,87 @@
+# completion file for bash
+
+# Copyright (C) 2012 Jason A. Donenfeld <Jason@zx2c4.com> and
+# Brian Mattern <rephorm@rephorm.com>. All Rights Reserved.
+# This file is licensed under the GPLv2+. Please see COPYING for more information.
+
+_pass_complete_entries () {
+ prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}"
+ suffix=".gpg"
+ autoexpand=${1:-0}
+
+ local IFS=$'\n'
+ local items=($(compgen -f $prefix$cur))
+ 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
+ # autocomplete the subentry as well (recursively)
+ if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then
+ while [[ -d $item ]]; do
+ local subitems=($(compgen -f "$item/"))
+ if [[ ${#subitems[@]} -eq 1 ]]; then
+ item="${subitems[0]}"
+ else
+ break
+ fi
+ done
+ fi
+
+ # append / to directories
+ [[ -d $item ]] && item="$item/"
+
+ item="${item%$suffix}"
+ COMPREPLY+=("${item#$prefix}")
+ done
+}
+
+_pass_complete_keys () {
+ local IFS=$'\n'
+ # Extract names and email addresses from gpg --list-keys
+ local keys="$(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')"
+ COMPREPLY+=($(compgen -W "${keys}" -- ${cur}))
+}
+
+_pass()
+{
+ COMPREPLY=()
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ local commands="init ls show insert generate edit rm git help version"
+ if [[ $COMP_CWORD -gt 1 ]]; then
+ case "${COMP_WORDS[1]}" in
+ init)
+ COMPREPLY+=($(compgen -W "-e --reencrypt" -- ${cur}))
+ _pass_complete_keys
+ ;;
+ ls|list|edit)
+ _pass_complete_entries
+ ;;
+ show|-*)
+ COMPREPLY+=($(compgen -W "-c --clip" -- ${cur}))
+ _pass_complete_entries 1
+ ;;
+ insert)
+ COMPREPLY+=($(compgen -W "-e --echo -m --multiline -f --force" -- ${cur}))
+ _pass_complete_entries
+ ;;
+ generate)
+ COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force" -- ${cur}))
+ _pass_complete_entries
+ ;;
+ rm|remove|delete)
+ COMPREPLY+=($(compgen -W "-r --recursive -f --force" -- ${cur}))
+ _pass_complete_entries
+ ;;
+ git)
+ COMPREPLY+=($(compgen -W "init push pull config log reflog" -- ${cur}))
+ ;;
+ esac
+ else
+ COMPREPLY+=($(compgen -W "${commands}" -- ${cur}))
+ _pass_complete_entries 1
+ fi
+}
+
+complete -o filenames -o nospace -F _pass pass
diff --git a/src/completion/pass.fish-completion b/src/completion/pass.fish-completion
new file mode 100644
index 0000000..9130d1f
--- /dev/null
+++ b/src/completion/pass.fish-completion
@@ -0,0 +1,104 @@
+#!/usr/bin/env fish
+
+# Copyright (C) 2012 Dmitry Medvinsky <dmedvinsky@gmail.com>. All Rights Reserved.
+# This file is licensed under the GPLv2+. Please see COPYING for more information.
+
+set PROG 'pass'
+
+function __fish_pass_get_prefix
+ set -l prefix "$PASSWORD_STORE_DIR"
+ if [ -z "$prefix" ]
+ set prefix "$HOME/.password-store"
+ end
+ echo "$prefix"
+end
+
+function __fish_pass_needs_command
+ set -l cmd (commandline -opc)
+ if [ (count $cmd) -eq 1 -a $cmd[1] = $PROG ]
+ return 0
+ end
+ return 1
+end
+function __fish_pass_uses_command
+ set cmd (commandline -opc)
+ if [ (count $cmd) -gt 1 ]
+ if [ $argv[1] = $cmd[2] ]
+ return 0
+ end
+ end
+ return 1
+end
+
+function __fish_pass_print_gpg_keys
+ gpg2 --list-keys | grep uid | sed 's/.*<\(.*\)>/\1/'
+end
+function __fish_pass_print_entry_dirs
+ set -l prefix (__fish_pass_get_prefix)
+ set -l dirs
+ eval "set dirs "$prefix"/**/"
+ for dir in $dirs
+ set entry (echo "$dir" | sed "s#$prefix/\(.*\)#\1#")
+ echo "$entry"
+ end
+end
+function __fish_pass_print_entries
+ set -l prefix (__fish_pass_get_prefix)
+ set -l files
+ eval "set files "$prefix"/**.gpg"
+ for file in $files
+ set file (echo "$file" | sed "s#$prefix/\(.*\)\.gpg#\1#")
+ echo "$file"
+ end
+end
+function __fish_pass_print_entries_and_dirs
+ __fish_pass_print_entry_dirs
+ __fish_pass_print_entries
+end
+
+
+complete -c $PROG -e
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a help -d 'Command: show usage help'
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a version -d 'Command: show program version'
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a init -d 'Command: initialize new password storage'
+complete -c $PROG -f -A -n '__fish_pass_uses_command init' -s e -l reencrypt -d 'Reencrypt existing passwords using new gpg-id'
+complete -c $PROG -f -A -n '__fish_contains_opt -s e reencrypt' -a '(__fish_pass_print_gpg_keys)'
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a ls -d 'Command: list passwords'
+complete -c $PROG -f -A -n '__fish_pass_uses_command ls' -a "(__fish_pass_print_entry_dirs)"
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a insert -d 'Command: insert new password'
+complete -c $PROG -f -A -n '__fish_pass_uses_command insert' -s e -l echo -d 'Echo the password on console'
+complete -c $PROG -f -A -n '__fish_pass_uses_command insert' -s m -l multiline -d 'Provide multiline password entry'
+complete -c $PROG -f -A -n '__fish_pass_uses_command insert' -s f -l force -d 'Do not prompt before overwritting'
+complete -c $PROG -f -A -n '__fish_pass_uses_command insert' -a "(__fish_pass_print_entry_dirs)"
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a generate -d 'Command: generate new password'
+complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s n -l no-symbols -d 'Do not use special symbols'
+complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s c -l clip -d 'Put the password in clipboard'
+complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s f -l force -d 'Do not prompt before overwritting'
+complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -a "(__fish_pass_print_entry_dirs)"
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a rm -d 'Command: remove existing password'
+complete -c $PROG -f -A -n '__fish_pass_uses_command rm' -s r -l recursive -d 'Remove password groups recursively'
+complete -c $PROG -f -A -n '__fish_pass_uses_command rm' -s f -l force -d 'Force removal'
+complete -c $PROG -f -A -n '__fish_pass_uses_command rm' -a "(__fish_pass_print_entries_and_dirs)"
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a edit -d 'Command: edit password using text editor'
+complete -c $PROG -f -A -n '__fish_pass_uses_command edit' -a "(__fish_pass_print_entries)"
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a show -d 'Command: show existing password'
+complete -c $PROG -f -A -n '__fish_pass_uses_command show' -s c -l clip -d 'Put password in clipboard'
+complete -c $PROG -f -A -n '__fish_pass_uses_command show' -a "(__fish_pass_print_entries)"
+# When no command is given, `show` is defaulted.
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -s c -l clip -d 'Put password in clipboard'
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a "(__fish_pass_print_entries)"
+complete -c $PROG -f -A -n '__fish_pass_uses_command -c' -a "(__fish_pass_print_entries)"
+complete -c $PROG -f -A -n '__fish_pass_uses_command --clip' -a "(__fish_pass_print_entries)"
+
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a git -d 'Command: execute a git command'
+complete -c $PROG -f -A -n '__fish_pass_uses_command git' -a 'init' -d 'Initialize git repository'
+complete -c $PROG -f -A -n '__fish_pass_uses_command git' -a 'push' -d 'Push changes to remote repo'
+complete -c $PROG -f -A -n '__fish_pass_uses_command git' -a 'pull' -d 'Pull changes from remote repo'
+complete -c $PROG -f -A -n '__fish_pass_uses_command git' -a 'log' -d 'View changelog'
diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
new file mode 100644
index 0000000..0bb14de
--- /dev/null
+++ b/src/completion/pass.zsh-completion
@@ -0,0 +1,116 @@
+#compdef pass
+
+# Copyright (C) 2012:
+# Johan Venant <jvenant@invicem.pro>
+# Brian Mattern <rephorm@rephorm.com>
+# Jason A. Donenfeld <Jason@zx2c4.com>.
+# All Rights Reserved.
+# This file is licensed under the GPLv2+. Please see COPYING for more information.
+
+_pass () {
+ local cmd
+ if (( CURRENT > 2)); then
+ cmd=${words[2]}
+ # Set the context for the subcommand.
+ curcontext="${curcontext%:*:*}:pass-$cmd"
+ # Narrow the range of words we are looking at to exclude `pass'
+ (( CURRENT-- ))
+ shift words
+ # Run the completion for the subcommand
+ case "${cmd}" in
+ init)
+ _arguments : \
+ "-r[re-encrypt existing passwords]" \
+ "--reencrypt[re-encrypt existing passwords]"
+ _pass_complete_keys
+ ;;
+ ls|list|edit)
+ _pass_complete_entries_with_subdirs
+ ;;
+ insert)
+ _arguments : \
+ "-e[echo password to console]" \
+ "--echo[echo password to console]" \
+ "-m[multiline]" \
+ "--multiline[multiline]"
+ _pass_complete_entries_with_subdirs
+ ;;
+ generate)
+ _arguments : \
+ "-n[don't include symbols in password]" \
+ "--no-symbols[don't include symbols in password]" \
+ "-c[copy password to the clipboard]" \
+ "--clip[copy password to the clipboard]"
+ _pass_complete_entries_with_subdirs
+ ;;
+ rm)
+ _arguments : \
+ "-f[force deletion]" \
+ "--force[force deletion]" \
+ "-r[recursively delete]" \
+ "--recursive[recursively delete]"
+ _pass_complete_entries_with_subdirs
+ ;;
+ git)
+ local -a subcommands
+ subcommands=(
+ "init:Initialize git repository"
+ "push:Push to remote repository"
+ "pull:Pull from remote repository"
+ "config:Show git config"
+ "log:Show git log"
+ "reflog:Show git reflog"
+ )
+ _describe -t commands 'pass git' subcommands
+ ;;
+ show|*)
+ _pass_cmd_show
+ ;;
+ esac
+ else
+ local -a subcommands
+ subcommands=(
+ "init:Initialize new password storage"
+ "ls:List passwords"
+ "show:Decrypt and print a password"
+ "insert:Insert a new password"
+ "generate:Generate a new password using pwgen"
+ "edit:Edit a password with \$EDITOR"
+ "rm:Remove the password"
+ "git:Call git on the password store"
+ "version:Output version information"
+ "help:Output help message"
+ )
+ _describe -t commands 'pass' subcommands
+ _arguments : \
+ "--version[Output version information]" \
+ "--help[Output help message]"
+ _pass_cmd_show
+ fi
+}
+
+_pass_cmd_show () {
+ _arguments : \
+ "-c[put it on the clipboard]" \
+ "--clip[put it on the clipboard]"
+ _pass_complete_entries
+}
+_pass_complete_entries_helper () {
+ local IFS=$'\n'
+ local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
+ _values -C 'passwords' $(find -L "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print | sed -e "s#${prefix}.##" -e 's#\.gpg##' | sort)
+}
+
+_pass_complete_entries_with_subdirs () {
+ _pass_complete_entries_helper
+}
+
+_pass_complete_entries () {
+ _pass_complete_entries_helper -type f
+}
+
+_pass_complete_keys () {
+ local IFS=$'\n'
+ # Extract names and email addresses from gpg --list-keys
+ _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
+}