diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2022-10-03 17:17:14 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2022-10-03 17:17:14 +0800 |
| commit | 39ca5ff64c88d21ec4423ffa1f591f398814d698 (patch) | |
| tree | e0d5a16e83774e10e8fa8f81cddf3151516ab767 /X11/rofi | |
| parent | 596f8bf16ef20d04fb669f9db0cb5a69a3a4148e (diff) | |
Change paths
Diffstat (limited to 'X11/rofi')
| -rwxr-xr-x | X11/rofi/pass.edit | 22 | ||||
| -rwxr-xr-x | X11/rofi/pass.get | 54 | ||||
| -rwxr-xr-x | X11/rofi/pass.rm | 21 | ||||
| -rwxr-xr-x | X11/rofi/rofi-pass | 7 |
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 | |||
| 3 | ROFI_ARGS=( '-font' 'Hack 22' ) | ||
| 4 | ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')" | ||
| 5 | |||
| 6 | # Give rofi available passwords and exit | ||
| 7 | if [ $# -eq 0 ]; then | ||
| 8 | # Specify rofi prompt as 'Edit' | ||
| 9 | echo -e "\0prompt\x1fEdit" | ||
| 10 | |||
| 11 | echo "$ENTRIES" | ||
| 12 | exit 0 | ||
| 13 | fi | ||
| 14 | |||
| 15 | # If password doesn't exist, just quit | ||
| 16 | <<<"$ENTRIES" grep -q $1 || exit 0 | ||
| 17 | |||
| 18 | # Use alacritty to edit password | ||
| 19 | coproc ( | ||
| 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 | |||
| 3 | ROFI_ARGS=( '-font' 'Hack 22' ) | ||
| 4 | OPTIONS_NEW=( 'NO' 'YES' 'YES, and edit it' ) | ||
| 5 | |||
| 6 | # Generate a new password | ||
| 7 | if [ -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 | ||
| 23 | fi | ||
| 24 | |||
| 25 | # Give rofi available passwords and exit | ||
| 26 | if [ $# -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 | ||
| 34 | fi | ||
| 35 | |||
| 36 | # Test password exists or not | ||
| 37 | RESULT="$(pass $1)" | ||
| 38 | if [ -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 | ||
| 47 | else | ||
| 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 | ||
| 54 | fi | ||
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 | |||
| 3 | ROFI_ARGS=( '-font' 'Hack 22' ) | ||
| 4 | ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')" | ||
| 5 | |||
| 6 | # Give rofi available passwords and exit | ||
| 7 | if [ $# -eq 0 ]; then | ||
| 8 | # Specify rofi prompt as 'Remove' | ||
| 9 | echo -e "\0prompt\x1fRemove" | ||
| 10 | |||
| 11 | echo "$ENTRIES" | ||
| 12 | exit 0 | ||
| 13 | fi | ||
| 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 | |||
| 3 | cd $(dirname $0) | ||
| 4 | |||
| 5 | rofi -show get\ | ||
| 6 | -modes get:./pass.get,edit:./pass.edit,rm:./pass.rm \ | ||
| 7 | -font 'Hack 22' | ||