From abb2633143620d108bafd845c932125782272408 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 22 May 2019 21:52:11 +0300 Subject: [PATCH] general: clean up. --- .travis.yml | 0 LICENSE.md | 0 Makefile | 0 README.md | 0 pash | 87 +++++++++++++++++------------------------------------ pash.1 | 65 --------------------------------------- 6 files changed, 27 insertions(+), 125 deletions(-) mode change 100644 => 100755 .travis.yml mode change 100644 => 100755 LICENSE.md mode change 100644 => 100755 Makefile mode change 100644 => 100755 README.md delete mode 100644 pash.1 diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/pash b/pash index 15d1ea8..72af14e 100755 --- a/pash +++ b/pash @@ -7,14 +7,11 @@ pw_add() { case $REPLY in [yY]) - length=${length:=50} - password=$("${gpg[0]}" --armor --gen-random 0 "$length") - password=${password:0:length} + password=$("${gpg[0]}" --armor --gen-random 0 50) + password=${password:0:50} ;; - *) - read -rsp "Enter password: " password - ;; + *) read -rsp "Enter password: " password ;; esac [[ $password ]] || @@ -32,31 +29,34 @@ pw_del() { pw_show() { read -r password < <("${gpg[0]}" -dq "$1.gpg") + + [[ ${FUNCNAME[1]} != pw_copy ]] && + printf '%s\n' "$password" +} + +pw_copy() { + pw_show "$1" + + if [[ $TMUX ]]; then + tmux load-buffer "$password" + else + hash xclip && xclip -selection clipboard <<< "$password" + fi } pw_list() { shopt -s globstar nullglob - if [[ $tree ]]; then - tree - else - printf -- '%s\e[4D\e[K\n' **/*.gpg - fi -} - -tree() { printf '%s\n' "pash" for pwrd in **; do - [[ -d $pwrd ]] && - dir=/ + [[ -d $pwrd ]] && dir=/ || dir= nest=${pwrd//[^\/]} pwrd=${pwrd//[^[:print:]]/^[} pwrd=${pwrd//.gpg} printf '%s\n' "${nest//\//│ }├─ ${pwrd##*/}${dir}" - dir= done printf '└%s\b┘\n' "${nest//\//──┴}" @@ -72,48 +72,20 @@ die() { exit 1 } -copy() { - [[ $TMUX ]] && { - tmux load-buffer "$password" - return - } - - hash xclip 2>/dev/null && - xclip -selection clipboard &>/dev/null <<< "$password" -} - usage() { printf '%s' "\ -pash - simple password manager. -usage: pash [add|del|show|list] [name] [flags] - --c Copy password to clipboard. --l length Length of generated passwords. --q Don't print password to stdout. --t Print list output as a tree. --h Print this message. --v Show version. +pash 0.1.0 - simple password manager. +=> [a]dd [name] - Create a new password entry. +=> [c]opy [name] - Copy entry to the clipboard. +=> [d]el [name] - Delete a password entry. +=> [l]ist - List all entries. +=> [s]how [name] - Show password for an entry. " exit 1 } -get_args() { - [[ $1 != l* ]] && - shift 1 - - shift 1 - - while getopts ":ncvqtl:" opt; do case $opt in - c) clipboard=1 ;; - l) length=${OPTARG//[^0-9]} ;; - q) quiet=1 ;; - t) tree=1 ;; - v) printf '%s\n' "pash 0.01"; exit ;; - ?) usage ;; - esac; done -} - main() { - get_args "$@" + [[ $1 == -? || -z $1 ]] && + usage mapfile -t gpg < <(type -p gpg gpg2) && [[ ! -x ${gpg[0]} ]] && die "GPG not found." @@ -146,17 +118,12 @@ main() { case $1 in a*) pw_add "$2" ;; + c*) pw_copy "$2" ;; d*) pw_del "$2" ;; s*) pw_show "$2" ;; l*) pw_list ;; - *) usage ;; + *) usage esac - - [[ $clipboard && $password ]] && - copy - - [[ -z $quiet && $password ]] && - printf '%s\n' "$password" } main "$@" diff --git a/pash.1 b/pash.1 deleted file mode 100644 index 682db0b..0000000 --- a/pash.1 +++ /dev/null @@ -1,65 +0,0 @@ -.TH PASH 1 -.SH NAME -pash \- simple pasword manager - - -.SH SYNOPSIS -.B pash -[\fBadd|del|show|list\fR] -[name] -[\fB-cqthv\fR] -[\fB-l\fR length] - - -.SH DESCRIPTION -.B pash -simple pasword manager - - -.SH COMMANDS -.TP -.BR [a]dd -[name]: -Create a new entry in the password store. -.TP - -.BR [d]el -[name]: -Delete an entry from the password store. -.TP - -.BR [s]how -[name]: -Show password from an entry in the password store. -.TP - -.BR [l]ist: -List all entries from the password store. -.TP - -.SH OPTIONS -.TP - -.BR \-c -Copy password to clipboard. -.TP - -.BR \-l -Length of generated passwords. -.TP - -.BR \-q -Don't print password to stdout. -.TP - -.BR \-t -Print list output as a tree. -.TP - -.BR \-h -Show usage and exit. -.TP - -.BR \-v -Show version and exit. -.TP