Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 41 lines (35 sloc) 1.21 KB
#!/usr/bin/env bash
# Proxy commands for the bitwarden CLI, intercepting them to get or set a
# session token for seamless use between shells and other programs.
# Make sure this script is in your $PATH, so you can simply run 'bw' like you
# normally would.
# If you have a $HOME/bin dir that is at the front of your $PATH, you should be
# able to use this as an install method:
# curl https://raw.githubusercontent.com/mjslabs/bitagent/master/examples/bw > $HOME/bin/bw && chmod 0755 $HOME/bin/bw
# Installation of the bitwarden CLI
bwcmd="/snap/bin/bw"
# Default socket location
basock="${HOME}/.bitagent.sock"
# This assumes you've run a `go install`
bitagent="${GOBIN}/bitagent $basock"
if [[ ! -e $basock ]]; then
$bitagent 1>/dev/null & disown
fi
if [[ $1 == "unlock" ]]; then
unlockOut=$($bwcmd unlock)
<<< $unlockOut grep -q BW_SESSION
if [[ $? == "0" ]]; then
echo Success
echo "P"$(<<< $unlockOut tr -d '\n' | sed -e 's/^.*BW_SESSION="\(.*\)".*$/\1/') | nc -U $basock -N
else
echo $unlockOut
fi
exit
else
export BW_SESSION="$(echo G | nc -U $basock -N)"
if [[ $BW_SESSION == "" ]]; then
# Avoids "Session key is invalid." being sent to the terminal
unset BW_SESSION
fi
$bwcmd $*
fi
You can’t perform that action at this time.