From f47670763cd79b2ca34b61930e78b97d6631f88f Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 7 May 2023 10:27:38 +0800 Subject: Improve password script --- X11/rofi/pass.edit | 12 ++++++------ X11/rofi/pass.get | 11 +++++++---- X11/rofi/pass.replace | 43 +++++++++++++++++++++++++++++++++++++++++++ X11/rofi/rofi-pass | 4 +++- 4 files changed, 59 insertions(+), 11 deletions(-) create mode 100755 X11/rofi/pass.replace (limited to 'X11') diff --git a/X11/rofi/pass.edit b/X11/rofi/pass.edit index 66fba6b..2c0eeea 100755 --- a/X11/rofi/pass.edit +++ b/X11/rofi/pass.edit @@ -4,17 +4,17 @@ 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" + # Specify rofi prompt as 'Edit' + echo -e "\0prompt\x1fEdit" - echo "$ENTRIES" - exit 0 + echo "$ENTRIES" + exit 0 fi # If password doesn't exist, just quit <<<"$ENTRIES" grep -q $1 || exit 0 # Use detected terminal emulator to edit password -coproc ( - alacritty -e pass edit $1 && $(dirname $0)/pass.get $1 +coproc ( + $terminal -e pass edit $1 && $(dirname $0)/pass.get $1 ) diff --git a/X11/rofi/pass.get b/X11/rofi/pass.get index 425cd62..20ef852 100755 --- a/X11/rofi/pass.get +++ b/X11/rofi/pass.get @@ -15,8 +15,9 @@ if [ -n "${ROFI_DATA}" ]; then # Generate password in a new process # And Use current script to copy the values info X11 selections - coproc ( + coproc ( pass generate ${PASSWORD} ${extra_arguments} + $terminal -e pass edit ${PASSWORD} $0 ${PASSWORD} ) @@ -48,15 +49,17 @@ if [ -n "$RESULT" ]; then coproc ( rofi -e "Copied: $1$EXTRA" ) elif [ -f "$HOME/.password-store/$1.gpg" ]; then - coproc ( + # Password exist but command fails + # Must be something wrong with GPG decryption + coproc ( rofi -e "GPG passphase is not chached" \ -theme-str '#window { font: "hacker 40"; }' ) -else +else # Password doesn't exist yet # Go to next rofi execution echo -e "\0prompt\x1f$1" - echo -e "\0message\x1fThis password doesn't exist, generate with custom arguments?" + echo -e "\0message\x1f\"NUMBER\" for length, \"-n\" to exclude spcecial chars" echo -e "\0data\x1f$1" echo ${GENERATION_HINT} fi diff --git a/X11/rofi/pass.replace b/X11/rofi/pass.replace new file mode 100755 index 0000000..fa3d442 --- /dev/null +++ b/X11/rofi/pass.replace @@ -0,0 +1,43 @@ +#! /bin/bash + +ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')" +GENERATION_HINT="Generate with default config" + +# Generate a new password if ROFI_DATA is given by last execution +if [ -n "${ROFI_DATA}" ]; then + PASSWORD="${ROFI_DATA}" + export ROFI_DATA= + + # If custom arguments for password generation is given + # Set environment variable + if [ ${ROFI_RETV} -eq 2 ]; then + extra_arguments="${1}" + fi + + # Generate password in a new process + # And Use current script to copy the values info X11 selections + coproc ( + pass generate -i ${PASSWORD} ${extra_arguments} + $(dirname $0)/pass.get ${PASSWORD} + ) + + exit 0 +fi + +# Give rofi available passwords and exit +if [ $# -eq 0 ]; then + # Specify rofi prompt as 'Replace' + echo -e "\0prompt\x1fReplace" + + echo "$ENTRIES" + exit 0 +fi + +# If password doesn't exist, just quit +<<<"$ENTRIES" grep -q $1 || exit 0 + +# Show message for password options +echo -e "\0prompt\x1f$1" +echo -e "\0message\x1f\"NUMBER\" for length, \"-n\" to exclude spcecial chars" +echo -e "\0data\x1f$1" +echo ${GENERATION_HINT} diff --git a/X11/rofi/rofi-pass b/X11/rofi/rofi-pass index b6a1e01..498fa62 100755 --- a/X11/rofi/rofi-pass +++ b/X11/rofi/rofi-pass @@ -1,5 +1,7 @@ #! /bin/bash +export terminal=${terminal:-alacritty} + cd $(dirname $0) -rofi -show get -modes get:./pass.get,edit:./pass.edit,rm:./pass.rm +rofi -show get -modes get:./pass.get,edit:./pass.edit,replace:./pass.replace,rm:./pass.rm -- cgit v1.2.3-70-g09d2