Eric Bower
·
2026-09-19
1# Completion script for the "pa" command.
2# https://github.com/biox/pa or similar simple password manager
3
4function completion/pa {
5 typeset OPTIONS ARGOPT PREFIX
6 OPTIONS=( #>#
7 "--help; show usage information"
8 ) #<#
9
10 command -f completion//parseoptions -e
11 case $ARGOPT in
12 (-)
13 command -f completion//completeoptions
14 ;;
15 ("")
16 if [ ${WORDS[#]} -le 1 ]; then
17 command -f completion/pa::completecmd
18 else
19 typeset pacmd="${WORDS[2]}"
20 case $pacmd in
21 (g|git|g*)
22 WORDS=(git "${WORDS[3,-1]}")
23 command -f completion//reexecute
24 return
25 ;;
26 esac
27
28 command -f completion//getoperands
29 case $pacmd in
30 (a|add|a*)
31 if [ ${WORDS[#]} -eq 1 ]; then
32 command -f completion/pa::categories
33 command -f completion/pa::passwords
34 fi
35 ;;
36 (d|del|d*|e|edit|e*|s|show|s*)
37 if [ ${WORDS[#]} -eq 1 ]; then
38 command -f completion/pa::passwords
39 fi
40 ;;
41 (l|list|l*)
42 if [ ${WORDS[#]} -eq 1 ]; then
43 command -f completion/pa::categories
44 fi
45 ;;
46 (m|move|m*)
47 if [ ${WORDS[#]} -eq 1 ]; then
48 command -f completion/pa::passwords
49 elif [ ${WORDS[#]} -eq 2 ]; then
50 command -f completion/pa::categories
51 command -f completion/pa::passwords
52 fi
53 ;;
54 esac
55 fi
56 ;;
57 esac
58}
59
60function completion/pa::completecmd {
61 complete -P "$PREFIX" -D "Add a password entry" add
62 complete -P "$PREFIX" -D "Delete a password entry" del
63 complete -P "$PREFIX" -D "Edit a password entry" edit
64 complete -P "$PREFIX" -D "Run git command in password dir" git
65 complete -P "$PREFIX" -D "List all entries in a category" list
66 complete -P "$PREFIX" -D "Show password for an entry" show
67 complete -P "$PREFIX" -D "Rename a password entry" move
68}
69
70function completion/pa::passwords {
71 typeset padir="${PA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/pa}/passwords"
72 if [ -d "$padir" ]; then
73 typeset list
74 typeset IFS='
75'
76 list=($(find -L "$padir" -name .git -prune -o -name "*.age" -type f -print 2>/dev/null | sed -e "s#^${padir}/##" -e "s/\.age$//" | sort))
77 if [ ${list[#]} -gt 0 ]; then
78 complete -P "$PREFIX" -- "$list"
79 fi
80 fi
81}
82
83function completion/pa::categories {
84 typeset padir="${PA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/pa}/passwords"
85 if [ -d "$padir" ]; then
86 typeset list
87 typeset IFS='
88'
89 list=($(find -L "$padir" -mindepth 1 -name .git -prune -o -type d -print 2>/dev/null | sed -e "s#^${padir}/##" | sort))
90 if [ ${list[#]} -gt 0 ]; then
91 complete -P "$PREFIX" -S / -T -- "$list"
92 fi
93 fi
94}
95
96# kak: filetype=sh