added option to type password directly in textbox

This commit is contained in:
Phuntsok Drak-pa 2019-11-04 10:57:55 +01:00
parent 740f579d61
commit 275e2c6c58
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 70 additions and 4 deletions

View File

@ -756,6 +756,25 @@
#!/usr/bin/env fish
#+END_SRC
Lets parse all the arguments passed to the script. If one of them is
=--type=, =-t= or =type=, the script will attempt to type the password to the
text area already selected without pasting the password to the clipboard.
#+BEGIN_SRC fish
for arg in $argv
switch $arg
case '--type'
set -g TYPE "yes"
case '-t'
set -g TYPE "yes"
case 'type'
set -g TYPE "yes"
case '*'
printf 'Unknown argument: %s\n.' $arg
exit 1
end
end
#+END_SRC
Now, lets get the list of the passwords that exist in our =pass= repository.
#+BEGIN_SRC fish
set passwords (find $HOME/.password-store -type f -name "*.gpg" | \
@ -778,12 +797,39 @@
end
#+END_SRC
Finally, lets copy the password for 45 seconds in the clipboard.
#+BEGIN_SRC fish
Depending on the arguments passed earlier, we might want some different
behavior.
#+BEGIN_SRC fish :noweb yes
if test $TYPE = "yes"
<<rofi-pass-type>>
else
<<rofi-pass-copy>>
end
#+END_SRC
The default behavior is to copy the password to the clipboard for 45 seconds,
so lets do that.
#+NAME: rofi-pass-copy
#+BEGIN_SRC fish :noweb yes :tangle no
pass show -c $password 2> /dev/null
#+END_SRC
And were done!
Else, if we passed =--type=, =-t= or =type= as an argument of the script, we
want it to attempt to type our password in the currently selected text input.
Lets do that.
#+NAME: rofi-pass-type
#+BEGIN_SRC fish :noweb yes :tangle no
set -l IFS
<<rofi-pass-type-get-password>>
printf %s $pass | xvkbd -file -
#+END_SRC
To correctly get the password from =pass=, we need to parse the output and
only get the first line, hence the following command.
#+NAME: rofi-pass-type-get-password
#+BEGIN_SRC fish :tangle no
set pass (pass show $password | string split -n \n)[1]
#+END_SRC
* Rofi-umount
:PROPERTIES:

View File

@ -1,5 +1,19 @@
#!/usr/bin/env fish
for arg in $argv
switch $arg
case '--type'
set -g TYPE "yes"
case '-t'
set -g TYPE "yes"
case 'type'
set -g TYPE "yes"
case '*'
printf 'Unknown argument: %s\n.' $arg
exit 1
end
end
set passwords (find $HOME/.password-store -type f -name "*.gpg" | \
string replace -r ".*.password-store/" "" | \
string replace -r ".gpg" "" | sort)
@ -12,4 +26,10 @@ if test -z $password
exit
end
pass show -c $password 2> /dev/null
if test $TYPE = "yes"
set -l IFS
set pass (pass show $password | string split -n \n)[1]
printf %s $pass | xvkbd -file -
else
pass show -c $password 2> /dev/null
end