summaryrefslogtreecommitdiffstats
path: root/rofi-gpgpass
diff options
context:
space:
mode:
Diffstat (limited to 'rofi-gpgpass')
-rwxr-xr-xrofi-gpgpass80
1 files changed, 80 insertions, 0 deletions
diff --git a/rofi-gpgpass b/rofi-gpgpass
new file mode 100755
index 0000000..5193ee2
--- /dev/null
+++ b/rofi-gpgpass
@@ -0,0 +1,80 @@
+#!/usr/bin/env ruby
+
+#
+# rofi-gpgpass - small script to type passwords from my passwords.gpg
+#
+# Copyright (c) 2022 Florian Pritz <bluewind@xinu.at>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http: #www.gnu.org/licenses/
+#
+
+require 'open3'
+
+$pwfile = "#{ENV['HOME']}/passwords.gpg"
+
+def get_passwords(pwfile)
+ data = `gpg --quiet --batch --decrypt "#{pwfile}" | grep -v '^HIDEOLD'`
+ raise "Failed to get passwords" if $? != 0 or data == '""'
+ return data
+end
+
+def get_single_password(passwords, identifier)
+ identifier.chomp!
+ passwords.split("\n").each do |line|
+ if line.end_with?(identifier)
+ return line.gsub(/^"([^"]+)" .*$/, '\1').chomp if line =~ /^"/
+ return line.gsub(/^([^ ]+) .*$/, '\1').chomp
+ end
+ end
+ return nil
+end
+
+def get_identifiers(passwords)
+ pass_array = passwords.split("\n").map do |line|
+ next line.gsub(/^"([^"]+)" (.*)$/, '\2') if line =~ /^"/
+ next line.gsub(/^([^ ]+) (.*)$/, '\2')
+ end
+ return pass_array.join("\n")
+end
+
+def rofi_select(passwords)
+ Open3.popen2("rofi -lines 20 -dmenu -i -p password") do |stdin, stdout, wait_thr|
+ stdin.puts get_identifiers(passwords)
+ return stdout.gets
+ end
+end
+
+def type_password(identifier, passwords)
+ password = get_single_password(passwords, identifier)
+
+ x_repeat_enabled = `xset q | awk '/auto repeat:/ {print $3}'`.chomp
+ system("xset r off")
+
+ Open3.popen2("xdotool type --clearmodifiers --file -") do |stdin, stdout, wait_thr|
+ stdin.write password
+ end
+
+ system("xset r '#{x_repeat_enabled}'")
+end
+
+def main()
+ passwords = get_passwords($pwfile)
+ selection = rofi_select(passwords)
+ type_password(selection, passwords)
+
+ return 1
+end
+
+
+exit(main())