From 6fae25b305d714b3ab7608fa003f1af9bf024545 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 14 Feb 2023 13:33:23 +0800 Subject: Rename tools into bin --- bin/desktop/password-store.sh | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 bin/desktop/password-store.sh (limited to 'bin/desktop/password-store.sh') diff --git a/bin/desktop/password-store.sh b/bin/desktop/password-store.sh new file mode 100755 index 0000000..1de3148 --- /dev/null +++ b/bin/desktop/password-store.sh @@ -0,0 +1,51 @@ +#! /bin/bash + +# Use rofi to quickly access password by command 'pass' +# xsel needed !! + +ROFI_ARGS=( "-font" "Hack 22" ) + +find ~/.password-store -name '*gpg' -printf %P\\n | \ +sed 's/.gpg$//' | \ +rofi -dmenu "${ROFI_ARGS[@]}" | { + # Get arguments for command 'pass' + read ARG1 ARG2 + + if [[ -z $ARG1 ]]; then + exit 1 + elif [[ $ARG1 == edit ]]; then + # Edit an existing password + alacritty --hold -e pass edit $ARG2 && \ + rofi -e Password Edited: $ARG2 + else + # If pass fails, then it means password doesn't exists + set pipefail + + pass $ARG1 | { + # If command fails, just fail directly + read PASSWORD; [[ -z $PASSWORD ]] && exit 1 + + # Simply copy password into system clipboard + echo $PASSWORD | xsel -ib + + # Show success message, and display extra contents + rofi "${ROFI_ARGS[@]}" \ + -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" + } || { + # Make sure user want to create a new password + return_code=$(alacritty -e sh -c ' + dialog --yesno "Password does not exist, Generate a new one?" 8 30; + echo "$?" + ') + [[ $return_code == 1 ]] && exit 1 + + # Generate a new password by ARG1 + alacritty -e pass generate $ARG1 --clip && \ + + # Show success message + rofi "${ROFI_ARGS[@]}" -e "Password Created and Copied: $ARG1" + } + + # TODO: if return code is 2, it means gpg password is not cached + fi +} -- cgit v1.2.3-70-g09d2