Created
March 25, 2024 19:09
-
-
Save sangheonhan/924ed53cffe2913e9059d0bb3a996c81 to your computer and use it in GitHub Desktop.
Creates tmux windows for SSH sessions to given hostnames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
current_dir_name=$(basename "$PWD") | |
session_name=${current_dir_name// /_} | |
if ! tmux has-session -t "$session_name" 2>/dev/null; then | |
tmux new-session -d -s "$session_name" -n "${1}" -c "$PWD" | |
tmux send-keys -t "$session_name" "ssh ${1}" C-m | |
shift | |
else | |
tmux new-window -t "$session_name" -n "${1}" -c "$PWD" | |
tmux send-keys -t "$session_name:${1}" "ssh ${1}" C-m | |
shift | |
fi | |
for host in "$@" | |
do | |
tmux new-window -t "$session_name" -n "$host" -c "$PWD" | |
tmux send-keys -t "$session_name:$host" "ssh $host" C-m | |
done | |
tmux select-window -t "$session_name:0" | |
tmux attach-session -t "$session_name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment