From e1e403e1bda92febb5df2c57096f9a2168ec5e60 Mon Sep 17 00:00:00 2001 From: samedamci Date: Sun, 29 Mar 2020 17:04:41 +0200 Subject: [PATCH] Fix bug with `--help` flag When you started rofi-keepassxc with `--help` flag rofi-keepassxc has asked you for password. --- rofi-keepassxc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/rofi-keepassxc b/rofi-keepassxc index 0252bde..180d143 100755 --- a/rofi-keepassxc +++ b/rofi-keepassxc @@ -1,11 +1,5 @@ #!/usr/bin/env zsh -CACHE=$HOME/.cache/rofi-keepassxc/ -mkdir -p $CACHE - -DBPASS=$(rofi -dmenu -i -p "Enter your database password" -l 0 -password -width 500) -[ ! "$DBPASS" ] && exit - clip_username() { echo $DBPASS | keepassxc-cli show $DB $ENTRY | grep 'UserName:' | cut -b 11- | xclip -selection clipboard } @@ -159,16 +153,23 @@ choose_action() { case "$1" in -h || --help) echo " - usage: rofi-keepassxc [-h] [-d] + usage: rofi-keepassxc [-h] [-d] - arguments: - -h, --help show this help message and exit - -d, --database specify keepass database file path + arguments: + -h, --help show this help message and exit + -d, --database [file] specify keepass database file path " exit;; -d || --database) DB="$2" ;; + *) echo "[E] Invalid argument."; exit ;; esac +CACHE=$HOME/.cache/rofi-keepassxc/ +mkdir -p $CACHE + +DBPASS=$(rofi -dmenu -i -p "Enter your database password" -l 0 -password -width 500) +[ ! "$DBPASS" ] && exit + ERROR_PASS='Error while reading the database' CHECK_PASS=$(echo $DBPASS | keepassxc-cli open $DB &> $CACHE/tmp && grep -oh $ERROR_PASS $CACHE/tmp) ERROR_DB='Failed to open database file'