1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
# (C) 2023 Victorien Elvinger
# Completion script for the "pass" command.
function completion/pass {
OPTIONS=( #>#
"c:: --clip::; copy the password to clipboard"
"--help"
"q:: --qrcode::; encode the password in a QR Code"
"--version"
) #<#
command -f completion//parseoptions -n
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
if [ ${WORDS[#]} -eq 1 ]; then
command -f completion/pass::completecmd
command -f completion/pass::passwords
else
typeset passcmd="${WORDS[2]}"
command -f completion//parseoptions
command -f completion//getoperands
if command -vf "completion/pass::$passcmd:arg" >/dev/null 2>&1; then
command -f "completion/pass::$passcmd:arg"
elif [ ${WORDS[#]} -eq 0 ]; then
command -f completion/pass::passwords
fi
fi
;;
esac
}
function completion/pass::completecmd { #>>#
complete -P "$PREFIX" -D "copy a password" cp
complete -P "$PREFIX" -D "edit a password" edit
complete -P "$PREFIX" -D "list passwords matching a name" find
complete -P "$PREFIX" -D "generate a password" generate
complete -P "$PREFIX" -D "git commands inside the password store" git
complete -P "$PREFIX" -D "grep inside passwords" grep
complete -P "$PREFIX" -D "show help" help
complete -P "$PREFIX" -D "initialize new password store" init
complete -P "$PREFIX" -D "insert a new password" insert
complete -P "$PREFIX" -D "list passwords" list ls
complete -P "$PREFIX" -D "move a password" mv
complete -P "$PREFIX" -D "remove a password" rm
complete -P "$PREFIX" -D "show a password" show
complete -P "$PREFIX" -D "show version" version
#<<#
}
function completion/pass::cp:arg {
OPTIONS=( #>#
"f --force; don't prompt when overriding a password"
) #<#
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion//getoperands
if [ ${WORDS[#]} -lt 2 ]; then
command -f completion/pass::passwords
command -f completion/pass::subfolders
fi
;;
esac
}
function completion/pass::edit:arg {
if [ ${WORDS[#]} -eq 1 ]; then
command -f completion/pass::passwords
fi
}
function completion/pass::generate:arg {
OPTIONS=( #>#
"c --clip; copy the password to clipboard"
"f --force; override if a password with the same name exists"
"i --in-place; update the password keeping other lines unchanged"
"n --no-symbols; don't use any non-alphanumeric characters"
) #<#
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion//getoperands
if [ ${WORDS[#]} -eq 0 ]; then
command -f completion/pass::passwords
fi
;;
esac
}
function completion/pass::git:arg {
# delegate to git completion
command -f completion//reexecute
}
function completion/pass::grep:arg {
# delegate to grep completion
command -f completion//reexecute
}
function completion/pass::init:arg {
OPTIONS=( #>#
"p: --path:; path of the password store"
) #<#
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion/pass::gpgids
;;
esac
}
function completion/pass::insert:arg {
OPTIONS=( #>#
"e --echo; don't print entered characters"
"f --force; override if a password with the same name exists"
"m --multiline; add several lines in the password file"
) #<#
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion//getoperands
if [ ${WORDS[#]} -eq 0 ]; then
command -f completion/pass::passwords
fi
;;
esac
}
function completion/pass::ls:arg {
if [ ${WORDS[#]} -eq 1 ]; then
command -f completion/pass::subfolders
fi
}
function completion/pass::mv:arg {
# same completion as `pass cp`
command -f completion/pass::cp:arg
}
function completion/pass::show:arg {
OPTIONS=( #>#
"c:: --clip::; copy the password to clipboard"
"q:: --qrcode::; encode the password in a QR Code"
) #<#
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
command -f completion//getoperands
if [ ${WORDS[#]} -eq 0 ]; then
command -f completion/pass::passwords
fi
;;
esac
}
function completion/pass::rm:arg {
OPTIONS=( #>#
"f --force; don't prompt before removing"
"r --recursive; remove passwords recursively if it is a directory"
) #<#
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
# find first non-option argument parse options that modify completion behavior
typeset OPTIND=2 isrec=0
while [ $OPTIND -le ${WORDS[#]} ]; do
case ${WORDS[OPTIND]} in
(-r|--recursive)
isrec=1
;;
(-?*)
;;
(*)
break
;;
esac
OPTIND=$((OPTIND+1))
done
if [ $OPTIND -gt ${WORDS[#]} ]; then
if [ $isrec -eq 1 ]; then
command -f completion/pass::subfolders
else
command -f completion/pass::passwords
fi
fi
;;
esac
}
function completion/pass::passwords {
typeset passdir="${PASSWORD_STORE_DIR:-"$HOME/.password-store"}"
complete -P "$PREFIX" -- $(find -L "$passdir" -name '.git' -prune -o -name '*.gpg' -print 2>/dev/null | sed -e "s#${passdir}/\{0,1\}##" -e 's#\.gpg##' -e 's#\\#\\\\#g' -e 's#:#\\:#g')
}
function completion/pass::subfolders {
typeset passdir="${PASSWORD_STORE_DIR:-"$HOME/.password-store"}"
complete -P "$PREFIX" -- $(find -L "$passdir" -name '.git' -prune -o -type d -print | sed -e "s#${passdir}/\{0,1\}##" -e 's#\\#\\\\#g' -e 's#:#\\:#g')
}
function completion/pass::gpgids {
# suggest emails and public key ids
complete -P "$PREFIX" -- $(gpg2 --list-keys 2>/dev/null | grep '^uid.*>$' | sed -e 's/.*<\(.*\)>$/\1/') $(gpg2 --list-keys --with-colons 2> /dev/null | grep '^pub:' | cut -d: -f5)
}
# vim: set ft=sh ts=8 sts=8 sw=8 et:
|