Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A bash script to work with Bitwarden CLI and pass together, TOTP from PASS and Passwords From Bitwarden
## Help Message
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ $# -eq 0 ]; then
echo "Usage: `basename $0` password's name/password's ID"
echo "EX: `basename $0` github"
echo "EX: `basename $0` 33j9p592-3c2u-be6h-nek8-e3y4cpbvf53c"
exit 0
## stty -echo disables/hides the user input to avoid leaking password (bitwarden takes time to run so if we kept it normal some of your password would be leaked)
## Ask user to add his own Bitwarden Master Password and save it into "pass"
stty -echo
echo -ne "Type Your Bitwarden MP: "
pass=$(bw get password $1 2>&1)
totp=$(pass show $1 2>&1)
stty echo
##Prints *** in the password place
echo "****"
## For the look sake!
echo "----"
## Error handling for bitwarden and pass
if [[ $pass == *"Not found"* ]]; then
echo "Did not find password for $1"
elif [[ $pass == *"Invalid master password"* ]]; then
echo "Wrong Master Password"
elif [[ $pass == *"More than one result was found"* ]]; then
echo -ne "More than one item found under the same name! so please search by it's ID: "
echo ""
echo "$pass" | sed -n 3,9999p
echo -ne "Your $1's Password: "
echo "${pass}" | sed -n 2p
echo "--"
if [[ $totp == *"is not in the password store"* ]]; then
echo "Did not found TOTP for $1"
elif [[ ! $totp ]]; then
echo "Something went wrong with pass and totp, please report!"
echo "Your $1's TOTP: "
oathtool -b --totp `pass show $1`
## For the look sake!
echo "----"
## Exit with good status
exit 0

This comment has been minimized.

Copy link
Owner Author

@EsmailELBoBDev2 EsmailELBoBDev2 commented Nov 13, 2020

I want to add ask for password on same line and to pause user's input for 2s

done 👍

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