summaryrefslogtreecommitdiff
path: root/xsh
blob: 67b8edfe0f5a3691f79faa4b72b390446beb2404 (plain)
  1. #!/bin/bash
  2. SCRIPT=$(basename $0)
  3. usage() {
  4. echo "Usage: $SCRIPT [--x] [--verbose] [su|sudo] [[{user}]@{host}] [[--] 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. SUDO=''
  25. X=''
  26. V=''
  27. HOST=''
  28. ssh_opts="-t"
  29. while [ $# -gt 0 ]; do
  30. case $1 in
  31. su) SU=1; SUDO=;;
  32. sudo) SUDO=1; SU=;;
  33. --x|-x|x) X=1; ssh_opts="$ssh_opts -X";;
  34. --ssh2|-2) ssh_opts="$ssh_opts -2";;
  35. --verbose|-v) V=1; ssh_opts="$ssh_opts -v";;
  36. --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
  37. --) shift; break;;
  38. -*) usage; exit 1;;
  39. *@*|@*) HOST=$1;;
  40. *) break;;
  41. esac
  42. shift
  43. done
  44. # Split program name from its options
  45. if [ $# -gt 0 ]; then
  46. prg_base=$1
  47. shift
  48. prg_opts=$@
  49. fi
  50. case `readlink /etc/alternatives/x-terminal-emulator | xargs basename` in
  51. # rxvt*) opts="+sb -sl 500";;
  52. rxvt*) opts="+sb -sl 500 -ls";;
  53. urxvt*) opts="+sb -sl 500 -ls";;
  54. *xterm) opts="+sb -sl 500 +wc";;
  55. gnome-terminal) opts="";;
  56. gnome-terminal.wrapper) opts="";;
  57. konsole*) opts="--notoolbar";;
  58. *) opts="";;
  59. esac
  60. # Pause for a moment if verbose
  61. if [ "$V" = 1 ]; then
  62. prg_opts="$prg_opts; sleep 4"
  63. fi
  64. if [ -z "$prg_base" ]; then
  65. prg_base='/bin/bash'
  66. fi
  67. prg="$prg_base $prg_opts"
  68. prg_su="echo -n 'Changing to root...: '; su -c \"cd; $prg\""
  69. prg_sudo="sudo -i -- $prg"
  70. case "$HOST" in
  71. '')
  72. if [ -n "$SU" ]; then
  73. termwrapper $prg_su
  74. elif [ -n "$SUDO" ]; then
  75. termwrapper $prg_sudo
  76. else
  77. termwrapper $prg
  78. fi
  79. ;;
  80. @*)
  81. HOST=$(echo "$HOST" | sed 's/^@//')
  82. ;;&
  83. *)
  84. if [ -n "$SU" ]; then
  85. termwrapper ssh $ssh_opts $HOST $prg_su
  86. elif [ -n "$SUDO" ]; then
  87. termwrapper ssh $ssh_opts $HOST $prg_sudo
  88. else
  89. termwrapper ssh $ssh_opts $HOST $prg
  90. fi
  91. ;;
  92. esac