diff options
Diffstat (limited to 'X11')
| -rwxr-xr-x | X11/rofi/pass.get | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/X11/rofi/pass.get b/X11/rofi/pass.get index 20ef852..97a67f9 100755 --- a/X11/rofi/pass.get +++ b/X11/rofi/pass.get | |||
| @@ -2,6 +2,20 @@ | |||
| 2 | 2 | ||
| 3 | GENERATION_HINT="Generate with default config" | 3 | GENERATION_HINT="Generate with default config" |
| 4 | 4 | ||
| 5 | _save_to_clipboard() { | ||
| 6 | # Copy the given password into PRIMARY selection and kill it in 30s | ||
| 7 | echo "$1" | sed -n 1p | tr -d '\n' | xsel -i -t 30000 | ||
| 8 | # Copy the second non-empty line (most of the time, account name) into CLIPBOARD selection | ||
| 9 | echo "$1" | sed -n '1d;/^./{p;q}' | tr -d '\n' | xsel -ib | ||
| 10 | } | ||
| 11 | |||
| 12 | # Show extra message | ||
| 13 | _show_extra() { | ||
| 14 | EXTRA="$(echo; echo; echo "$1" | sed '1d' | sed '1{/^$/d}')" | ||
| 15 | coproc ( rofi -e "Copied: $2$EXTRA" ) | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 5 | # Generate a new password if ROFI_DATA is given by last execution | 19 | # Generate a new password if ROFI_DATA is given by last execution |
| 6 | if [ -n "${ROFI_DATA}" ]; then | 20 | if [ -n "${ROFI_DATA}" ]; then |
| 7 | PASSWORD="${ROFI_DATA}" | 21 | PASSWORD="${ROFI_DATA}" |
| @@ -38,22 +52,20 @@ fi | |||
| 38 | # Test password exists or not | 52 | # Test password exists or not |
| 39 | RESULT="$(pass $1)" | 53 | RESULT="$(pass $1)" |
| 40 | set -x | 54 | set -x |
| 41 | if [ -n "$RESULT" ]; then | ||
| 42 | # Copy the given password into PRIMARY selection and kill it in 30s | ||
| 43 | echo "$RESULT" | sed -n 1p | tr -d '\n' | xsel -i -t 30000 | ||
| 44 | # Copy the second non-empty line (most of the time, account name) into CLIPBOARD selection | ||
| 45 | echo "$RESULT" | sed -n '1d;/^./{p;q}' | tr -d '\n' | xsel -ib | ||
| 46 | 55 | ||
| 47 | # And show extra message | 56 | if [ -n "$RESULT" ]; then |
| 48 | EXTRA="$(echo; echo; echo "$RESULT" | sed '1d' | sed '1{/^$/d}')" | 57 | _save_to_clipboard "$RESULT" |
| 49 | coproc ( rofi -e "Copied: $1$EXTRA" ) | 58 | _show_extra "$RESULT" "$1" |
| 50 | 59 | ||
| 51 | elif [ -f "$HOME/.password-store/$1.gpg" ]; then | 60 | elif [ -f "$HOME/.password-store/$1.gpg" ]; then |
| 52 | # Password exist but command fails | 61 | # Password exist but command fails, must be something wrong with GPG decryption |
| 53 | # Must be something wrong with GPG decryption | 62 | # Most of the time it is because passphrase is not cached by gpg-agent |
| 54 | coproc ( | 63 | |
| 55 | rofi -e "GPG passphase is not chached" \ | 64 | # Use zenity for passphrase input |
| 56 | -theme-str '#window { font: "hacker 40"; }' | 65 | coproc( |
| 66 | RESULT="$( zenity --password | gpg --pinentry-mode loopback --passphrase-fd 0 -d "$HOME/.password-store/$1.gpg")" | ||
| 67 | _save_to_clipboard "$RESULT" | ||
| 68 | _show_extra "$RESULT" "$1" | ||
| 57 | ) | 69 | ) |
| 58 | else | 70 | else |
| 59 | # Password doesn't exist yet | 71 | # Password doesn't exist yet |