]> git.lyx.org Git - lyx.git/blob - development/MacOSX/inkscape
f1e6ca458fdeadd023eb52b35388b8114e1507d3
[lyx.git] / development / MacOSX / inkscape
1 #!/bin/bash
2
3 # \author Stephan Witt
4 # Full author contact details are available in file CREDITS.
5
6 unset DISPLAY
7
8 # check for file arguments with relative path names
9 # convert them to absolute path names
10 # inkscape on Mac changes the working directory
11 # this invalidates relative path names
12 startinkscape() {
13         inkscape="$1" ; shift
14         pwd=$(pwd)
15         iparams=( "$@" )
16         oparams=()
17         for i in ${!iparams[@]}; do
18                 # echo $i "=>" "${iparams[$i]}"
19                 case "${iparams[$i]}" in
20                 --file=/*|--export-pdf=/*|--export-eps=/*|--export-png=/*|--export-emf=/*|--export-wmf=/*|--export-ps=/*|--export-ps-level=/*|--export-pdf-version=/*)
21                         oparams+=( "${iparams[$i]}" )
22                         ;;
23                 --file=*|--export-pdf=*|--export-eps=*|--export-png=*|--export-emf=*|--export-wmf=*|--export-ps=*|--export-ps-level=*|--export-pdf-version=*)
24                         oparams+=( "${iparams[$i]//=/=${pwd}/}" )
25                         ;;
26                 --without-gui|-z)
27                         # ignore this argument - its provided below anyway
28                         ;;
29                 *)
30                         oparams+=( "${iparams[$i]}" )
31                         ;;
32                 esac
33         done
34         exec "${inkscape}" --without-gui "${oparams[@]}"
35 }
36
37 # try to find the inkscape installation...
38 # at first try the well known location
39 RESDIR="/Applications/Inkscape.app/Contents/Resources"
40 if [ -f "${RESDIR}"/bin/inkscape -a -x "${RESDIR}"/bin/inkscape ]; then
41         startinkscape "${RESDIR}"/bin/inkscape "$@"
42         exit 0
43 fi
44 # this failed... so try PATH expansion to start the inkscape shell wrapper
45 IFS=":" read -ra DIRLIST <<< "${PATH}"
46 for BINDIR in "${DIRLIST[@]}" ; do
47         RESDIR=$(dirname "${BINDIR}")
48         if [ -f "${RESDIR}"/bin/inkscape -a -x "${RESDIR}"/bin/inkscape ]; then
49                 startinkscape "${RESDIR}"/bin/inkscape "$@"
50                 exit 0
51         fi
52 done
53 # report error and exit with failure status
54 exec 1>&2
55 echo Could not find Inkscape binary.
56 exit 1