From 39ca5ff64c88d21ec4423ffa1f591f398814d698 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 3 Oct 2022 17:17:14 +0800 Subject: Change paths --- X11/rofi/pass.edit | 22 ++++++++++++++++++++++ X11/rofi/pass.get | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ X11/rofi/pass.rm | 21 +++++++++++++++++++++ X11/rofi/rofi-pass | 7 +++++++ 4 files changed, 104 insertions(+) create mode 100755 X11/rofi/pass.edit create mode 100755 X11/rofi/pass.get create mode 100755 X11/rofi/pass.rm create mode 100755 X11/rofi/rofi-pass (limited to 'X11/rofi') 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 @@ +#! /bin/sh + +ROFI_ARGS=( '-font' 'Hack 22' ) +ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')" + +# Give rofi available passwords and exit +if [ $# -eq 0 ]; then + # Specify rofi prompt as 'Edit' + echo -e "\0prompt\x1fEdit" + + echo "$ENTRIES" + exit 0 +fi + +# If password doesn't exist, just quit +<<<"$ENTRIES" grep -q $1 || exit 0 + +# Use alacritty to edit password +coproc ( + alacritty -e pass edit $1 && pass $1 --clip + rofi "${ROFI_ARGS[@]}" -e "Copied: $1" +) 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 @@ +#! /bin/sh + +ROFI_ARGS=( '-font' 'Hack 22' ) +OPTIONS_NEW=( 'NO' 'YES' 'YES, and edit it' ) + +# Generate a new password +if [ -n "${ROFI_DATA}" ]; then + [ "$1" == "${OPTIONS_NEW[1]}" ] && \ + coproc ( + export POST=false + pass generate ${ROFI_DATA} --clip + rofi "${ROFI_ARGS[@]}" -e "Generate and Copied: ${ROFI_DATA}" + ) + + [ "$1" == "${OPTIONS_NEW[2]}" ] && \ + coproc ( + export POST=false + pass generate ${ROFI_DATA} --clip + alacritty -e pass edit ${ROFI_DATA}; \ + ) + + exit 0 +fi + +# Give rofi available passwords and exit +if [ $# -eq 0 ]; then + # Specify rofi prompt as 'Get' + echo -e "\0prompt\x1fGet" + + find ~/.password-store -name '*gpg' -printf %P\\n | \ + sed 's/.gpg$//' + + exit 0 +fi + +# Test password exists or not +RESULT="$(pass $1)" +if [ -n "$RESULT" ]; then + # Copy the given password into clipboard + echo "$RESULT" | head -1 | xsel -ib + + # And show extra message + EXTRA="$(echo; echo; echo "$RESULT" | sed '1d; 1{/^$/d}')" + coproc ( rofi "${ROFI_ARGS[@]}" -e "Copied: $1$EXTRA" ) +# Password doesn't exist yet +# Go to next rofi execution +else + echo -e "\0prompt\x1f$1 doesn't exist, generate it?" + echo -e "\0data\x1f$1" + + for i in "${OPTIONS_NEW[@]}"; do + echo $i + done +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 @@ +#! /bin/sh + +ROFI_ARGS=( '-font' 'Hack 22' ) +ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')" + +# Give rofi available passwords and exit +if [ $# -eq 0 ]; then + # Specify rofi prompt as 'Remove' + echo -e "\0prompt\x1fRemove" + + echo "$ENTRIES" + exit 0 +fi + +# If password doesn't exist, just quit +<<<"$ENTRIES" grep -q $1 && \ + coproc ( + pass rm $1 &>/dev/null && \ + rofi "${ROFI_ARGS[@]}" -e "Removed: $1" || \ + rofi "${ROFI_ARGS[@]}" -e "Fail to remove $1" + ) 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 @@ +#! /bin/bash + +cd $(dirname $0) + +rofi -show get\ + -modes get:./pass.get,edit:./pass.edit,rm:./pass.rm \ + -font 'Hack 22' -- cgit v1.2.3-70-g09d2