From dbb0d6bf3a46f3cf89c561974fcf143fc17902c5 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 22 Oct 2019 10:36:28 +0200 Subject: [PATCH] [ssh_tools] tabssh: handle tmux --- ssh_tools/tabssh.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ssh_tools/tabssh.sh b/ssh_tools/tabssh.sh index ec7f6b4..6f72694 100755 --- a/ssh_tools/tabssh.sh +++ b/ssh_tools/tabssh.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# tabssh.sh, Copyright © 2013 Matteo Cypriani +# tabssh.sh, Copyright © 2013, 2019 Matteo Cypriani # (Formerly named cluster-ssh.sh) # # This program is free software. It comes without any warranty, to @@ -56,9 +56,14 @@ elif [ $# -ne 1 ] ; then fi # Check dependencies -SCREEN=$(command -v screen) -if [ -z "$SCREEN" ] ; then - err "GNU screen is required by this script." +TMUX_CMD=$(command -v tmux) +SCREEN_CMD=$(command -v screen) +if [ -n "$TMUX_CMD" ] ; then + echo "tmux is available, we'll be using it." +elif [ -n "$SCREEN_CMD" ] ; then + echo "tmux is not available, we'll be using GNU screen instead." +else + err "Either tmux or GNU screen is required by this script." exit $EXIT_DEPENDENCY fi @@ -82,6 +87,10 @@ fi # Create the screen tabs while read -r HOST ; do SSH="ssh ${LOGIN}${HOST}" - # shellcheck disable=SC2086 - $SCREEN -t "$SSH" $SSH + if [ -n "$TMUX_CMD" ] ; then + $TMUX_CMD new-window -d -n "$SSH" -- "$SSH" + else + # shellcheck disable=SC2086 + $SCREEN_CMD -t "$SSH" $SSH + fi done <"$HOSTS"