diff options
author | Anirudh Oppiliappan <x@icyphox.sh> | 2019-11-17 15:10:27 +0530 |
---|---|---|
committer | Anirudh Oppiliappan <x@icyphox.sh> | 2019-11-17 15:10:27 +0530 |
commit | 0a5b7244b36afce7b95e77d1ce8acda600513a9a (patch) | |
tree | a4ad6dee6982cf7b4f124868baeccded452575da /pw | |
parent | ec848fac2e389b04c481c53a994ac104ccb4aa03 (diff) | |
download | pw-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-x | pw | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -34,6 +34,7 @@ add() { | |||
34 | } | 34 | } |
35 | 35 | ||
36 | del() { | 36 | del() { |
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 | ||
45 | show() { | 46 | show() { |
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 | |||
49 | copy() { | 53 | copy() { |
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 | ||
82 | checkf() { | ||
83 | [[ ! -f "$1" ]] && | ||
84 | die "$1 does not exist" | ||
85 | } | ||
86 | |||
77 | die() { | 87 | die() { |
78 | printf "error: %s\n" "$1" | 88 | printf "error: %s\n" "$1" |
79 | exit 1 | 89 | exit 1 |