Created
January 31, 2019 01:49
-
-
Save raphaelcastaneda/afe1ee9669243f263248c6b511d65e7c to your computer and use it in GitHub Desktop.
Bash function to search lastpass cli and put passwords on your clipboard
This file contains hidden or 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
function getpw() { | |
if [ $# -lt 1 ]; then | |
echo "Usage: getpw <LPASS_ENTRY>" | |
return 1 | |
fi | |
options=$(lpass ls | egrep -i "$*") | |
count=$(echo "$options" | wc -l | sed 's/ //g') | |
if [ $count -gt 1 ]; then | |
echo "$options" | |
echo "Too many LastPass entries returned. Please pick from one of the above $count items." | |
return 2 | |
elif [ $count -eq 0 -o -z "$options" ]; then | |
echo "No options returned. Please check your search and try again." | |
return 3 | |
else | |
option_id=$(echo "$options" | awk '{print $NF}' | cut -d] -f1) | |
password=$(lpass show "$option_id" --password | tr -d '\n') | |
if [ -n "$password" ]; then | |
echo "Placing password for $options in to the clipboard..." | |
echo -n "$password" | pbcopy | |
else | |
echo "No password defined for $options, cannot copy password." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't remember where I found this thing, but I use it all the time and I don't want to lose it.