aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/desktop/password-store.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/desktop/password-store.sh')
-rwxr-xr-xbin/desktop/password-store.sh51
1 files changed, 51 insertions, 0 deletions
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 @@
1#! /bin/bash
2
3# Use rofi to quickly access password by command 'pass'
4# xsel needed !!
5
6ROFI_ARGS=( "-font" "Hack 22" )
7
8find ~/.password-store -name '*gpg' -printf %P\\n | \
9sed 's/.gpg$//' | \
10rofi -dmenu "${ROFI_ARGS[@]}" | {
11 # Get arguments for command 'pass'
12 read ARG1 ARG2
13
14 if [[ -z $ARG1 ]]; then
15 exit 1
16 elif [[ $ARG1 == edit ]]; then
17 # Edit an existing password
18 alacritty --hold -e pass edit $ARG2 && \
19 rofi -e Password Edited: $ARG2
20 else
21 # If pass fails, then it means password doesn't exists
22 set pipefail
23
24 pass $ARG1 | {
25 # If command fails, just fail directly
26 read PASSWORD; [[ -z $PASSWORD ]] && exit 1
27
28 # Simply copy password into system clipboard
29 echo $PASSWORD | xsel -ib
30
31 # Show success message, and display extra contents
32 rofi "${ROFI_ARGS[@]}" \
33 -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')"
34 } || {
35 # Make sure user want to create a new password
36 return_code=$(alacritty -e sh -c '
37 dialog --yesno "Password does not exist, Generate a new one?" 8 30;
38 echo "$?"
39 ')
40 [[ $return_code == 1 ]] && exit 1
41
42 # Generate a new password by ARG1
43 alacritty -e pass generate $ARG1 --clip && \
44
45 # Show success message
46 rofi "${ROFI_ARGS[@]}" -e "Password Created and Copied: $ARG1"
47 }
48
49 # TODO: if return code is 2, it means gpg password is not cached
50 fi
51}