Added tree view (-t)

This commit is contained in:
Dylan Araps 2019-02-25 21:46:57 +02:00
parent a5bf91c5d1
commit 484188e3d9
3 changed files with 29 additions and 10 deletions

View File

@ -46,6 +46,7 @@ OPTIONS
l Length of generated passwords. l Length of generated passwords.
c Copy password to clipboard. c Copy password to clipboard.
q Don't print password to stdout. q Don't print password to stdout.
-t Print list output as a tree.
h Show usage and exit. h Show usage and exit.
v Show version and exit. v Show version and exit.
``` ```
@ -61,7 +62,7 @@ The passwords are store in GPG encrypted files located at `${XDG_DATA_HOME:=$HOM
- [x] Add support for not generating passwords. - [x] Add support for not generating passwords.
- [x] Add support for categories. - [x] Add support for categories.
- [ ] Add an optional `tree` view. - [x] Add an optional `tree` view.
- [x] Add support for both `gpg` and `gpg2`. - [x] Add support for both `gpg` and `gpg2`.
- [x] Man page. - [x] Man page.
- [x] Setup automatic linting. - [x] Setup automatic linting.

32
pash
View File

@ -37,15 +37,24 @@ pw_show() {
} }
pw_list() { pw_list() {
shopt -s globstar shopt -s globstar nullglob
pw_files=(**/*.gpg)
[[ ! -f ${pw_files[0]} ]] && { for pwrd in **; do
printf '%s\n' "No stored passwords." [[ -d $pwrd ]] &&
exit dir=/
}
printf '%s\n' "${pw_files[@]//.gpg}" nest=${pwrd//[^\/]}
pwrd=${pwrd//[^[:print:]]/^[}
pwrd=${pwrd//.gpg}
if [[ -z $tree ]]; then
printf '%s\n' "$pwrd"
else
printf '%s\n' "${nest//\//│ }├─ ${pwrd##*/}${dir}"
dir=
fi
done
} }
pw_gen() { pw_gen() {
@ -103,6 +112,7 @@ usage: pash [add|del|show|list] [name] [-n,-q,-c] [-l length]
-l length Length of generated passwords. -l length Length of generated passwords.
-c Copy password to clipboard. -c Copy password to clipboard.
-q Don't print password to stdout. -q Don't print password to stdout.
-t Print list output as a tree.
-h Print this message. -h Print this message.
-v Show version. -v Show version.
" "
@ -110,13 +120,17 @@ exit 1
} }
get_args() { get_args() {
shift 2 [[ $1 != l* ]] &&
shift 1
while getopts ":ncvql:" opt; do case $opt in shift 1
while getopts ":ncvqtl:" opt; do case $opt in
n) plain=1 ;; n) plain=1 ;;
l) length=${OPTARG//[^0-9]} ;; l) length=${OPTARG//[^0-9]} ;;
c) clipboard=1 ;; c) clipboard=1 ;;
q) quiet=1 ;; q) quiet=1 ;;
t) tree=1 ;;
v) printf '%s\n' "pash 0.01"; exit ;; v) printf '%s\n' "pash 0.01"; exit ;;
?) usage ;; ?) usage ;;
esac; done esac; done

4
pash.1
View File

@ -55,6 +55,10 @@ Copy password to clipboard.
Don't print password to stdout. Don't print password to stdout.
.TP .TP
.BR \-t
Print list output as a tree.
.TP
.BR \-h .BR \-h
Show usage and exit. Show usage and exit.
.TP .TP