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
88 if [ "${HELP}" = 1 ]; then
89 # --help takes precedence
92 elif [ "${GUI}" = 1 ]; then
93 # --gui takes precedence over --headless
100 # set vars for being inside the macos App Bundle
101 if [ "${ISMACOS}" = 1 ]; then
103 DIR="$(dirname "$(readlinkf "$0")")"
104 JVMARGS=( "${JVMARGS[@]}" "-Xdock:icon=${DIR}/jalview_logo.png" )
107 DIR="$(dirname "$(readlink -f "$0")")"
110 if [ "${HEADLESS}" = 1 ]; then
111 # this suppresses the Java icon appearing in the macOS Dock and maybe other things in other OSes
112 JVMARGS=( "${JVMARGS[@]}" "-Djava.awt.headless=true" )
117 # decide which jalview jar to launch - either 'j11' or 'j1.8'
118 if [[ "$JALVIEW_JRE" != "j11" && "$JALVIEW_JRE" != "j1.8" ]]; then
120 # if java 8 is installed we pick the j1.8 build
121 if [[ $( "${JAVA}" -version 2>&1 | grep '"1.8' ) != "" ]]; then
126 JARPATH="${DIR}/jalview-all-${JALVIEW_JRE}.jar"
128 # check if memory maximum is set and if so forward to java-based jalview call
129 if [ \! -z "$JALVIEW_MAXMEM" ]; then
130 JVMARGS=( "${JVMARGS[@]}" "-Xmx${JALVIEW_MAXMEM}" )
133 # WINDOWS ONLY (Cygwin or WSL)
134 # change paths for Cygwin or Windows Subsystem for Linux (WSL)
135 if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid
136 if [ "$(uname -o)" = "Cygwin" ]; then
138 JARPATH="$(cygpath -pw "${JARPATH}")"
139 # now for some arg paths fun. only translating paths starting with './', '../', '/' or '~'
141 for ARG in "${@}"; do
142 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
143 ARGS=( "${ARGS[@]}" "$(cygpath -aw "${ARG}")" )
145 ARGS=( "${ARGS[@]}" "${ARG}" )
148 elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then
150 JARPATH="$(wslpath -aw "${JARPATH}")"
152 for ARG in "${@}"; do
153 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
154 # annoyingly wslpath does not work if the file doesn't exist!
155 ARGBASENAME="$(basename "${ARG}")"
156 ARGDIRNAME="$(dirname "${ARG}")"
157 ARGS=( "${ARGS[@]}" "$(wslpath -aw "${ARGDIRNAME}")\\${ARGBASENAME}" )
159 ARGS=( "${ARGS[@]}" "${ARG}" )
166 # get console width -- three ways to try, just in case
167 if command -v tput 2>&1 >/dev/null; then
168 COLUMNS=$(tput cols) 2>/dev/null
169 elif command -v stty 2>&1 >/dev/null; then
170 COLUMNS=$(stty size | cut -d" " -f2) 2>/dev/null
171 elif command -v resize 2>&1 >/dev/null; then
172 COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null
174 JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" )
176 if [ "${DEBUG}" = 1 ]; then
177 echo Shell running: "${JAVA}" "${JVMARGS[@]}" -jar \""${JARPATH}"\" jalview.bin.Launcher "${ARGS[@]}"
180 "${JAVA}" "${JVMARGS[@]}" -jar "${JARPATH}" jalview.bin.Launcher "${ARGS[@]}"