diff --git a/home/xonsh_footer.xsh b/home/xonsh_footer.xsh index 1b6c8a2..019831e 100644 --- a/home/xonsh_footer.xsh +++ b/home/xonsh_footer.xsh @@ -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