[pass] [patch] Fish shell completion for pass

Dmitry Medvinsky dmedvinsky at gmail.com
Fri Sep 21 12:19:43 CEST 2012


Hey folks,

There are some weird fish shell users out there in the wild, me included. You
might not believe it, but fish has tab completions, too (at least in v2). So I
figured, why not create completions for pass?

It might not be so feature complete as the famous zsh completions for pass, but
I don't know as I haven't used zsh for several months since I switched to fish.
It completes all the commands, options, and password entries, though.

Also, it might be kind of buggy since I haven't tested it much, but I think I'm
ready to share it so that maybe some other fish users of this list might test
it.

Enjoy,
Dmitry
-------------- next part --------------
From 369bba530e438063dd76cca684c93b832c10d83a Mon Sep 17 00:00:00 2001
From: Dmitry Medvinsky <dmedvinsky at gmail.com>
Date: Fri, 21 Sep 2012 14:09:38 +0400
Subject: [PATCH] Add fish shell completion

---
 contrib/pass.fish | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 contrib/pass.fish

diff --git a/contrib/pass.fish b/contrib/pass.fish
new file mode 100644
index 0000000..a0bbabd
--- /dev/null
+++ b/contrib/pass.fish
@@ -0,0 +1,110 @@
+#!/usr/bin/env fish
+#
+# Fish shell completions for pass.
+#
+# Copyright © 2012 Jason A. Donenfeld <Jason at zx2c4.com>
+# Pass is GNU GPL v2 licensed.
+# This completion script is, as pass itself, GNU GPL v2 licensed.
+# See COPYING file distributed with pass for more details.
+#
+# Contributed by Dmitry Medvinsky <dmedvinsky at gmail.com>
+
+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
+    gpg --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 n -l no-echo -d 'Do not 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'
-- 
1.7.12

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20120921/7c0cfa7b/attachment.asc>


More information about the Password-Store mailing list