diff --git a/.local/bin/README.org b/.local/bin/README.org index b0ec3d0..c6f7bb3 100644 --- a/.local/bin/README.org +++ b/.local/bin/README.org @@ -756,6 +756,25 @@ #!/usr/bin/env fish #+END_SRC + Let’s 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, let’s 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, let’s 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" + <> + else + <> + end + #+END_SRC + + The default behavior is to copy the password to the clipboard for 45 seconds, + so let’s do that. + #+NAME: rofi-pass-copy + #+BEGIN_SRC fish :noweb yes :tangle no pass show -c $password 2> /dev/null #+END_SRC - And we’re 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. + Let’s do that. + #+NAME: rofi-pass-type + #+BEGIN_SRC fish :noweb yes :tangle no + set -l IFS + <> + 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: diff --git a/.local/bin/rofi-pass b/.local/bin/rofi-pass index e9cbf82..2a9ed81 100755 --- a/.local/bin/rofi-pass +++ b/.local/bin/rofi-pass @@ -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