Created
July 26, 2014 22:14
-
-
Save conanite/e92ccc1baa0bea89c4e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- ruby-mode -*- | |
base = File.expand_path "~/.password-store" | |
pass_files = `find #{base} | grep -v -e .git -e .gpg-id` | |
trimmed = pass_files. | |
split(/\n/). | |
map { |f| f.gsub "#{base}", '' }. | |
map { |f| f.gsub /^\//, '' }. | |
reject { |f| f == '' || f !~ /.gpg$/ }. | |
map { |f| f.sub /.gpg$/, '' } | |
$*.each { |pattern| | |
trimmed = trimmed.select { |f| f.index(pattern) != nil } | |
} | |
if trimmed.length == 1 | |
pw = `/bin/bash -lc '/usr/bin/pass show #{trimmed[0]}'` | |
puts pw | |
elsif trimmed.length > 0 | |
trimmed.each { |f| $stderr.puts f } | |
else | |
$stderr.puts "no results for #{$*.join ' '}" | |
$stderr.puts `pass` | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getpw $* | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment