Created
November 26, 2017 22:05
-
-
Save xstasi/cd9d5b58d754937bbb1487bd8c3e8f15 to your computer and use it in GitHub Desktop.
tmux-based mssh replacement
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 | |
# Avoid nesting tmuces | |
if [ -n "${TMUX}" ]; then | |
echo "Cannot run this inside tmux." | |
exit | |
fi | |
# Help | |
if [ -z "$1" ] ; then | |
echo "Usage: $0 <host1> [host2] ..." | |
exit | |
fi | |
# Create a temporary file as a tmux script | |
tmux_script=$(mktemp) | |
sess="mssh-${RANDOM}" | |
# Initialize the tmux session with a meaningful name | |
echo "new-session -t ${sess}" > ${tmux_script} | |
# Generate a line to create a new pane with ssh for every server | |
for i in $@ ; do | |
echo "split-window 'unset HISTFILE; ssh ${i}'" >> ${tmux_script} | |
# Manually set layout to tiled each time in order not to have "no space left" / "lost server" errors | |
echo "select-layout tiled" >> ${tmux_script} | |
done | |
# Get rid of the first pane with no sshs, then reset the layout | |
echo "kill-pane -t 0" >> ${tmux_script} | |
echo "select-layout tiled" >> ${tmux_script} | |
# Lastly switch to a tiled layout and attach to the session | |
echo "attach" >> ${tmux_script} | |
# Fire up tmux, load the script | |
tmux new-session -t ${sess} \; source-file ${tmux_script} | |
# Remove the temp file | |
rm -f ${tmux_script} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will allow you to toggle that feature with
Ctrl-B e