From ee68f3f15cbd7473d8f8e2c200c4d70cd91c324f Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 7 Dec 2016 18:10:32 -0800 Subject: [PATCH] [Linux] Add keepass functions --- dotfiles/lib/shellenv/functions.sh | 10 ++------ dotfiles/lib/shellenv/keepass.sh | 39 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 dotfiles/lib/shellenv/keepass.sh diff --git a/dotfiles/lib/shellenv/functions.sh b/dotfiles/lib/shellenv/functions.sh index 931b84d2..08723e80 100644 --- a/dotfiles/lib/shellenv/functions.sh +++ b/dotfiles/lib/shellenv/functions.sh @@ -464,12 +464,6 @@ function localip { esac } -function keepass_system_password { - keepasshttp.py --get -u "http://$(hostname).systempassword" | - jq '.[].password' | unescape.py -} - -function keepass_keepass_password { - keepasshttp.py --get -u "http://keepass.password" | - jq '.[].password' | unescape.py +function all_lines_after { + sed -n "/$1/"'$p' } diff --git a/dotfiles/lib/shellenv/keepass.sh b/dotfiles/lib/shellenv/keepass.sh new file mode 100644 index 00000000..0ad355e4 --- /dev/null +++ b/dotfiles/lib/shellenv/keepass.sh @@ -0,0 +1,39 @@ +keepass_system_password() { + keepasshttp.py --get -u "http://$(hostname).systempassword" | + jq '.[].password' | unescape.py +} + +keepass_password() { + keepasshttp.py --get -u "http://keepass.password" | + jq '.[].password' | unescape.py +} + +my_kp() { + kpcli --kdb "$HOME/SparkleShare/config/db.kdbx" \ + --key "$HOME/SparkleShare/config/creds/keepass.key" \ + --pwfile <(keepass_password) "$@" +} + +list_passwords() { + my_kp --command 'ls Root/' | sed -n '/=== Entries ===/,$p' | tail -n +2 +} + +get_pass_from_entry() { + grep -E '^ *Pass:' | get_cols 2 +} + +select_password() { + list_passwords | rofi -dmenu -i | get_cols 2 +} + +get_password() { + my_kp --command "show -f Root/$1" | get_pass_from_entry +} + +echo_selected_password() { + get_password "$(select_password)" +} + +type_selected_password() { + xdotool type --clearmodifiers "$(echo_selected_password)" +}