26 lines
612 B
Plaintext
26 lines
612 B
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
if [[ $# -eq 1 ]]; then
|
||
|
selected=$1
|
||
|
else
|
||
|
selected=$(grep "Host .*" ~/.ssh/config | grep -v "*" | sed "s/Host \(.*\)/\1/" | fzf --cycle --bind 'tab:toggle-up,btab:toggle-down')
|
||
|
fi
|
||
|
|
||
|
if [[ -z $selected ]]; then
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
selected_name="ssh_$selected"
|
||
|
tmux_running=$(pgrep tmux)
|
||
|
|
||
|
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
||
|
tmux new-session -s $selected_name -c $selected ssh "$selected"
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
if ! tmux has-session -t=$selected_name 2> /dev/null; then
|
||
|
tmux new-session -ds $selected_name -c $selected ssh "$selected"
|
||
|
fi
|
||
|
|
||
|
tmux switch-client -t $selected_name
|