Skip to content

Instantly share code, notes, and snippets.

@sangheonhan
Created March 25, 2024 19:09
Show Gist options
  • Save sangheonhan/924ed53cffe2913e9059d0bb3a996c81 to your computer and use it in GitHub Desktop.
Save sangheonhan/924ed53cffe2913e9059d0bb3a996c81 to your computer and use it in GitHub Desktop.
Creates tmux windows for SSH sessions to given hostnames
#!/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