Skip to content

Instantly share code, notes, and snippets.

@xstasi
Created November 26, 2017 22:05
Show Gist options
  • Save xstasi/cd9d5b58d754937bbb1487bd8c3e8f15 to your computer and use it in GitHub Desktop.
Save xstasi/cd9d5b58d754937bbb1487bd8c3e8f15 to your computer and use it in GitHub Desktop.
tmux-based mssh replacement
#!/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}
@ldidry
Copy link

ldidry commented Oct 12, 2018

echo "bind-key e setw synchronize-panes" >> ${tmux_script}

will allow you to toggle that feature with Ctrl-B e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment