Add checkf helper function Checks if file exists, dies otherwise Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Sun, 17 Nov 2019 15:10:27 +0530
1 files changed,
10 insertions(+),
0 deletions(-)
jump to
M
pw
→
pw
@@ -34,6 +34,7 @@ fi
} del() { + checkf "$PW_DIR/$1.gpg" read -rn 1 -p "pw: are you sure you want to delete $1? [y/n]: " printf "\n" [[ "$REPLY" == [yY] ]] && {@@ -43,10 +44,14 @@ }
} show() { + checkf "$PW_DIR/$1.gpg" gpg2 --decrypt --quiet --use-agent "$PW_DIR/$1.gpg" } +# TODO: rework having to checkf twice + copy() { + checkf "$PW_DIR/$1.gpg" show "$1" | xclip -selection clipboard echo "pw: copied $1 to clipboard" }@@ -72,6 +77,11 @@ "
echo "$usage" exit 1 +} + +checkf() { + [[ ! -f "$1" ]] && + die "$1 does not exist" } die() {