grass-xterm-mac 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if [ -z "$MANPATH" ] ; then
  30. echo "MANPATH=\"$GISBASE/docs/man:`manpath`\""
  31. else
  32. echo "MANPATH=\"$GISBASE/docs/man:$MANPATH\""
  33. fi
  34. echo "export MANPATH"
  35. # get command, ignore all other xterm flags
  36. while true ; do
  37. if [ "$1" = "-e" ] ; then break ; fi
  38. shift
  39. done
  40. shift
  41. # and add it to end of script
  42. echo "$@"
  43. ) > "$TMPSCRIPT.sh"
  44. chmod +x "$TMPSCRIPT.sh"
  45. # execute
  46. # save current active app/window, return to it when script finishes.
  47. osascript - <<EOF
  48. --tell application "System Events"
  49. -- set save_app to item 1 of (get name of processes whose frontmost is true)
  50. --end tell
  51. tell application "Terminal"
  52. activate
  53. -- start new window with env/cmd script
  54. do script "$TMPSCRIPT.sh; exit"
  55. tell window 1
  56. -- wait for it to finish
  57. repeat while (processes is not equal to {})
  58. delay 1
  59. end repeat
  60. close
  61. end tell
  62. end tell
  63. --tell application save_app to activate
  64. EOF
  65. rm -f "$TMPSCRIPT.sh"
  66. fi