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=("${@}")
31 # this function is because there's no readlink -f in Darwin/macOS
32 function readlinkf() {
37 MAX=100 # just in case we end up in a loop
39 while [ "${C}" -lt "${MAX}" -a "${FILE}" != "${PREVFILE}" -a "${FOUND}" -ne 1 ]; do
41 FILE="$(readlink "${FILE}")"
42 if [ -z "${FILE}" ]; then
43 # the readlink is empty means we've arrived at the script, let's canonicalize with pwd
44 FILE="$(cd "$(dirname "${PREVFILE}")" &> /dev/null && pwd -P)"/"$(basename "${PREVFILE}")"
46 elif [ "${FILE#/}" = "${FILE}" ]; then
47 # FILE is not an absolute path link, we need to add the relative path to the previous dir
48 FILE="$(dirname "${PREVFILE}")/${FILE}"
52 if [ "${FOUND}" -ne 1 ]; then
53 echo "Could not determine path to actual file '$(basename "${FINDFILE}")'" >&2
60 if [ "$( uname -s )" = "Darwin" ]; then
64 # check for headless mode
69 for RAWARG in "${@}"; do
72 --headless|--output|--image|--structureimage)
75 --help|--help-*|--version)
86 if [ "${HELP}" = 1 ]; then
87 # --help takes precedence
90 elif [ "${GUI}" = 1 ]; then
91 # --gui takes precedence over --headless
98 # set vars for being inside the macos App Bundle
99 if [ "${ISMACOS}" = 1 ]; then
101 DIR="$(dirname "$(readlinkf "$0")")"
102 JVMARGS=( "${JVMARGS[@]}" "-Xdock:icon=${DIR}/jalview_logo.png" )
105 DIR="$(dirname "$(readlink -f "$0")")"
108 if [ "${HEADLESS}" = 1 ]; then
109 # this suppresses the Java icon appearing in the macOS Dock and maybe other things in other OSes
110 JVMARGS=( "${JVMARGS[@]}" "-Djava.awt.headless=true" )
115 # decide which jalview jar to launch - either 'j11' or 'j1.8'
116 if [[ "$JALVIEW_JRE" != "j11" && "$JALVIEW_JRE" != "j1.8" ]]; then
118 # if java 8 is installed we pick the j1.8 build
119 if [[ $( "${JAVA}" -version 2>&1 | grep '"1.8' ) != "" ]]; then
124 JARPATH="${DIR}/jalview-all-${JALVIEW_JRE}.jar"
126 # check if memory maximum is set and if so forward to java-based jalview call
127 if [ \! -z "$JALVIEW_MAXMEM" ]; then
128 JVMARGS=( "${JVMARGS[@]}" "-Xmx${JALVIEW_MAXMEM}" )
131 # WINDOWS ONLY (Cygwin or WSL)
132 # change paths for Cygwin or Windows Subsystem for Linux (WSL)
133 if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid
134 if [ "$(uname -o)" = "Cygwin" ]; then
136 JARPATH="$(cygpath -pw "${JARPATH}")"
137 # now for some arg paths fun. only translating paths starting with './', '../', '/' or '~'
139 for ARG in "${@}"; do
140 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
141 ARGS=( "${ARGS[@]}" "$(cygpath -aw "${ARG}")" )
143 ARGS=( "${ARGS[@]}" "${ARG}" )
146 elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then
148 JARPATH="$(wslpath -aw "${JARPATH}")"
150 for ARG in "${@}"; do
151 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
152 # annoyingly wslpath does not work if the file doesn't exist!
153 ARGBASENAME="$(basename "${ARG}")"
154 ARGDIRNAME="$(dirname "${ARG}")"
155 ARGS=( "${ARGS[@]}" "$(wslpath -aw "${ARGDIRNAME}")\\${ARGBASENAME}" )
157 ARGS=( "${ARGS[@]}" "${ARG}" )
164 # get console width -- three ways to try, just in case
165 if command -v tput 2>&1 >/dev/null; then
166 COLUMNS=$(tput cols) 2>/dev/null
167 elif command -v stty 2>&1 >/dev/null; then
168 COLUMNS=$(stty size | cut -d" " -f2) 2>/dev/null
169 elif command -v resize 2>&1 >/dev/null; then
170 COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null
172 JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" )
174 if [ "${DEBUG}" = 1 ]; then
175 echo Shell running: "${JAVA}" "${JVMARGS[@]}" -jar \""${JARPATH}"\" "${ARGS[@]}"
178 "${JAVA}" "${JVMARGS[@]}" -jar "${JARPATH}" "${ARGS[@]}"