3 ###############################
6 # 2023-08-16 Jalview 2.11.3.0 has new command line arguments
7 # Old command line arguments are currently detected and actioned
8 # but are no longer supported and will be removed at a later date.
11 # Jalview -> Help -> Documentation -> Command Line -> introduction and reference
13 # https://www.jalview.org/help/html/features/clarguments.html
14 # for details of the new command line arguments.
16 # Note, in order to run commandline-only calls use
19 # By default, this wrapper executes java -version to determine the JRE version
20 # Set JALVIEW_JRE=j1.8 or JALVIEW_JRE=j11 to skip the version check.
22 # By default, this wrapper does NOT restrict the memory consumption of Jalview.
23 # Set eg. JALVIEW_MAXMEM=1g to set the maximal memory of Jalview's VM
25 # This script is maintained in the Jalview repository in utils/conda/jalview.sh
26 ###############################
28 declare -a ARGS=("${@}")
30 # this function is because there's no readlink -f in Darwin/macOS
31 function readlinkf() {
36 MAX=100 # just in case we end up in a loop
38 while [ "${C}" -lt "${MAX}" -a "${FILE}" != "${PREVFILE}" -a "${FOUND}" -ne 1 ]; do
40 FILE="$(readlink "${FILE}")"
41 if [ -z "${FILE}" ]; then
42 # the readlink is empty means we've arrived at the script, let's canonicalize with pwd
43 FILE="$(cd "$(dirname "${PREVFILE}")" &> /dev/null && pwd -P)"/"$(basename "${PREVFILE}")"
45 elif [ "${FILE#/}" = "${FILE}" ]; then
46 # FILE is not an absolute path link, we need to add the relative path to the previous dir
47 FILE="$(dirname "${PREVFILE}")/${FILE}"
51 if [ "${FOUND}" -ne 1 ]; then
52 echo "Could not determine path to actual file '$(basename "${FINDFILE}")'" >&2
59 if [ "$( uname -s )" = "Darwin" ]; then
63 # check for headless mode
68 for RAWARG in "${@}"; do
71 --headless|--output|--image|--structureimage)
74 --help|--help-*|--version|-h)
85 if [ "${HELP}" = 1 ]; then
86 # --help takes precedence
89 elif [ "${GUI}" = 1 ]; then
90 # --gui takes precedence over --headless
97 # set vars for being inside the macos App Bundle
98 if [ "${ISMACOS}" = 1 ]; then
100 DIR="$(dirname "$(readlinkf "$0")")"
101 if [ -e "${DIR}/jalview_logo.png" ]; then
102 JVMARGS=( "${JVMARGS[@]}" "-Xdock:icon=${DIR}/jalview_logo.png" )
106 DIR="$(dirname "$(readlink -f "$0")")"
109 if [ "${HEADLESS}" = 1 ]; then
110 # not setting java.awt.headless in java invocation of running jalview due to problem with Jmol
111 if [ "${HELP}" = 1 ]; then
112 JVMARGS=( "${JVMARGS[@]}" "-Djava.awt.headless=true" )
114 # this suppresses the Java icon appearing in the macOS Dock
115 if [ "${ISMACOS}" = 1 ]; then
116 JVMARGS=( "${JVMARGS[@]}" "-Dapple.awt.UIElement=true" )
122 # decide which jalview jar to launch - either 'j11' or 'j1.8'
123 if [[ "$JALVIEW_JRE" != "j11" && "$JALVIEW_JRE" != "j1.8" ]]; then
125 # if java 8 is installed we pick the j1.8 build
126 if [[ $( "${JAVA}" -version 2>&1 | grep '"1.8' ) != "" ]]; then
131 JARPATH="${DIR}/jalview-all-${JALVIEW_JRE}.jar"
133 # check if memory maximum is set and if so forward to java-based jalview call
134 if [ \! -z "$JALVIEW_MAXMEM" ]; then
135 JVMARGS=( "${JVMARGS[@]}" "-Xmx${JALVIEW_MAXMEM}" )
138 # WINDOWS ONLY (Cygwin or WSL)
139 # change paths for Cygwin or Windows Subsystem for Linux (WSL)
140 if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid
141 if [ "$(uname -o)" = "Cygwin" ]; then
143 JARPATH="$(cygpath -pw "${JARPATH}")"
144 # now for some arg paths fun. only translating paths starting with './', '../', '/' or '~'
146 for ARG in "${@}"; do
147 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
148 ARGS=( "${ARGS[@]}" "$(cygpath -aw "${ARG}")" )
150 ARGS=( "${ARGS[@]}" "${ARG}" )
153 elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then
155 JARPATH="$(wslpath -aw "${JARPATH}")"
157 for ARG in "${@}"; do
158 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
159 # annoyingly wslpath does not work if the file doesn't exist!
160 ARGBASENAME="$(basename "${ARG}")"
161 ARGDIRNAME="$(dirname "${ARG}")"
162 ARGS=( "${ARGS[@]}" "$(wslpath -aw "${ARGDIRNAME}")\\${ARGBASENAME}" )
164 ARGS=( "${ARGS[@]}" "${ARG}" )
171 # get console width -- three ways to try, just in case
172 if command -v tput 2>&1 >/dev/null; then
173 COLUMNS=$(tput cols) 2>/dev/null
174 elif command -v stty 2>&1 >/dev/null; then
175 COLUMNS=$(stty size | cut -d" " -f2) 2>/dev/null
176 elif command -v resize 2>&1 >/dev/null; then
177 COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null
179 JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" )
181 function quotearray() {
183 for VAL in "${@}"; do
184 if [ \! "$QUOTEDVALS" = "" ]; then
185 QUOTEDVALS="${QUOTEDVALS} "
187 QUOTEDVALS="${QUOTEDVALS}\"${VAL}\""
192 JVMARGSSTR=$(quotearray "${JVMARGS[@]}")
193 ARGSSTR=$(quotearray "${ARGS[@]}")
195 if [ "${DEBUG}" = 1 ]; then
196 echo Shell running: \""${JAVA}"\" ${JVMARGSSTR} -jar \""${JARPATH}"\" ${ARGSSTR}
199 "${JAVA}" "${JVMARGS[@]}" -jar "${JARPATH}" "${ARGS[@]}"