pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

_pashage (4244B)


      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 		;;
     82 	   (generate)
     83 		_arguments -s -w -S \
     84 		    '(-c --clip -q --qrcode)'{-c,--clip}'[copy password to clipboard]' \
     85 		    '(-c --clip -q --qrcode)'{-q,--qrcode}'[display password as QR-code]' \
     86 		    '(-f --force -i --in-place)'{-f,--force}'[overwrite existing entry]' \
     87 		    '(-f --force -i --in-place)'{-i,--in-place}'[replace first line]' \
     88 		    '(-m --multiline)'{-m,--multiline}'[enter extra lines after password]' \
     89 		    '(-n --no-symbols)'{-m,--multiline}'[don'\''t include symbols in password]' \
     90 		    '(-t --try)'{-t,--try}'[ask confirmation before saving entry]'
     91 		_pashage_entries_and_dirs
     92 		;;
     93 	   (git)
     94 		;;
     95 	   (gitconfig)
     96 		;;
     97 	   (grep)
     98 		;;
     99 	   (help|version)
    100 		_message "No arguments"
    101 		;;
    102 	   (init)
    103 		_arguments -s -w -S \
    104 		    '(-i --interactive -k --keep)'{-i,--interactive}'[reencrypt interactively]' \
    105 		    '(-i --interactive -k --keep)'{-k,--keep}'[do not reencrypt]' \
    106 		    '(-p --path)'{-p-,--path=-}'[subdirectory]:dir:'
    107 		;;
    108 	   (insert)
    109 		_arguments -s -w -S \
    110 		    '(-e --echo -m --multiline)'{-e,--echo}'[echo password to conole]' \
    111 		    '(-e --echo -m --multiline)'{-m,--multiline}'[insert multiple lines]' \
    112 		    '(-f --force)'{-f,--force}'[overwrite without asking]'
    113 		;;
    114 	   (ls|list)
    115 		_pashage_dirs
    116 		;;
    117 	   (random)
    118 		;;
    119 	   (reencrypt)
    120 		;;
    121 	   (remove|rm|delete)
    122 		_arguments -s -w -S \
    123 		    '(-f --force)'{-f,--force}'[delete without asking]' \
    124 		    '(-r --recursive)'{-r,--recursive}'[delete directories]'
    125 		_pashage_entries_and_dirs
    126 		;;
    127 	   (show)
    128 		_arguments -s -w -S \
    129 		    '(-c --clip -q --qrcode)'{-c-,--clip=-}'[clipboard a line]:line:' \
    130 		    '(-c --clip -q --qrcode)'{-q-,--qrcode=-}'[display a line as QR-code]:line:'
    131 		_pashage_entries
    132 		;;
    133 	esac
    134 }
    135 
    136 # vim ft=zsh