Skip to content

Instantly share code, notes, and snippets.

@nagy135
Last active August 13, 2021 13:48
Show Gist options
  • Save nagy135/100106ca67832da936db7e3caafa5984 to your computer and use it in GitHub Desktop.
Save nagy135/100106ca67832da936db7e3caafa5984 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Dependencies: https://github.com/junegunn/fzf
# Convenient way of selecting connection on terminal when often ssh-ing or copying files from other servers
declare -A conn_pairs
conn_pairs["hostname_DEV"]="[email protected]"
conn_pairs["anotherhostname_STAGE"]="[email protected]"
[[ $1 == 'scp' ]] && SCP=1 || SCP=0
[[ $1 == 'clip' ]] && CLIP=1 || CLIP=0
choice=$(echo ${!conn_pairs[@]} | tr ' ' '\n' | fzf)
[ -z $choice ] && echo "nothing chosen...exiting" && exit 1
if [ $CLIP -eq 1 ]; then
echo -n ${conn_pairs[${choice}]} | xclip -sel clipboard
exit 0
fi
if [ $SCP -eq 0 ]; then
ssh ${conn_pairs[${choice}]}
exit 0
fi
# else scp transfer
echo "1 : local => server"
echo "2 : server => local"
echo -n "Direction? (write number): "
read DIRECTION
echo -n "From: "
read FROM
echo -n "To: "
read TO
[ $DIRECTION -eq 1 ] \
&& echo "running scp -r $FROM ${conn_pairs[${choice}]}:$TO" \
|| echo "running scp -r ${conn_pairs[${choice}]}:$FROM $TO"
[ $DIRECTION -eq 1 ] \
&& scp -r $FROM ${conn_pairs[${choice}]}:$TO \
|| scp -r ${conn_pairs[${choice}]}:$FROM $TO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment