diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2022-09-27 23:34:21 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2022-09-27 23:45:00 +0800 |
| commit | 3556eb2403cb89a9c164e4eabe323507a1b9ac2b (patch) | |
| tree | 7eec71c6a2fbe06b6c783410d49221583162402c /tools/desktop | |
| parent | dd97e761a8b354e09c27ef604d27a3bbaa27b2e2 (diff) | |
Improve script for password
Diffstat (limited to 'tools/desktop')
| -rwxr-xr-x | tools/desktop/password-store.sh | 25 |
1 files changed, 19 insertions, 6 deletions
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 @@ | |||
| 1 | #! /bin/bash | 1 | #! /bin/bash |
| 2 | 2 | ||
| 3 | # Use rofi to quickly access password by command 'pass' | ||
| 4 | # xsel needed !! | ||
| 5 | |||
| 6 | ROFI_ARGS=( "-font" "Hack 22" ) | ||
| 7 | |||
| 3 | find ~/.password-store -name '*gpg' -printf %P\\n | \ | 8 | find ~/.password-store -name '*gpg' -printf %P\\n | \ |
| 4 | sed 's/.gpg$//' | \ | 9 | sed 's/.gpg$//' | \ |
| 5 | rofi -dmenu -font 'Hack 22' | { | 10 | rofi -dmenu "${ROFI_ARGS[@]}" | { |
| 11 | # Get arguments for command 'pass' | ||
| 6 | read ARG1 ARG2 | 12 | read ARG1 ARG2 |
| 7 | if [[ $ARG1 =~ gen ]]; then | 13 | |
| 14 | if [[ -z $ARG1 ]]; then | ||
| 15 | exit 1 | ||
| 16 | elif [[ $ARG1 =~ gen ]]; then | ||
| 8 | # Generate a new password by ARG2 | 17 | # Generate a new password by ARG2 |
| 9 | alacritty --hold -e pass generate $ARG2 | 18 | alacritty --hold -e pass --clip generate $ARG2 |
| 10 | else | 19 | else |
| 11 | pass $ARG1 | { | 20 | pass $ARG1 | { |
| 12 | read PASSWORD | 21 | # If command fails, just fail directly |
| 22 | read PASSWORD; [[ -z $PASSWORD ]] && exit 1 | ||
| 23 | |||
| 24 | # Simply copy password into system clipboard | ||
| 13 | echo $PASSWORD | xsel -ib | 25 | echo $PASSWORD | xsel -ib |
| 14 | 26 | ||
| 15 | rofi -e "Password Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" \ | 27 | # Show success message, and display extra contents |
| 16 | -font 'Hack 22' | 28 | rofi -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" \ |
| 29 | "${ROFI_ARGS[@]}" | ||
| 17 | } | 30 | } |
| 18 | fi | 31 | fi |
| 19 | } | 32 | } |