Skip to content

Instantly share code, notes, and snippets.

@mikesmithgh
Created February 14, 2024 13:33
Show Gist options
  • Save mikesmithgh/9c7b8421526c431672cb7a51a23387c9 to your computer and use it in GitHub Desktop.
Save mikesmithgh/9c7b8421526c431672cb7a51a23387c9 to your computer and use it in GitHub Desktop.
lpass fzf wrapper
#!/usr/bin/env bash
lp='/opt/homebrew/bin/lpass'
if (( $# )); then
$lp "$@"
exit $?
fi
if ! $lp status -q; then
printf "\e[31m\e[1mNot logged in\e[0m.\n"
read -r -p "Username: " user
$lp login "$user"
fi
$lp ls --format $'\e[34;5m%ag \e[33;5m%an\e[m \e[35;5m%au\e[m \e[90;5m[id: %ai]\e[m' --color=always | \
sed -E -e 's/^[ \t]*//g' -e '/\[id:/!d' -e '/\[Deprecated/d' -e 's/^(.*5m) /\1None /g' | \
fzf --ansi --header $' <\e[33;5menter\e[m> Copy password to clipboard\n <\e[33;5mctrl-o\e[m> Output JSON' \
--prompt='󰑆 ' \
--border-label=' Lastpass ' \
"--bind=ctrl-o:execute@echo {} | sed 's/.*\[id: \([0-9]*\)\].*/\1/g' | xargs '$lp' show --json | jq . @+abort" \
"--bind=enter:execute@echo {} | sed 's/.*\[id: \([0-9]*\)\].*/\1/g' | xargs '$lp' show --password --clip @+abort"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment