Created
April 25, 2023 06:49
-
-
Save istarkov/eeb1d4fd4c2e442c90d0120dc7766cea to your computer and use it in GitHub Desktop.
Get bw password by exact name, fix of this https://github.com/bitwarden/clients/issues/3366
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
# https://github.com/bitwarden/clients/issues/3366 | |
# Usage: | |
# bwget <item-name> | |
# to get any org password | |
# bwget <item-name> null | |
# to get self password | |
bwget() { | |
local pwd | |
local count | |
# by default search inside any organisation | |
local organisation=${2:-notnull} | |
count=$(bw list items --pretty --organizationid ${organisation} | jq -r '[.[] | select(.name=="'$1'")] | length') | |
if [[ "$count" -gt 1 ]]; then | |
echo "Multiple items found" | |
return 1 | |
fi | |
if [[ "$count" -lt 1 ]]; then | |
echo "No items found" | |
return 1 | |
fi | |
pwd=$(bw list items --pretty --organizationid ${organisation} | jq -r '.[] | select(.name=="'$1'") | .login.password') | |
if [[ -z "$pwd" ]]; then | |
echo "Password not found" | |
return 1 | |
fi | |
echo "$pwd" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment