| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# This script is designed to automatically configure a TeXworks distribution. |
| 4 |
# You can run it by double clicking on it on a Mac. |
| 5 |
# On Linux this behavior is controlled by a preference. See http://askubuntu.com/questions/286621/how-do-i-run-executable-scripts-in-nautilus for details. |
| 6 |
# If prompted, you need to select "Run in Terminal" to see the output. |
| 7 |
|
| 8 |
|
| 9 |
#This trap combination allows the window to linger long enough for the user to |
| 10 |
#inspect the output, but still get closed when all is said and done. |
| 11 |
function quit { |
| 12 |
read -n1 -r -p "Press any key to close window." key |
| 13 |
if $mac; then |
| 14 |
osascript -e 'tell application "Terminal" to close front window' > /dev/null 2>&1 & |
| 15 |
else |
| 16 |
exit |
| 17 |
fi |
| 18 |
} |
| 19 |
|
| 20 |
trap quit EXIT |
| 21 |
|
| 22 |
case "$(uname -s)" in |
| 23 |
Darwin) |
| 24 |
echo 'Mac OS X detected' |
| 25 |
mac=true |
| 26 |
ToolsDir="$HOME/Library/TeXworks" |
| 27 |
;; |
| 28 |
Linux) |
| 29 |
echo 'Linux detected' |
| 30 |
mac=false |
| 31 |
ToolsDir="$HOME/.TeXworks" |
| 32 |
;; |
| 33 |
*) |
| 34 |
echo 'Unsupported OS detected' |
| 35 |
echo "Please configure TeXworks manually" |
| 36 |
exit 1 |
| 37 |
;; |
| 38 |
esac |
| 39 |
|
| 40 |
# Add the typesetting tool |
| 41 |
TOOLS="$ToolsDir/configuration/tools.ini" |
| 42 |
if [ ! -e "$TOOLS" ]; then |
| 43 |
echo "Cannot find TeXworks configuration" |
| 44 |
echo "Please open and close TeXworks and try running this script again" |
| 45 |
echo "If this still does not work, then Add and Remove a dummy typesetting" |
| 46 |
echo " tool from the Preferences dialog." |
| 47 |
exit 1 |
| 48 |
fi |
| 49 |
echo "Adding LuaLaTeX+se Typesetting tool" |
| 50 |
oldTOOLS="$TOOLS.old" |
| 51 |
cp "$TOOLS" "$oldTOOLS" |
| 52 |
last=`grep -E "^\[[0-9]+\]$" "$TOOLS" | tail -1` |
| 53 |
last=${last:1:-1} |
| 54 |
last=$(expr $last + 0) |
| 55 |
(( last++ )) |
| 56 |
last=`printf "%03d" $last` |
| 57 |
last="[$last]" |
| 58 |
echo "" >> "$TOOLS" |
| 59 |
echo "$last" >> "$TOOLS" |
| 60 |
echo "name=LuaLaTeX+se" >> "$TOOLS" |
| 61 |
echo "program=lualatex" >> "$TOOLS" |
| 62 |
echo "arguments=--shell-escape, \$synctexoption, \$fullname" >> "$TOOLS" |
| 63 |
echo "showPdf=true" >> "$TOOLS" |
| 64 |
|
| 65 |
# Add the file filter and cleanup patterns to the configuration |
| 66 |
CONFIG="$ToolsDir/configuration/texworks-config.txt" |
| 67 |
oldCONFIG="$CONFIG.old" |
| 68 |
mv "$CONFIG" "$oldCONFIG" |
| 69 |
cleanup=false |
| 70 |
echo "Adding Gregorio files to Open dialog and Trash Aux Files list" |
| 71 |
while read line; do |
| 72 |
if [[ $line == "# file-open-filter:"* ]]; then |
| 73 |
line=${line:2} |
| 74 |
fi |
| 75 |
if [[ $line == *"Auxiliary files"* ]]; then |
| 76 |
line="${line%?} *.gaux)" |
| 77 |
fi |
| 78 |
if [[ $line == *"All files"* ]]; then |
| 79 |
echo "file-open-filter: Gabc score (*.gabc)" >> "$CONFIG" |
| 80 |
fi |
| 81 |
if [[ $line == "cleanup-patterns:"* ]]; then |
| 82 |
cleanup=true |
| 83 |
else |
| 84 |
if $cleanup; then |
| 85 |
echo "cleanup-patterns: \$jobname.gaux \$jobname.glog *-*_*_*.gtex" >> "$CONFIG" |
| 86 |
cleanup=false |
| 87 |
fi |
| 88 |
fi |
| 89 |
echo "$line" >> "$CONFIG" |
| 90 |
done < "$oldCONFIG" |
| 91 |
|
| 92 |
echo "Configuration Complete" |
| 93 |
exit 0 |