Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added :clip command #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ in a convenient way using [rofi](https://github.com/DaveDavenport/rofi).
respectively.
`:otp` will generate an OTP, either `pass-otp(1)` style, or according to the
`otp_method:`, if it is defined.
`:clip` puts every field after it into the clipboard.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add an example.

* Generating OTPs.
The format for OTPs should either be `pass-otp(1)`-compatible
```
Expand Down
32 changes: 23 additions & 9 deletions rofi-pass
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,35 @@ checkIfPass () {

autopass () {
x_repeat_enabled=$(xset q | awk '/auto repeat:/ {print $3}')
inclip='false'
clipcontent=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should put both inclip and clipcontent as local variables.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the '%s%s ' supposed to be? Why is there a whitespace at the end?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'%s%s ' basically requires two string arguments. (in that case clipcontent wordToPrint).

I don't know if the whitespace is required but lets look at an example:

If we have:

:clip user pass

without the whitespace the clipboard content after the auto fill would look like: userpass. Which is probably not the expected behaviour, therefore there's a whitespace after it so it turns to user pass.

Copy link
Contributor

@moviuro moviuro Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly you mean '%s %s' instead of '%s%s '?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say we have this auto pass field: :clip user otp url

Then the content of the clipcontent looks like this (loop iteration -> result):

Look at the whitespaces here:

  • clipcontent=""
  • clipcontent=$(printf '%s%s ' "" "<user>") -> result: clipcontent="<user> "
  • clipcontent=$(printf '%s%s ' "<user> " "<otp>") -> result: clipcontent="<user> <otp> "
  • clipcontent=$(printf '%s%s ' "<user> <otp> " "<url>") -> result: clipcontent="<user> <otp> <url> "

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the whitespace at the end of the string not pose any issue?

else
printf '%s' "$wordToPrint" | xdotool type --clearmodifiers --file -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably exile xdotool type --clearmodifiers --file - into a function of its own. Certainly for another PR, though.

fi
fi
done
if [[ ${inclip} == "true" ]]; then
printf '%s' "$clipcontent" | doClip
fi
if [[ ${auto_enter} == "true" ]]; then
xdotool key Return
fi
Expand Down