_pashage (4493B)
1 #compdef _pashage pashage 2 #autoload 3 4 # pashage - age-backed POSIX password manager 5 # Copyright (C) 2024 Natasha Kerensikova 6 # 7 # This program is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License 9 # as published by the Free Software Foundation; either version 2 10 # of the License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 21 function _pashage_prefix { 22 local prefix 23 prefix="${PASHAGE_DIR:-${PASSAGE_DIR:-${PASSWORD_STORE_DIR:-${HOME}/.passage/store}}}" 24 printf '%s' "${prefix%/}" 25 } 26 27 function _pashage_dirs { 28 local prefix="$(_pashage_prefix)" 29 local -a _secret_dirs 30 for item in "$prefix"/**/*(/); do 31 _secret_dirs=($_secret_dirs "${item#"$prefix/"}/") 32 done 33 _multi_parts / _secret_dirs 34 } 35 36 function _pashage_entries { 37 local prefix="$(_pashage_prefix)" 38 local -a _secret_entries 39 for item in "$prefix"/**/*.age(:r); do 40 _secret_entries=($_secret_entries "${item#"$prefix/"}") 41 done 42 _multi_parts / _secret_entries 43 } 44 45 function _pashage_entries_and_dirs { 46 local prefix="$(_pashage_prefix)" 47 local -a _secrets 48 for item in "$prefix"/**/*(/); do 49 _secrets=($_secrets "${item#"$prefix/"}/") 50 done 51 for item in "$prefix"/**/*.age(:r); do 52 _secrets=($_secrets "${item#"$prefix/"}") 53 done 54 _multi_parts / _secrets 55 } 56 57 # $prefx/**/*.age(:r) 58 59 function _pashage { 60 local curcontext="$curcontext" 61 local state state_descr line 62 typeset -A opt_args 63 64 _arguments -C \ 65 "1: :(copy cp delete edit find generate git gitconfig grep help init insert list ls move mv random reencrypt remove rm show version)" \ 66 "*::arg:->args" 67 68 case $line[1] in 69 (copy|cp|move|mv) 70 _arguments -s -w -S \ 71 '(-e --reencrypt -i --interactive -k --keep)'{-e,--reencrypt}'[force reencryption]' \ 72 '(-e --reencrypt -i --interactive -k --keep)'{-i,--interactive}'[ask before reencryption]' \ 73 '(-e --reencrypt -i --interactive -k --keep)'{-k,--keep}'[without reencryption]' \ 74 '(-f --force)'{-f,--force}'[force overwriting]' 75 _pashage_entries_and_dirs 76 ;; 77 (edit) 78 _pashage_entries 79 ;; 80 (find) 81 _arguments -s -w -S \ 82 '(-r --raw)'{-r,--raw}'[raw list]' 83 ;; 84 (generate) 85 _arguments -s -w -S \ 86 '(-c --clip -q --qrcode)'{-c,--clip}'[copy password to clipboard]' \ 87 '(-c --clip -q --qrcode)'{-q,--qrcode}'[display password as QR-code]' \ 88 '(-f --force -i --in-place)'{-f,--force}'[overwrite existing entry]' \ 89 '(-f --force -i --in-place)'{-i,--in-place}'[replace first line]' \ 90 '(-m --multiline)'{-m,--multiline}'[enter extra lines after password]' \ 91 '(-n --no-symbols)'{-m,--multiline}'[don'\''t include symbols in password]' \ 92 '(-t --try)'{-t,--try}'[ask confirmation before saving entry]' 93 _pashage_entries_and_dirs 94 ;; 95 (git) 96 ;; 97 (gitconfig) 98 ;; 99 (grep) 100 ;; 101 (help|version) 102 _message "No arguments" 103 ;; 104 (init) 105 _arguments -s -w -S \ 106 '(-i --interactive -k --keep)'{-i,--interactive}'[reencrypt interactively]' \ 107 '(-i --interactive -k --keep)'{-k,--keep}'[do not reencrypt]' \ 108 '(-p --path)'{-p-,--path=-}'[subdirectory]:dir:' 109 ;; 110 (insert) 111 _arguments -s -w -S \ 112 '(-e --echo -m --multiline)'{-e,--echo}'[echo password to conole]' \ 113 '(-e --echo -m --multiline)'{-m,--multiline}'[insert multiple lines]' \ 114 '(-f --force)'{-f,--force}'[overwrite without asking]' 115 ;; 116 (ls|list) 117 _arguments -s -w -S \ 118 '(-r --raw)'{-r,--raw}'[raw list]' 119 _pashage_dirs 120 ;; 121 (random) 122 ;; 123 (reencrypt) 124 _arguments -s -w -S \ 125 '(-i --interactive)'{-i,--interactive}'[ask for each entry]' 126 _pashage_entries_and_dirs 127 ;; 128 (remove|rm|delete) 129 _arguments -s -w -S \ 130 '(-f --force)'{-f,--force}'[delete without asking]' \ 131 '(-r --recursive)'{-r,--recursive}'[delete directories]' 132 _pashage_entries_and_dirs 133 ;; 134 (show) 135 _arguments -s -w -S \ 136 '(-c --clip -q --qrcode)'{-c-,--clip=-}'[clipboard a line]:line:' \ 137 '(-c --clip -q --qrcode)'{-q-,--qrcode=-}'[display a line as QR-code]:line:' 138 _pashage_entries 139 ;; 140 esac 141 } 142 143 # vim ft=zsh