Created
April 18, 2024 14:23
-
-
Save nilscox/a4c9f1c998e09c30100475e1f145d2ac to your computer and use it in GitHub Desktop.
Wofi script to copy passwords from bitwarden (requires bitwarden-cli, wl-clipboard and jq)
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
#!/usr/bin/env bash | |
session=$(systemctl --user show-environment | grep '^BW_SESSION=' | sed 's/^BW_SESSION=//') | |
if [ -n "$session" ]; then | |
items=$(bw --session "$session" list items) | |
[ "$?" -ne 0 ] && unset session | |
fi | |
if [ -z "$session" ]; then | |
systemctl --user unset-environment BW_SESSION | |
mpw=$(wofi --dmenu --password) | |
[ -z "$mpw" ] && exit 1 | |
session=$(echo "$mpw" | bw unlock --raw) | |
[ "$?" -ne 0 ] && exit 1 | |
systemctl --user set-environment BW_SESSION="$session" | |
$0; exit $? | |
fi | |
names=$(echo -E "$items" | jq -r '.[].name') | |
item=$(echo "$names" | wofi --dmenu -i --matching=fuzzy) | |
[ -z "$item" ] && exit 1 | |
password=$(echo "$items" | jq -r ".[] | select(.name == \"$item\") | .login.password") | |
wl-copy "$password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment