#!/usr/bin/env bash # Startup script for GMT.app in macOS. # Setup environment and start Terminal. if [ "$1" = "GMT_PROMPT" ]; then _rundir=$(dirname "$0") cd "${_rundir}/.." export BUNDLE_RESOURCES="${PWD}/Resources" cd "${OLDPWD}" # Getting and setting terminal width so wide enough to not wrap the gmt splash screen dim=($(osascript -e 'tell application "Terminal" to get size of front window' | tr ',' ' ')) w=$(echo "${dim[0]} 1.25" | awk '{print int($1*$2)}') osascript << EOF tell application "Terminal" to set size of front window to {$w, ${dim[1]}} EOF export PATH="${BUNDLE_RESOURCES}/@GMT_BINDIR@:${PATH}" export PROJ_LIB="${BUNDLE_RESOURCES}/share/proj" export MAGICK_CONFIGURE_PATH=${BUNDLE_RESOURCES}/lib/GraphicsMagick/config function gmt () { "${BUNDLE_RESOURCES}/@GMT_BINDIR@/gmt" "$@"; } export -f gmt unset DYLD_LIBRARY_PATH gmt echo -e "Note 1: If you want to use GMT outside of this terminal or in scripts, then follow these steps:\n a) export GMTHOME=${BUNDLE_RESOURCES}\n b) add \$GMTHOME/bin to your path\n c) export PROJ_LIB=\$GMTHOME/share/proj\n d) export MAGICK_CONFIGURE_PATH=\$GMTHOME/lib/GraphicsMagick/config" echo -e "Note 2: GMT may use Ghostscript, GraphicsMagick, FFmpeg, and GDAL executables; see\n ${BUNDLE_RESOURCES}/share/Licenses for details.\n" _usershell=$(dscl . -read "/Users/$USER" UserShell) _usershell=${_usershell##* } if [ ${_usershell} = ${_usershell%bash} ]; then # not using bash as default shell echo -e "Warning: your default shell is ${_usershell}. GMT commands completions are only available in BASH.\n" exec ${_usershell} fi # bash: start interactive shell and source gmt completions _temp_bashrc=$(mktemp -t temp_bashrc) cat << EOF > "${_temp_bashrc}" rm -- "${_temp_bashrc}" test -f ~/.bashrc && source ~/.bashrc source "${BUNDLE_RESOURCES}/share/tools/gmt_completion.bash" unset DYLD_LIBRARY_PATH # Assist modern mode scripts by setting a unique session name export GMT_SESSION_NAME=$$ EOF exec /bin/bash --rcfile "${_temp_bashrc}" -i fi # run terminal, set path, and run gmt # http://hintsforums.macworld.com/showthread.php?t=68252 osascript << EOF tell application "System Events" if (count (processes whose bundle identifier is "com.apple.Terminal")) is 0 then tell application "Terminal" do script with command "/bin/bash \"${BASH_SOURCE[0]}\" GMT_PROMPT" in window 0 end tell else tell application "Terminal" do script with command "/bin/bash \"${BASH_SOURCE[0]}\" GMT_PROMPT" end tell end if tell application "Terminal" activate end tell end tell EOF exit 0