summaryrefslogtreecommitdiff
path: root/xsh
blob: 630709c002e6fa2e3e41a9209f71f04333ec641b (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. if [ "$V" = 1 ]; then
  8. echo "$@"
  9. sleep 4
  10. fi
  11. if [ $# -gt 0 ]; then
  12. x-terminal-emulator -e "$@" &
  13. else
  14. x-terminal-emulator &
  15. fi
  16. }
  17. # Initial setup
  18. SU=''
  19. SUDO=''
  20. X=''
  21. V=''
  22. HOST=''
  23. ssh_opts="-t"
  24. while [ $# -gt 0 ]; do
  25. case $1 in
  26. su) SU=1; SUDO=;;
  27. sudo) SUDO=1; SU=;;
  28. --x|-x|x) X=1; ssh_opts="$ssh_opts -X";;
  29. --verbose|-v) V=1; ssh_opts="$ssh_opts -v";;
  30. --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
  31. --) shift; break;;
  32. -*) usage; exit 1;;
  33. @*) HOST=${1#@};;
  34. *@*) HOST=$1;;
  35. *) break;;
  36. esac
  37. shift
  38. done
  39. [ $# -gt 0 ] || set -- /bin/bash
  40. # FIXME: needs shell wrapper (provided by SSH but not in local use)
  41. [ -z "$SU" ] || set -- "echo -n 'Changing to root...: '; su -c \"cd; "$@"\""
  42. [ -z "$SUDO" ] || set -- sudo -i -- "$@"
  43. # Pause for a moment if verbose
  44. # FIXME: needs shell wrapper (provided by SSH but not in local use)
  45. [ -z "$V" ] || set -- "$@"\; sleep 4
  46. [ -z "$HOST" ] || set -- ssh $ssh_opts $HOST "$@"
  47. termwrapper "$@"