Admin/MacOS/App1/script
author wenzelm
Mon, 19 Sep 2011 12:58:52 +0200
changeset 45866 272e8e4e4fc7
parent 45819 b455e4f42c04
child 45980 bf7a8906c0cb
permissions -rw-r--r--
imitate Apple in setting initial shell PATH -- especially relevant for MacTeX, MacPorts etc.;
     1 #!/bin/bash
     2 #
     3 # Author: Makarius
     4 #
     5 # Isabelle application wrapper
     6 
     7 THIS="$(cd "$(dirname "$0")"; pwd)"
     8 THIS_APP="$(cd "$THIS/../.."; pwd)"
     9 SUPER_APP="$(cd "$THIS/../../.."; pwd)"
    10 
    11 
    12 # sane environment defaults
    13 
    14 cd "$HOME"
    15 if [ -x /usr/libexec/path_helper ]; then
    16   eval $(/usr/libexec/path_helper -s)
    17 fi
    18 
    19 [ -z "$LANG" ] && export LANG=en_US.UTF-8
    20 
    21 
    22 # settings support
    23 
    24 function choosefrom ()
    25 {
    26   local RESULT=""
    27   local FILE=""
    28 
    29   for FILE in "$@"
    30   do
    31     [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
    32   done
    33 
    34   [ -z "$RESULT" ] && RESULT="$FILE"
    35   echo "$RESULT"
    36 }
    37 
    38 
    39 # Isabelle
    40 
    41 ISABELLE_TOOL="$(choosefrom \
    42   "$THIS/Isabelle/bin/isabelle" \
    43   "$SUPER_APP/Isabelle/bin/isabelle" \
    44   "$HOME/bin/isabelle" \
    45   isabelle)"
    46 
    47 
    48 # Proof General / Emacs
    49 
    50 PROOFGENERAL_EMACS="$(choosefrom \
    51   "$THIS/Emacs.app/Contents/MacOS/Emacs" \
    52   "$SUPER_APP/Emacs.app/Contents/MacOS/Emacs" \
    53   /Applications/Emacs.app/Contents/MacOS/Emacs \
    54   "")"
    55 
    56 declare -a EMACS_OPTIONS=()
    57 if [ -n "$PROOFGENERAL_EMACS" ]; then
    58   EMACS_OPTIONS=(-p "$PROOFGENERAL_EMACS")
    59 fi
    60 
    61 
    62 # enforce fonts
    63 
    64 if [ ! -f "$HOME/Library/Fonts/STIXGeneral.ttf" -a ! -f "$HOME/Library/Fonts/STIXGeneral.otf" ]
    65 then
    66   cp -f "$THIS/STIXv1.0.0/Fonts"/STIXGeneral* "$HOME/Library/Fonts/"
    67   sleep 3
    68 fi
    69 
    70 EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="-x"
    71 EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="true"
    72 
    73 
    74 # run interface with error feedback
    75 
    76 ISABELLE_INTERFACE_CHOICE="$("$ISABELLE_TOOL" getenv -b ISABELLE_INTERFACE_CHOICE)"
    77 if [ "$ISABELLE_INTERFACE_CHOICE" != emacs -a "$ISABELLE_INTERFACE_CHOICE" != jedit ]
    78 then
    79   declare -a CHOICE
    80   CHOICE=($("$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" dropdown \
    81     --title Isabelle \
    82     --text "Which Isabelle interface?" \
    83     --items "Emacs / Proof General" "Isabelle/jEdit PIDE" \
    84     --button2 "OK, do not ask again" --button1 "OK"))
    85   if [ "${CHOICE[1]}" = 0 ]; then
    86     ISABELLE_INTERFACE_CHOICE=emacs
    87   else
    88     ISABELLE_INTERFACE_CHOICE=jedit
    89   fi
    90   if [ "${CHOICE[0]}" = 2 ]; then
    91     ISABELLE_HOME_USER="$("$ISABELLE_TOOL" getenv -b ISABELLE_HOME_USER)"
    92     mkdir -p "$ISABELLE_HOME_USER/etc"
    93     ( echo; echo "ISABELLE_INTERFACE_CHOICE=$ISABELLE_INTERFACE_CHOICE"; ) \
    94       >> "$ISABELLE_HOME_USER/etc/settings"
    95     "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" ok-msgbox \
    96       --title Isabelle \
    97       --text Note \
    98       --informative-text "ISABELLE_INTERFACE_CHOICE stored in $ISABELLE_HOME_USER/etc/settings" \
    99       --no-cancel
   100   fi
   101 fi
   102 
   103 OUTPUT="/tmp/isabelle$$.out"
   104 
   105 if [ "$ISABELLE_INTERFACE_CHOICE" = emacs ]; then
   106   ( "$ISABELLE_TOOL" emacs "${EMACS_OPTIONS[@]}" "$@" ) > "$OUTPUT" 2>&1
   107   RC=$?
   108 else
   109   rm -f "$OUTPUT" && touch "$OUTPUT"
   110   "$ISABELLE_TOOL" jedit "$@"
   111   RC=$?
   112 fi
   113 
   114 if [ "$RC" != 0 ]; then
   115   echo >> "$OUTPUT"
   116   echo "Return code: $RC" >> "$OUTPUT"
   117 fi
   118 
   119 if [ $(stat -f "%z" "$OUTPUT") != 0 ]; then
   120   "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" textbox \
   121     --title "Isabelle" \
   122     --informative-text "Isabelle output" \
   123     --text-from-file "$OUTPUT" \
   124     --button1 "OK"
   125 fi
   126 
   127 rm -f "$OUTPUT"
   128 
   129 exit "$RC"