Admin/MacOS/App1/script
author berghofe
Mon, 23 Jul 2012 18:52:10 +0200
changeset 48453 2421ff8c57a5
parent 45095 bf7a8906c0cb
child 48631 81c81f13d152
permissions -rw-r--r--
set_vcs now derives prefix from fully qualified procedure / function name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     1
#!/bin/bash
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     2
#
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     3
# Author: Makarius
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     4
#
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     5
# Isabelle application wrapper
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     6
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
     7
THIS="$(cd "$(dirname "$0")"; pwd)"
29149
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
     8
THIS_APP="$(cd "$THIS/../.."; pwd)"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
     9
SUPER_APP="$(cd "$THIS/../../.."; pwd)"
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    10
29173
c14c9a41f1ac PATH: /opt/local/bin is back again (required for latex etc.);
wenzelm
parents: 29149
diff changeset
    11
c14c9a41f1ac PATH: /opt/local/bin is back again (required for latex etc.);
wenzelm
parents: 29149
diff changeset
    12
# sane environment defaults
41643
10b0d338d99e default UTF-8 locale, to work with funny base directory (e.g. Chinese);
wenzelm
parents: 41642
diff changeset
    13
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    14
cd "$HOME"
44985
272e8e4e4fc7 imitate Apple in setting initial shell PATH -- especially relevant for MacTeX, MacPorts etc.;
wenzelm
parents: 44948
diff changeset
    15
if [ -x /usr/libexec/path_helper ]; then
272e8e4e4fc7 imitate Apple in setting initial shell PATH -- especially relevant for MacTeX, MacPorts etc.;
wenzelm
parents: 44948
diff changeset
    16
  eval $(/usr/libexec/path_helper -s)
272e8e4e4fc7 imitate Apple in setting initial shell PATH -- especially relevant for MacTeX, MacPorts etc.;
wenzelm
parents: 44948
diff changeset
    17
fi
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    18
41643
10b0d338d99e default UTF-8 locale, to work with funny base directory (e.g. Chinese);
wenzelm
parents: 41642
diff changeset
    19
[ -z "$LANG" ] && export LANG=en_US.UTF-8
10b0d338d99e default UTF-8 locale, to work with funny base directory (e.g. Chinese);
wenzelm
parents: 41642
diff changeset
    20
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    21
29149
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    22
# settings support
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    23
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    24
function choosefrom ()
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    25
{
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    26
  local RESULT=""
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    27
  local FILE=""
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    28
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    29
  for FILE in "$@"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    30
  do
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    31
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    32
  done
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    33
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    34
  [ -z "$RESULT" ] && RESULT="$FILE"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    35
  echo "$RESULT"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    36
}
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    37
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    38
29149
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    39
# Isabelle
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    40
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    41
ISABELLE_TOOL="$(choosefrom \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    42
  "$THIS/Isabelle/bin/isabelle" \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    43
  "$SUPER_APP/Isabelle/bin/isabelle" \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    44
  "$HOME/bin/isabelle" \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    45
  isabelle)"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    46
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    47
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    48
# Proof General / Emacs
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    49
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    50
PROOFGENERAL_EMACS="$(choosefrom \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    51
  "$THIS/Emacs.app/Contents/MacOS/Emacs" \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    52
  "$SUPER_APP/Emacs.app/Contents/MacOS/Emacs" \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    53
  /Applications/Emacs.app/Contents/MacOS/Emacs \
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    54
  "")"
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    55
33912
a5e6e849a0d8 allow spaces within PROOFGENERAL_EMACS;
wenzelm
parents: 31924
diff changeset
    56
declare -a EMACS_OPTIONS=()
29149
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    57
if [ -n "$PROOFGENERAL_EMACS" ]; then
33912
a5e6e849a0d8 allow spaces within PROOFGENERAL_EMACS;
wenzelm
parents: 31924
diff changeset
    58
  EMACS_OPTIONS=(-p "$PROOFGENERAL_EMACS")
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    59
fi
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    60
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    61
41642
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    62
# enforce fonts
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    63
41644
a6c45c8d52fc enforce STIXGeneral, which is preferred by PG 4.1;
wenzelm
parents: 41643
diff changeset
    64
if [ ! -f "$HOME/Library/Fonts/STIXGeneral.ttf" -a ! -f "$HOME/Library/Fonts/STIXGeneral.otf" ]
41642
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    65
then
41644
a6c45c8d52fc enforce STIXGeneral, which is preferred by PG 4.1;
wenzelm
parents: 41643
diff changeset
    66
  cp -f "$THIS/STIXv1.0.0/Fonts"/STIXGeneral* "$HOME/Library/Fonts/"
41642
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    67
  sleep 3
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    68
fi
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    69
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    70
EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="-x"
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    71
EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="true"
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    72
b9442d9ce7f5 enforce fonts;
wenzelm
parents: 41610
diff changeset
    73
29149
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
    74
# run interface with error feedback
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
    75
44881
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    76
ISABELLE_INTERFACE_CHOICE="$("$ISABELLE_TOOL" getenv -b ISABELLE_INTERFACE_CHOICE)"
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    77
if [ "$ISABELLE_INTERFACE_CHOICE" != emacs -a "$ISABELLE_INTERFACE_CHOICE" != jedit ]
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    78
then
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    79
  declare -a CHOICE
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    80
  CHOICE=($("$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" dropdown \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    81
    --title Isabelle \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    82
    --text "Which Isabelle interface?" \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    83
    --items "Emacs / Proof General" "Isabelle/jEdit PIDE" \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    84
    --button2 "OK, do not ask again" --button1 "OK"))
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    85
  if [ "${CHOICE[1]}" = 0 ]; then
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    86
    ISABELLE_INTERFACE_CHOICE=emacs
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    87
  else
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    88
    ISABELLE_INTERFACE_CHOICE=jedit
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    89
  fi
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    90
  if [ "${CHOICE[0]}" = 2 ]; then
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    91
    ISABELLE_HOME_USER="$("$ISABELLE_TOOL" getenv -b ISABELLE_HOME_USER)"
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    92
    mkdir -p "$ISABELLE_HOME_USER/etc"
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    93
    ( echo; echo "ISABELLE_INTERFACE_CHOICE=$ISABELLE_INTERFACE_CHOICE"; ) \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    94
      >> "$ISABELLE_HOME_USER/etc/settings"
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    95
    "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" ok-msgbox \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    96
      --title Isabelle \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    97
      --text Note \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    98
      --informative-text "ISABELLE_INTERFACE_CHOICE stored in $ISABELLE_HOME_USER/etc/settings" \
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
    99
      --no-cancel
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
   100
  fi
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
   101
fi
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
   102
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   103
OUTPUT="/tmp/isabelle$$.out"
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   104
44881
ca2f585d1ebe persistent ISABELLE_INTERFACE_CHOICE;
wenzelm
parents: 44880
diff changeset
   105
if [ "$ISABELLE_INTERFACE_CHOICE" = emacs ]; then
44880
9fb612890ad9 explicit choice of interface;
wenzelm
parents: 41644
diff changeset
   106
  ( "$ISABELLE_TOOL" emacs "${EMACS_OPTIONS[@]}" "$@" ) > "$OUTPUT" 2>&1
9fb612890ad9 explicit choice of interface;
wenzelm
parents: 41644
diff changeset
   107
  RC=$?
9fb612890ad9 explicit choice of interface;
wenzelm
parents: 41644
diff changeset
   108
else
45095
bf7a8906c0cb retain output, which is required for non-existent JRE, for example (cf. b455e4f42c04);
wenzelm
parents: 44985
diff changeset
   109
  ( "$ISABELLE_TOOL" jedit "$@" ) > "$OUTPUT" 2>&1
44880
9fb612890ad9 explicit choice of interface;
wenzelm
parents: 41644
diff changeset
   110
  RC=$?
9fb612890ad9 explicit choice of interface;
wenzelm
parents: 41644
diff changeset
   111
fi
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   112
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   113
if [ "$RC" != 0 ]; then
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   114
  echo >> "$OUTPUT"
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   115
  echo "Return code: $RC" >> "$OUTPUT"
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   116
fi
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   117
29149
eae45c2a6811 more sophisticated MacOS interface script (mostly for Carbon Emacs);
wenzelm
parents: 29136
diff changeset
   118
if [ $(stat -f "%z" "$OUTPUT") != 0 ]; then
29136
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   119
  "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" textbox \
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   120
    --title "Isabelle" \
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   121
    --informative-text "Isabelle output" \
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   122
    --text-from-file "$OUTPUT" \
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   123
    --button1 "OK"
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   124
fi
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   125
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   126
rm -f "$OUTPUT"
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   127
de5b29c25af9 basic setup for MacOS application bundle;
wenzelm
parents:
diff changeset
   128
exit "$RC"