grass-xterm-mac 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. # script to emulate an xterm in OSX Terminal.app
  3. #
  4. # -William Kyngesburye
  5. # just in case accidentally called on another system
  6. SYSTEMOSX=`uname -s | grep "Darwin"`
  7. if [ "$SYSTEMOSX" ] ; then
  8. # manually transfer the necessary env vars
  9. TMPSCRIPT="/tmp/grassxterm_$$"
  10. (
  11. cat <<-EOF
  12. #!/bin/sh
  13. DISPLAY="$DISPLAY"
  14. PATH="$PATH"
  15. GIS_LOCK="$GIS_LOCK"
  16. GISRC="$GISRC"
  17. GISBASE="$GISBASE"
  18. GRASS_VERSION="$GRASS_VERSION"
  19. GRASS_PAGER="$GRASS_PAGER"
  20. DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH"
  21. GRASS_HTML_BROWSER="$GRASS_HTML_BROWSER"
  22. GRASS_HTML_BROWSER_MACOSX="$GRASS_HTML_BROWSER_MACOSX"
  23. export DISPLAY PATH GIS_LOCK GISRC GISBASE GRASS_VERSION GRASS_PAGER DYLD_LIBRARY_PATH GRASS_LD_LIBRARY_PATH GRASS_HTML_BROWSER GRASS_HTML_BROWSER_MACOSX
  24. EOF
  25. if [ "$GRASS_ADDON_PATH" ] ; then
  26. echo "GRASS_ADDON_PATH=\"$GRASS_ADDON_PATH\""
  27. echo "export GRASS_ADDON_PATH"
  28. fi
  29. # get command, ignore all other xterm flags
  30. while true ; do
  31. if [ "$1" = "-e" ] ; then break ; fi
  32. shift
  33. done
  34. shift
  35. # and add it to end of script
  36. echo "$@"
  37. ) > "$TMPSCRIPT.sh"
  38. chmod +x "$TMPSCRIPT.sh"
  39. # execute
  40. # save current active app/window, return to it when script finishes.
  41. osascript - <<EOF
  42. --tell application "System Events"
  43. -- set save_app to item 1 of (get name of processes whose frontmost is true)
  44. --end tell
  45. tell application "Terminal"
  46. activate
  47. -- start new window with env/cmd script
  48. do script "$TMPSCRIPT.sh; exit"
  49. tell window 1
  50. -- wait for it to finish
  51. repeat while (processes is not equal to {})
  52. delay 1
  53. end repeat
  54. close
  55. end tell
  56. end tell
  57. --tell application save_app to activate
  58. EOF
  59. rm -f "$TMPSCRIPT.sh"
  60. fi