diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-05-07 10:27:38 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-05-07 10:27:38 +0800 |
| commit | f47670763cd79b2ca34b61930e78b97d6631f88f (patch) | |
| tree | fc0c7b82cb0a0eb3b36217eeb76bb874bfe9fafd | |
| parent | fe8327560ca95571cf6f2ce4762377a112cd815d (diff) | |
Improve password script
| -rwxr-xr-x | X11/rofi/pass.edit | 12 | ||||
| -rwxr-xr-x | X11/rofi/pass.get | 11 | ||||
| -rwxr-xr-x | X11/rofi/pass.replace | 43 | ||||
| -rwxr-xr-x | X11/rofi/rofi-pass | 4 |
4 files changed, 59 insertions, 11 deletions
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$//')" | |||
| 4 | 4 | ||
| 5 | # Give rofi available passwords and exit | 5 | # Give rofi available passwords and exit |
| 6 | if [ $# -eq 0 ]; then | 6 | if [ $# -eq 0 ]; then |
| 7 | # Specify rofi prompt as 'Edit' | 7 | # Specify rofi prompt as 'Edit' |
| 8 | echo -e "\0prompt\x1fEdit" | 8 | echo -e "\0prompt\x1fEdit" |
| 9 | 9 | ||
| 10 | echo "$ENTRIES" | 10 | echo "$ENTRIES" |
| 11 | exit 0 | 11 | exit 0 |
| 12 | fi | 12 | fi |
| 13 | 13 | ||
| 14 | # If password doesn't exist, just quit | 14 | # If password doesn't exist, just quit |
| 15 | <<<"$ENTRIES" grep -q $1 || exit 0 | 15 | <<<"$ENTRIES" grep -q $1 || exit 0 |
| 16 | 16 | ||
| 17 | # Use detected terminal emulator to edit password | 17 | # Use detected terminal emulator to edit password |
| 18 | coproc ( | 18 | coproc ( |
| 19 | alacritty -e pass edit $1 && $(dirname $0)/pass.get $1 | 19 | $terminal -e pass edit $1 && $(dirname $0)/pass.get $1 |
| 20 | ) | 20 | ) |
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 | |||
| 15 | 15 | ||
| 16 | # Generate password in a new process | 16 | # Generate password in a new process |
| 17 | # And Use current script to copy the values info X11 selections | 17 | # And Use current script to copy the values info X11 selections |
| 18 | coproc ( | 18 | coproc ( |
| 19 | pass generate ${PASSWORD} ${extra_arguments} | 19 | pass generate ${PASSWORD} ${extra_arguments} |
| 20 | $terminal -e pass edit ${PASSWORD} | ||
| 20 | $0 ${PASSWORD} | 21 | $0 ${PASSWORD} |
| 21 | ) | 22 | ) |
| 22 | 23 | ||
| @@ -48,15 +49,17 @@ if [ -n "$RESULT" ]; then | |||
| 48 | coproc ( rofi -e "Copied: $1$EXTRA" ) | 49 | coproc ( rofi -e "Copied: $1$EXTRA" ) |
| 49 | 50 | ||
| 50 | elif [ -f "$HOME/.password-store/$1.gpg" ]; then | 51 | elif [ -f "$HOME/.password-store/$1.gpg" ]; then |
| 51 | coproc ( | 52 | # Password exist but command fails |
| 53 | # Must be something wrong with GPG decryption | ||
| 54 | coproc ( | ||
| 52 | rofi -e "GPG passphase is not chached" \ | 55 | rofi -e "GPG passphase is not chached" \ |
| 53 | -theme-str '#window { font: "hacker 40"; }' | 56 | -theme-str '#window { font: "hacker 40"; }' |
| 54 | ) | 57 | ) |
| 55 | else | 58 | else |
| 56 | # Password doesn't exist yet | 59 | # Password doesn't exist yet |
| 57 | # Go to next rofi execution | 60 | # Go to next rofi execution |
| 58 | echo -e "\0prompt\x1f$1" | 61 | echo -e "\0prompt\x1f$1" |
| 59 | echo -e "\0message\x1fThis password doesn't exist, generate with custom arguments?" | 62 | echo -e "\0message\x1f\"NUMBER\" for length, \"-n\" to exclude spcecial chars" |
| 60 | echo -e "\0data\x1f$1" | 63 | echo -e "\0data\x1f$1" |
| 61 | echo ${GENERATION_HINT} | 64 | echo ${GENERATION_HINT} |
| 62 | fi | 65 | 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 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | ENTRIES="$(find ~/.password-store -name '*gpg' -printf %P\\n | sed 's/.gpg$//')" | ||
| 4 | GENERATION_HINT="Generate with default config" | ||
| 5 | |||
| 6 | # Generate a new password if ROFI_DATA is given by last execution | ||
| 7 | if [ -n "${ROFI_DATA}" ]; then | ||
| 8 | PASSWORD="${ROFI_DATA}" | ||
| 9 | export ROFI_DATA= | ||
| 10 | |||
| 11 | # If custom arguments for password generation is given | ||
| 12 | # Set environment variable | ||
| 13 | if [ ${ROFI_RETV} -eq 2 ]; then | ||
| 14 | extra_arguments="${1}" | ||
| 15 | fi | ||
| 16 | |||
| 17 | # Generate password in a new process | ||
| 18 | # And Use current script to copy the values info X11 selections | ||
| 19 | coproc ( | ||
| 20 | pass generate -i ${PASSWORD} ${extra_arguments} | ||
| 21 | $(dirname $0)/pass.get ${PASSWORD} | ||
| 22 | ) | ||
| 23 | |||
| 24 | exit 0 | ||
| 25 | fi | ||
| 26 | |||
| 27 | # Give rofi available passwords and exit | ||
| 28 | if [ $# -eq 0 ]; then | ||
| 29 | # Specify rofi prompt as 'Replace' | ||
| 30 | echo -e "\0prompt\x1fReplace" | ||
| 31 | |||
| 32 | echo "$ENTRIES" | ||
| 33 | exit 0 | ||
| 34 | fi | ||
| 35 | |||
| 36 | # If password doesn't exist, just quit | ||
| 37 | <<<"$ENTRIES" grep -q $1 || exit 0 | ||
| 38 | |||
| 39 | # Show message for password options | ||
| 40 | echo -e "\0prompt\x1f$1" | ||
| 41 | echo -e "\0message\x1f\"NUMBER\" for length, \"-n\" to exclude spcecial chars" | ||
| 42 | echo -e "\0data\x1f$1" | ||
| 43 | 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 @@ | |||
| 1 | #! /bin/bash | 1 | #! /bin/bash |
| 2 | 2 | ||
| 3 | export terminal=${terminal:-alacritty} | ||
| 4 | |||
| 3 | cd $(dirname $0) | 5 | cd $(dirname $0) |
| 4 | 6 | ||
| 5 | rofi -show get -modes get:./pass.get,edit:./pass.edit,rm:./pass.rm | 7 | rofi -show get -modes get:./pass.get,edit:./pass.edit,replace:./pass.replace,rm:./pass.rm |