Skip to content

Instantly share code, notes, and snippets.

@istarkov
Created April 25, 2023 06:49
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 istarkov/eeb1d4fd4c2e442c90d0120dc7766cea to your computer and use it in GitHub Desktop.
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
# 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