Skip to content

Instantly share code, notes, and snippets.

@conanite
Created July 26, 2014 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanite/e92ccc1baa0bea89c4e6 to your computer and use it in GitHub Desktop.
Save conanite/e92ccc1baa0bea89c4e6 to your computer and use it in GitHub Desktop.
#!/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
getpw $* | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment