aboutsummaryrefslogtreecommitdiffhomepage
path: root/X11/rofi
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2022-10-03 17:17:14 +0800
committerHsieh Chin Fan <pham@topo.tw>2022-10-03 17:17:14 +0800
commit39ca5ff64c88d21ec4423ffa1f591f398814d698 (patch)
treee0d5a16e83774e10e8fa8f81cddf3151516ab767 /X11/rofi
parent596f8bf16ef20d04fb669f9db0cb5a69a3a4148e (diff)
Change paths
Diffstat (limited to 'X11/rofi')
-rwxr-xr-xX11/rofi/pass.edit22
-rwxr-xr-xX11/rofi/pass.get54
-rwxr-xr-xX11/rofi/pass.rm21
-rwxr-xr-xX11/rofi/rofi-pass7
4 files changed, 104 insertions, 0 deletions
diff --git a/X11/rofi/pass.edit b/X11/rofi/pass.edit
new file mode 100755
index 0000000..fb6ade9
--- /dev/null
+++ b/X11/rofi/pass.edit
@@ -0,0 +1,22 @@
1#! /bin/sh
2
3ROFI_ARGS=( '-font' 'Hack 22' )
4ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')"
5
6# Give rofi available passwords and exit
7if [ $# -eq 0 ]; then
8 # Specify rofi prompt as 'Edit'
9 echo -e "\0prompt\x1fEdit"
10
11 echo "$ENTRIES"
12 exit 0
13fi
14
15# If password doesn't exist, just quit
16<<<"$ENTRIES" grep -q $1 || exit 0
17
18# Use alacritty to edit password
19coproc (
20 alacritty -e pass edit $1 && pass $1 --clip
21 rofi "${ROFI_ARGS[@]}" -e "Copied: $1"
22)
diff --git a/X11/rofi/pass.get b/X11/rofi/pass.get
new file mode 100755
index 0000000..df70652
--- /dev/null
+++ b/X11/rofi/pass.get
@@ -0,0 +1,54 @@
1#! /bin/sh
2
3ROFI_ARGS=( '-font' 'Hack 22' )
4OPTIONS_NEW=( 'NO' 'YES' 'YES, and edit it' )
5
6# Generate a new password
7if [ -n "${ROFI_DATA}" ]; then
8 [ "$1" == "${OPTIONS_NEW[1]}" ] && \
9 coproc (
10 export POST=false
11 pass generate ${ROFI_DATA} --clip
12 rofi "${ROFI_ARGS[@]}" -e "Generate and Copied: ${ROFI_DATA}"
13 )
14
15 [ "$1" == "${OPTIONS_NEW[2]}" ] && \
16 coproc (
17 export POST=false
18 pass generate ${ROFI_DATA} --clip
19 alacritty -e pass edit ${ROFI_DATA}; \
20 )
21
22 exit 0
23fi
24
25# Give rofi available passwords and exit
26if [ $# -eq 0 ]; then
27 # Specify rofi prompt as 'Get'
28 echo -e "\0prompt\x1fGet"
29
30 find ~/.password-store -name '*gpg' -printf %P\\n | \
31 sed 's/.gpg$//'
32
33 exit 0
34fi
35
36# Test password exists or not
37RESULT="$(pass $1)"
38if [ -n "$RESULT" ]; then
39 # Copy the given password into clipboard
40 echo "$RESULT" | head -1 | xsel -ib
41
42 # And show extra message
43 EXTRA="$(echo; echo; echo "$RESULT" | sed '1d; 1{/^$/d}')"
44 coproc ( rofi "${ROFI_ARGS[@]}" -e "Copied: $1$EXTRA" )
45# Password doesn't exist yet
46# Go to next rofi execution
47else
48 echo -e "\0prompt\x1f$1 doesn't exist, generate it?"
49 echo -e "\0data\x1f$1"
50
51 for i in "${OPTIONS_NEW[@]}"; do
52 echo $i
53 done
54fi
diff --git a/X11/rofi/pass.rm b/X11/rofi/pass.rm
new file mode 100755
index 0000000..44bdc33
--- /dev/null
+++ b/X11/rofi/pass.rm
@@ -0,0 +1,21 @@
1#! /bin/sh
2
3ROFI_ARGS=( '-font' 'Hack 22' )
4ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')"
5
6# Give rofi available passwords and exit
7if [ $# -eq 0 ]; then
8 # Specify rofi prompt as 'Remove'
9 echo -e "\0prompt\x1fRemove"
10
11 echo "$ENTRIES"
12 exit 0
13fi
14
15# If password doesn't exist, just quit
16<<<"$ENTRIES" grep -q $1 && \
17 coproc (
18 pass rm $1 &>/dev/null && \
19 rofi "${ROFI_ARGS[@]}" -e "Removed: $1" || \
20 rofi "${ROFI_ARGS[@]}" -e "Fail to remove $1"
21 )
diff --git a/X11/rofi/rofi-pass b/X11/rofi/rofi-pass
new file mode 100755
index 0000000..1730b93
--- /dev/null
+++ b/X11/rofi/rofi-pass
@@ -0,0 +1,7 @@
1#! /bin/bash
2
3cd $(dirname $0)
4
5rofi -show get\
6 -modes get:./pass.get,edit:./pass.edit,rm:./pass.rm \
7 -font 'Hack 22'