mssh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #/bin/sh
  2. #
  3. # -*- mssh -*-
  4. #
  5. # mssh: ssh multiplexer using tmux
  6. #
  7. # (following the excellent idea of Christoph Egger:
  8. # http://www.christoph-egger.org/weblog/entry/33)
  9. #
  10. # Author: 2011, Emmanuel Bouthenot <kolter@openics.org>
  11. #
  12. # This program is free software. It comes without any warranty, to
  13. # the extent permitted by applicable law. You can redistribute it
  14. # and/or modify it under the terms of the Do What The Fuck You Want
  15. # To Public License, Version 2, as published by Sam Hocevar. See
  16. # http://sam.zoy.org/wtfpl/COPYING for more details.
  17. #
  18. internal=0
  19. internal_opt="--internal"
  20. usage() {
  21. printf "Usage: %s host1 ... hostN\n" $1
  22. }
  23. if [ "$1" = "$internal_opt" ]; then
  24. internal=1
  25. shift
  26. fi
  27. TMUXBIN=$(which tmux)
  28. if [ $? != 0 ]; then
  29. printf "Error: %s needs tmux to run, could't find it in \$PATH\n" "$(basename "$0")"
  30. exit 1
  31. fi
  32. if [ -n "$TMUX" ] && [ $internal = 0 ]; then
  33. printf "Error: %s should not be run inside tmux\n" "$(basename "$0")"
  34. exit 1
  35. fi
  36. if [ $# = 0 ]; then
  37. usage
  38. exit 2
  39. fi
  40. if [ $internal = 1 ]; then
  41. for i in $* ; do
  42. $TMUXBIN splitw "ssh $i"
  43. $TMUXBIN select-layout tiled
  44. done
  45. $TMUXBIN set-window-option synchronize-panes on
  46. else
  47. $TMUXBIN new "exec $(readlink -f "$0") "$internal_opt" $*"
  48. fi