diff options
| -rwxr-xr-x | tools/desktop/password-store.sh | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/tools/desktop/password-store.sh b/tools/desktop/password-store.sh index 6918e3f..21dec79 100755 --- a/tools/desktop/password-store.sh +++ b/tools/desktop/password-store.sh | |||
| @@ -10,13 +10,19 @@ sed 's/.gpg$//' | \ | |||
| 10 | rofi -dmenu "${ROFI_ARGS[@]}" | { | 10 | rofi -dmenu "${ROFI_ARGS[@]}" | { |
| 11 | # Get arguments for command 'pass' | 11 | # Get arguments for command 'pass' |
| 12 | read ARG1 ARG2 | 12 | read ARG1 ARG2 |
| 13 | echo ARG1: $ARG1 | ||
| 14 | echo ARG2: $ARG2 | ||
| 13 | 15 | ||
| 14 | if [[ -z $ARG1 ]]; then | 16 | if [[ -z $ARG1 ]]; then |
| 15 | exit 1 | 17 | exit 1 |
| 16 | elif [[ $ARG1 =~ gen ]]; then | 18 | elif [[ $ARG1 == edit ]]; then |
| 17 | # Generate a new password by ARG2 | 19 | # Edit an existing password |
| 18 | alacritty --hold -e pass --clip generate $ARG2 | 20 | alacritty --hold -e pass edit $ARG2 && \ |
| 21 | rofi -e Password Edited: $ARG2 | ||
| 19 | else | 22 | else |
| 23 | # If pass fails, then it means password doesn't exists | ||
| 24 | set pipefail | ||
| 25 | |||
| 20 | pass $ARG1 | { | 26 | pass $ARG1 | { |
| 21 | # If command fails, just fail directly | 27 | # If command fails, just fail directly |
| 22 | read PASSWORD; [[ -z $PASSWORD ]] && exit 1 | 28 | read PASSWORD; [[ -z $PASSWORD ]] && exit 1 |
| @@ -25,8 +31,20 @@ rofi -dmenu "${ROFI_ARGS[@]}" | { | |||
| 25 | echo $PASSWORD | xsel -ib | 31 | echo $PASSWORD | xsel -ib |
| 26 | 32 | ||
| 27 | # Show success message, and display extra contents | 33 | # Show success message, and display extra contents |
| 28 | rofi -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" \ | 34 | rofi "${ROFI_ARGS[@]}" \ |
| 29 | "${ROFI_ARGS[@]}" | 35 | -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" |
| 30 | } | 36 | } || { |
| 37 | # Make sure user want to create a new password | ||
| 38 | alacritty -e dialog --yesno \ | ||
| 39 | "Password doesn't exist, Generate a new one?" 7 30 || exit 1 | ||
| 40 | |||
| 41 | # Generate a new password by ARG1 | ||
| 42 | alacritty -e pass generate $ARG1 --clip && \ | ||
| 43 | |||
| 44 | # Show success message | ||
| 45 | rofi "${ROFI_ARGS[@]}" -e "Password Created and Copied: $ARG1" | ||
| 46 | } | ||
| 47 | |||
| 48 | # TODO: if return code is 2, it means gpg password is not cached | ||
| 31 | fi | 49 | fi |
| 32 | } | 50 | } |