Last active
November 16, 2020 22:43
-
-
Save EsmailELBoBDev2/7233e1b2a8ba274b54289af555336f96 to your computer and use it in GitHub Desktop.
A bash script to work with Bitwarden CLI and pass together, TOTP from PASS and Passwords From Bitwarden
This file contains 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
#!/bin/bash | |
## 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 | |
fi | |
## 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 | |
else | |
## https://stackoverflow.com/a/1429628 | |
echo -ne "Your $1's Password: " | |
echo "${pass}" | sed -n 2p | |
fi | |
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!" | |
else | |
echo "Your $1's TOTP: " | |
oathtool -b --totp `pass show $1` | |
fi | |
## For the look sake! | |
echo "----" | |
## Exit with good status | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to
add ask for password on same lineandto pause user's input for 2sdone 👍