citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

dmenu-lpass (745B)


      1 #!/usr/bin/env bash
      2 
      3 set -e
      4 
      5 export LPASS_HOME=${LPASS_HOME:-"$HOME"/.config/lpass}
      6 
      7 login() {
      8   lpass login jackbox55@gmail.com
      9 }
     10 
     11 if [ ! -f "$LPASS_HOME"/session_privatekey ]
     12 then
     13   login
     14 fi
     15 
     16 IFS=$'\n'
     17 # List all entries in LastPass vault into dmenu formatted as follows
     18 # Folder/subfolder/Name of Site [username at site] [id: id for lookup]
     19 entries=($(lpass ls --long \
     20   | cut -d ' ' -f 3- \
     21   | sed 's/\[username: /[/;s/\(.*\)\(\[.*\]\) \(\[.*\]\)/\1 \3 \2/')
     22   )
     23 
     24 # Get id from dmenu user selection
     25 selid=$(printf '%s\n' "${entries[@]}" \
     26   | dmenu -i -p 'LastPass' -l 7 \
     27   | sed 's/^.*\[id: \([0-9]\{1,\}\)\].*$/\1/')
     28 
     29 # Password username and password to clipboard
     30 lpass show --clip --user "$selid"
     31 lpass show --clip --password "$selid"