summaryrefslogtreecommitdiff
path: root/xsh
blob: 9830df1e68cd556f5186e0bcd08b52fa6b7adf65 (plain)
  1. #!/bin/bash
  2. SCRIPT=$(basename $0)
  3. usage() {
  4. echo "Usage: $SCRIPT [--x] [--verbose] [[su] [{user}@]{host}] [--] [remote command...]"
  5. }
  6. termwrapper() {
  7. PRG=$@
  8. if [ "$V" = 1 ]; then
  9. echo $PRG
  10. sleep 4
  11. fi
  12. if [ -n "$PRG" ]; then
  13. # x-terminal-emulator +sb -sl 500 -e $PRG &
  14. x-terminal-emulator $opts -e $PRG &
  15. # exec x-terminal-emulator $opts -e $PRG &
  16. else
  17. # exec x-terminal-emulator +sb -sl 500 &
  18. x-terminal-emulator $opts &
  19. # exec x-terminal-emulator $opts &
  20. fi
  21. }
  22. # Initial setup
  23. SU=''
  24. X=''
  25. V=''
  26. HOST=''
  27. ssh_opts="-t"
  28. args=''
  29. while [ $# -gt 0 ]; do
  30. case $1 in
  31. su) SU=1;;
  32. --x|-x|x) X=1; ssh_opts="$ssh_opts -X";;
  33. --ssh2|-2) ssh_opts="$ssh_opts -2";;
  34. --verbose|-v) V=1; ssh_opts="$ssh_opts -v";;
  35. --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
  36. --host|-h) HOST=$1;;
  37. -) HOST="localhost";;
  38. --) shift; args="$args$@ "; break;;
  39. -*) usage; exit 1;;
  40. *) args="$args$1 ";;
  41. esac
  42. shift
  43. done
  44. set -- $args
  45. # Make sure we have a hostname
  46. if [ -z "$HOST" ]; then
  47. if [ $# -gt 0 ]; then
  48. HOST=$1
  49. shift
  50. else
  51. HOST="localhost"
  52. fi
  53. fi
  54. # Split program name from its options
  55. if [ $# -gt 0 ]; then
  56. prg_base=$1
  57. shift
  58. prg_opts=$@
  59. fi
  60. case `readlink /etc/alternatives/x-terminal-emulator | xargs basename` in
  61. # rxvt*) opts="+sb -sl 500";;
  62. rxvt*) opts="+sb -sl 500 -ls";;
  63. urxvt*) opts="+sb -sl 500 -ls";;
  64. *xterm) opts="+sb -sl 500 +wc";;
  65. gnome-terminal) opts="";;
  66. gnome-terminal.wrapper) opts="";;
  67. konsole*) opts="--notoolbar";;
  68. *) opts="";;
  69. esac
  70. # Pause for a moment if verbose
  71. if [ "$V" = 1 ]; then
  72. prg_opts="$prg_opts; sleep 4"
  73. fi
  74. if [ -z "$prg_base" ]; then
  75. prg_base='/bin/bash'
  76. fi
  77. prg="$prg_base $prg_opts"
  78. prg_su="echo -n 'Changing to root...: '; su -c \"cd; $prg\""
  79. case "$HOST" in
  80. *@localhost|localhost)
  81. if [ -n "$SU" ]; then
  82. termwrapper $prg_su
  83. else
  84. termwrapper $prg
  85. fi
  86. ;;
  87. *)
  88. if [ -n "$SU" ]; then
  89. termwrapper ssh $ssh_opts $HOST $prg_su
  90. else
  91. termwrapper ssh $ssh_opts $HOST $prg
  92. fi
  93. ;;
  94. esac