Skip to content

Instantly share code, notes, and snippets.

@lttlrck

lttlrck/bash.rc

Last active Jan 3, 2019
Embed
What would you like to do?
Use peco, jq and bitwarden for SSH login
# gets user name and password from bitwarden
# keeps a list of all conenctions, and presents them in peco so easy filtering
export BW_SESSION="***************************"
sss() {
cat .connections | sort | uniq > .connections_ && mv .connections_ .connections
IFS=$'\n' array=($(cat .connections | peco --print-query))
r1=${array[1]}
r2=${array[2]}
addr=""
if [[ "$r2" == "" ]]; then
#echo No match, using $r1
addr=$r1
else
# echo match, using $r2
addr=$r2
fi
o=$(bw list items --search $addr)
u=$(echo $o | jq -r ".[0].login.username")
p=$(echo $o | jq -r ".[0].login.password")
echo login as $u
sshpass -p $p ssh $u@$addr
if [[ $? == 0 ]]; then
echo $addr >> .connections
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.