Skip to content

Instantly share code, notes, and snippets.

@MartinSadovy
Last active September 1, 2017 18:22
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 MartinSadovy/1eb50ddb48452112a10f0b988e5d8a7d to your computer and use it in GitHub Desktop.
Save MartinSadovy/1eb50ddb48452112a10f0b988e5d8a7d to your computer and use it in GitHub Desktop.
lpass: search in show

Interactive console LastPass

Usage: lps [keyword]

Then it asks you to copy or show password:

  • if you want to copy, write that number before name of entry
  • if you want show the password, show [number] (or s [number], or s[number])
#!/bin/sh
# Usage: 1) change $USERNAME
# 2) save script to /bin/ (or anywhere you want) and chmod +x lps.sh
# 3) lps.sh google.com
export LPASS_DISABLE_PINENTRY=1
USERNAME=sodae@email.cz
isLogged=$(lpass status)
echo $isLogged;
if [[ $isLogged != *"Logged in as $USERNAME"* ]]
then
lpass login --trust $USERNAME;
fi;
function printField {
id=$1
fieldName=$2
value=$(lpass show $id --$fieldName)
echo -en "\e[33m$fieldName: \e[0m"
if [ $2 = "password" ]
then
echo -e "\e[8m$value\e[0m"
else
echo -e "\e[0m$value\e[0m"
fi
}
function printHead {
id=$1
groupName=$(lpass ls | grep -i "$id" | sed -r 's/(.*)\/.*\[id: [0-9]+\]/\1/')
name=$(lpass show $id --name)
echo -e "\e[4m$2)\e[0m \e[36m\e[1m$groupName/\e[34m$name \e[0m \e[92m[id: $id]\e[0m"
}
declare -A assoc
declare -i number
i=1
for LINE in $(lpass ls | grep -i $@ | sed -r 's/.*\[id: ([0-9]+)\]/\1/'); do
((number++))
printHead $LINE $number
printField $LINE "username"
#printField $LINE "password"
printField $LINE "url"
printField $LINE "note"
echo ""
assoc["$number"]=$LINE
done
while true
do
echo -n "What password would you like copy or show? (empty = exit; prefix 's' = show): "
read -r key
if [ -z "$key" ]
then
exit;
fi
if [[ $key == "s"* ]];
then
id=$(echo $key | sed -r 's/s.*([0-9]+)/\1/')
id=${assoc[$id]}
else
id=${assoc[$key]}
fi
if [ -z "$id" ]
then
echo "Not found, please select one of 1..$number"
else
if [[ $key == "s"* ]];
then
lpass show $id -p
else
lpass show $id -cp
echo "Password for $id id is copied"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment