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