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