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