From 3556eb2403cb89a9c164e4eabe323507a1b9ac2b Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 27 Sep 2022 23:34:21 +0800 Subject: Improve script for password --- tools/desktop/password-store.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/desktop/password-store.sh b/tools/desktop/password-store.sh index e83529b..4d3759e 100755 --- a/tools/desktop/password-store.sh +++ b/tools/desktop/password-store.sh @@ -1,19 +1,32 @@ #! /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 -font 'Hack 22' | { +rofi -dmenu "${ROFI_ARGS[@]}" | { + # Get arguments for command 'pass' read ARG1 ARG2 - if [[ $ARG1 =~ gen ]]; then + + if [[ -z $ARG1 ]]; then + exit 1 + elif [[ $ARG1 =~ gen ]]; then # Generate a new password by ARG2 - alacritty --hold -e pass generate $ARG2 + alacritty --hold -e pass --clip generate $ARG2 else pass $ARG1 | { - read PASSWORD + # If command fails, just fail directly + read PASSWORD; [[ -z $PASSWORD ]] && exit 1 + + # Simply copy password into system clipboard echo $PASSWORD | xsel -ib - rofi -e "Password Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" \ - -font 'Hack 22' + # Show success message, and display extra contents + rofi -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" \ + "${ROFI_ARGS[@]}" } fi } -- cgit v1.2.3-70-g09d2