Skip to content

Instantly share code, notes, and snippets.

@DepthDeluxe
Last active September 25, 2024 22:41
Show Gist options
  • Save DepthDeluxe/15aecc68ecb42e028c96bf30cfa949e7 to your computer and use it in GitHub Desktop.
Save DepthDeluxe/15aecc68ecb42e028c96bf30cfa949e7 to your computer and use it in GitHub Desktop.
Combines the power of lastpass cli and fzf to offer an interactive fuzzy finding password experience on the command line. Lists all lastpass passwords and pipes into FZF to search by name. Once selected, the script copies desired password to the system clipboard.
#!/bin/bash
lpass_data=$(lpass ls)
if [[ "$lpass_data" == "" ]]; then
echo 'Error: You are likely not logged into lastpass, attempting to login'
exit 1
fi
chosen_element=$(echo "$lpass_data" | fzf)
if [[ "$!" -eq 0 ]]; then
chosen_element_id=$(echo "$chosen_element" | egrep -o 'id: [0-9]+' | awk '{ print $2; }')
echo "Chose id: $chosen_element_id"
lpass show --password --clip "$chosen_element_id"
else
echo 'Cancelled operation...'
fi
@BlueDrink9
Copy link

Made some tweaks

#!/bin/sh

if echo 'n' | lpass logout 2>&1 | grep -qv "you sure"; then
    echo 'Not logged in. Enter lastpass username:'
    read username
    lpass login "$username"
    if [ ! "$?" -eq 0 ]; then
      echo "Failed to login" >&2
      exit $?
    fi
fi

chosen_element="$(lpass ls | fzf)"

if [ "$?" -eq 0 ]; then
    chosen_element_id="$(echo "$chosen_element" | egrep -o 'id: [0-9]+' | awk '{ print $2; }')"
    echo "Chose id: $chosen_element_id"
    lpass show --password "$chosen_element_id" | xclip -selection clipboard
else
    echo 'Cancelled operation...'
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment