From 484188e3d9d185dd39bd7fd99473cd14e6ac5362 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 25 Feb 2019 21:46:57 +0200 Subject: [PATCH] Added tree view (-t) --- README.md | 3 ++- pash | 32 +++++++++++++++++++++++--------- pash.1 | 4 ++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b7e1470..b2756d5 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ OPTIONS −l Length of generated passwords. −c Copy password to clipboard. −q Don't print password to stdout. +-t Print list output as a tree. −h Show usage 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 categories. -- [ ] Add an optional `tree` view. +- [x] Add an optional `tree` view. - [x] Add support for both `gpg` and `gpg2`. - [x] Man page. - [x] Setup automatic linting. diff --git a/pash b/pash index b3ea9a3..5a66b40 100755 --- a/pash +++ b/pash @@ -37,15 +37,24 @@ pw_show() { } pw_list() { - shopt -s globstar - pw_files=(**/*.gpg) + shopt -s globstar nullglob - [[ ! -f ${pw_files[0]} ]] && { - printf '%s\n' "No stored passwords." - exit - } + for pwrd in **; do + [[ -d $pwrd ]] && + 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() { @@ -103,6 +112,7 @@ usage: pash [add|del|show|list] [name] [-n,-q,-c] [-l length] -l length Length of generated passwords. -c Copy password to clipboard. -q Don't print password to stdout. +-t Print list output as a tree. -h Print this message. -v Show version. " @@ -110,13 +120,17 @@ exit 1 } 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 ;; l) length=${OPTARG//[^0-9]} ;; c) clipboard=1 ;; q) quiet=1 ;; + t) tree=1 ;; v) printf '%s\n' "pash 0.01"; exit ;; ?) usage ;; esac; done diff --git a/pash.1 b/pash.1 index 0ba6157..ed40f4d 100644 --- a/pash.1 +++ b/pash.1 @@ -55,6 +55,10 @@ Copy password to clipboard. Don't print password to stdout. .TP +.BR \-t +Print list output as a tree. +.TP + .BR \-h Show usage and exit. .TP