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 /X11/rofi/pass.replace | |
| parent | fe8327560ca95571cf6f2ce4762377a112cd815d (diff) | |
Improve password script
Diffstat (limited to 'X11/rofi/pass.replace')
| -rwxr-xr-x | X11/rofi/pass.replace | 43 |
1 files changed, 43 insertions, 0 deletions
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} | ||