summaryrefslogtreecommitdiff
path: root/xsh
blob: 5164c38c24983a0a4af4a313b504df8103fef711 (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 -e $PRG &
  14. else
  15. x-terminal-emulator &
  16. fi
  17. }
  18. # Initial setup
  19. SU=''
  20. SUDO=''
  21. X=''
  22. V=''
  23. HOST=''
  24. ssh_opts="-t"
  25. while [ $# -gt 0 ]; do
  26. case $1 in
  27. su) SU=1; SUDO=;;
  28. sudo) SUDO=1; SU=;;
  29. --x|-x|x) X=1; ssh_opts="$ssh_opts -X";;
  30. --verbose|-v) V=1; ssh_opts="$ssh_opts -v";;
  31. --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
  32. --) shift; break;;
  33. -*) usage; exit 1;;
  34. @*) HOST=${1#@};;
  35. *@*) HOST=$1;;
  36. *) break;;
  37. esac
  38. shift
  39. done
  40. [ $# -gt 0 ] || set -- /bin/bash
  41. # FIXME: needs shell wrapper (provided by SSH but not in local use)
  42. [ -z "$SU" ] || set -- "echo -n 'Changing to root...: '; su -c \"cd; "$@"\""
  43. [ -z "$SUDO" ] || set -- sudo -i -- "$@"
  44. # Split program name from its options
  45. if [ $# -gt 0 ]; then
  46. prg_base=$1
  47. shift
  48. prg_opts=$@
  49. fi
  50. # Pause for a moment if verbose
  51. if [ "$V" = 1 ]; then
  52. prg_opts="$prg_opts; sleep 4"
  53. fi
  54. prg="$prg_base $prg_opts"
  55. case "$HOST" in
  56. '')
  57. termwrapper $prg
  58. ;;
  59. *)
  60. termwrapper ssh $ssh_opts $HOST $prg
  61. ;;
  62. esac