diff --git a/README.md b/README.md index a27cd30..7a61c98 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,17 @@ in a convenient way using [rofi](https://github.com/DaveDavenport/rofi). * The field names for `user`, `url` and `autotype` are configurable * Bookmarks mode (open stored URLs in browser, default: Alt+x) * Share common used passwords between several entries (with different URLs, usernames etc) +* Each field after `:clip` gets copied into the clipbard. + +``` +hunter2 +user: foo +url: http://example.com +oauth://[...] +autotype: user :tab pass :clip :otp +``` + +The otp token will now be copied into the clipboard after auto-typing. ## Requirements diff --git a/rofi-pass b/rofi-pass index 752ee2c..b92067b 100755 --- a/rofi-pass +++ b/rofi-pass @@ -72,21 +72,35 @@ checkIfPass () { autopass () { x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}') + local inclip='false' + local clipcontent="" xset r off rm -f "$HOME/.cache/rofi-pass/last_used" printf '%s\n' "${root}: $selected_password" > "$HOME/.cache/rofi-pass/last_used" for word in ${stuff["$AUTOTYPE_field"]}; do - case "$word" in - ":tab") xdotool key Tab;; - ":space") xdotool key space;; - ":delay") sleep "${delay}";; - ":enter") xdotool key Return;; - ":otp") printf '%s' "$(generateOTP)" | xdotool type --clearmodifiers --file -;; - "pass") printf '%s' "${password}" | xdotool type --clearmodifiers --file -;; - *) printf '%s' "${stuff[${word}]}" | xdotool type --clearmodifiers --file -;; - esac + wordToPrint="" + case "$word" in + ":tab") xdotool key Tab;; + ":space") xdotool key space;; + ":delay") sleep "${delay}";; + ":enter") xdotool key Return;; + ":otp") wordToPrint="$(generateOTP)";; + "pass") wordToPrint="${password}";; + ":clip") inclip=true;; + *) wordToPrint="${stuff[${word}]}";; + esac + if [[ ! -z "$wordToPrint" ]]; then + if [[ ${inclip} == "true" ]]; then + clipcontent=$(printf '%s%s ' "$clipcontent" "$wordToPrint") + else + printf '%s' "$wordToPrint" | xdotool type --clearmodifiers --file - + fi + fi done + if [[ ${inclip} == "true" ]]; then + printf '%s' "$clipcontent" | sed -e 's/ *$//' | doClip + fi if [[ ${auto_enter} == "true" ]]; then xdotool key Return fi