Silence and document function

This commit is contained in:
Greg Hellings
2024-06-12 14:27:50 -05:00
committed by greg-compass
parent 4fb00208f4
commit 8cbae36433
+8 -5
View File
@@ -1,13 +1,16 @@
# vim: set ft=python :
def bw_unlock():
"""Unlocks the BitWarden CLI and adds the resulting session code to the
current environment variables. Also returns the code for them."""
if "BW_SESSION" in ${...}:
return $BW_SESSION
result = !(bw unlock)
while not result:
result = !(bw unlock)
l = [k for k in result.lines if 'BW_SESSION="' in k][0]
left, right = l.split("=")
result = $(bw unlock)
while "BW_SESSION" not in result:
result = $(bw unlock)
lines = result.split("\n")
l = [k for k in lines if 'BW_SESSION="' in k][0]
left, right = l.split("=", 1)
token = right[1:-1]
$BW_SESSION = token
return token