aboutsummaryrefslogtreecommitdiff
path: root/pw
diff options
context:
space:
mode:
authorAnirudh Oppiliappan <x@icyphox.sh>2019-11-17 15:10:27 +0530
committerAnirudh Oppiliappan <x@icyphox.sh>2019-11-17 15:10:27 +0530
commit0a5b7244b36afce7b95e77d1ce8acda600513a9a (patch)
treea4ad6dee6982cf7b4f124868baeccded452575da /pw
parentec848fac2e389b04c481c53a994ac104ccb4aa03 (diff)
downloadpw-0a5b7244b36afce7b95e77d1ce8acda600513a9a.tar.gz
Add checkf helper function
Checks if file exists, dies otherwise Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Diffstat (limited to 'pw')
-rwxr-xr-xpw10
1 files changed, 10 insertions, 0 deletions
diff --git a/pw b/pw
index 3357dc0..2e5f36a 100755
--- a/pw
+++ b/pw
@@ -34,6 +34,7 @@ add() {
34} 34}
35 35
36del() { 36del() {
37 checkf "$PW_DIR/$1.gpg"
37 read -rn 1 -p "pw: are you sure you want to delete $1? [y/n]: " 38 read -rn 1 -p "pw: are you sure you want to delete $1? [y/n]: "
38 printf "\n" 39 printf "\n"
39 [[ "$REPLY" == [yY] ]] && { 40 [[ "$REPLY" == [yY] ]] && {
@@ -43,10 +44,14 @@ del() {
43} 44}
44 45
45show() { 46show() {
47 checkf "$PW_DIR/$1.gpg"
46 gpg2 --decrypt --quiet --use-agent "$PW_DIR/$1.gpg" 48 gpg2 --decrypt --quiet --use-agent "$PW_DIR/$1.gpg"
47} 49}
48 50
51# TODO: rework having to checkf twice
52
49copy() { 53copy() {
54 checkf "$PW_DIR/$1.gpg"
50 show "$1" | xclip -selection clipboard 55 show "$1" | xclip -selection clipboard
51 echo "pw: copied $1 to clipboard" 56 echo "pw: copied $1 to clipboard"
52} 57}
@@ -74,6 +79,11 @@ Requires PW_KEY to be set. Optionally, set PW_DIR for custom directory location.
74 exit 1 79 exit 1
75} 80}
76 81
82checkf() {
83 [[ ! -f "$1" ]] &&
84 die "$1 does not exist"
85}
86
77die() { 87die() {
78 printf "error: %s\n" "$1" 88 printf "error: %s\n" "$1"
79 exit 1 89 exit 1