.dotfiles/tmux/tmux-ssher

26 lines
614 B
Plaintext
Raw Normal View History

2024-02-01 14:48:34 +01:00
#!/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')"
2024-02-01 14:48:34 +01:00
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