Created
February 23, 2021 18:56
-
-
Save dontlaugh/8327c97ca7653f07689d1d9b73e09b94 to your computer and use it in GitHub Desktop.
Bitwarden CLI wrapper
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 python3 | |
import json | |
import os | |
import subprocess | |
import sys | |
from subprocess import PIPE | |
def bw_status(): | |
result = subprocess.run(['bw', 'status'], env=os.environ, stdout=PIPE, check=True) | |
if json.loads(result.stdout)["status"] != "unlocked": | |
print("you're not logged in. try `bw unlock <password>` or `bw login <email> <password>`") | |
sys.exit(1) | |
def list_items(): | |
result = subprocess.run(['bw', 'list', 'items'], env=os.environ, stdout=PIPE, check=True) | |
data = json.loads(result.stdout) | |
for item in data: | |
print(item["name"]) | |
def main(): | |
# Check if we're logged in. The user must log in from the shell environment that invokes | |
# this python script. | |
bw_status() | |
# List items by name | |
# bw list items | jq '.[].name' | |
list_items() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment