-#!/usr/bin/env sh
+#!/usr/bin/env bash
-java -cp "./bin/main:./j11lib/*:./resources:./help" jalview.bin.Launcher "${@}"
+if command -v tput 2>&1 >/dev/null; then
+ COLUMNS=$(tput cols) 2>/dev/null
+elif command -v stty 2>&1 >/dev/null; then
+ COLUMNS=$(stty size | cut -d" " -f2) 2>/dev/null
+elif command -v resize 2>&1 >/dev/null; then
+ COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null
+fi
+
+java "-DCONSOLEWIDTH=${COLUMNS}" -cp "./bin/main:./j11lib/*:./resources:./help" jalview.bin.Launcher "${@}"
$SCRIPTPATH = Readlink-f -Link $CMDPATH
$DIR = Split-Path -Path $SCRIPTPATH -Parent
-# set the "-open" parameter if myArg1 is non-zero-length, and not "open" or starts with a "-"
-$OPEN = ""
-if ( $myArg1.length -gt 0 -and ( -not $myArg1.StartsWith("-") ) -and $myArg1 -cne "open" ) {
- $OPEN = "-open"
-}
-
$APPDIR = If ( ( Split-Path -Path $DIR -Leaf ) -eq "bin" ) { Split-Path -Path $DIR -Parent } Else { $DIR }
$JAVAEXE = If ( $myIsWindows ) { "java.exe" } Else { "java" }
$JAVA = Join-Path -Path $APPDIR -ChildPath ( "jre/" + $( If ( $myIsMacOS ) { "Contents/Home/" } Else { "" } ) + "bin/${JAVAEXE}" )
$CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $APPDIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join $( If ( $myIsWindows ) { ";" } Else { ":" } )
+# get console width
+$CONSOLEWIDTH = $Host.UI.RawUI.WindowSize.Width
+
# quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate command not string
$myArgsString = '"' + $($myArgs -join '" "') + '"'
-Invoke-Expression -Command "& `"${JAVA}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${OPEN} ${myArgsString}"
+Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${myArgsString}"
# WINDOWS ONLY (Cygwin or WSL)
# change paths for Cygwin or Windows Subsystem for Linux (WSL)
-if [ "${ISMACOS}" != 1 ]; then # macos doesn't like uname -o, best to avoid
+if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid
if [ "$(uname -o)" = "Cygwin" ]; then
# CYGWIN
echo "When using relative paths in args within Cygwin, please start with './' or '../'" >&2
fi
fi
+# get console width -- three ways to try, just in case
+if command -v tput 2>&1 >/dev/null; then
+ COLUMNS=$(tput cols) 2>/dev/null
+elif command -v stty 2>&1 >/dev/null; then
+ COLUMNS=$(stty size | cut -d" " -f2) 2>/dev/null
+elif command -v resize 2>&1 >/dev/null; then
+ COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null
+fi
+JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" )
+
# Is there a bundled Java? If not just try one in the PATH (do need .exe in WSL)
if [ \! -e "${JAVA}" ]; then
JAVA=$SYSJAVA
echo "Cannot find bundled java, using system ${JAVA} and hoping for the best!" >&2
fi
-# check to see if $1 is set and is not start of other cli args
-OPEN=""
-if [ -n "${ARG1}" -a "${ARG1}" = "${ARG1#-}" -a "${ARG1}" != "open" ]; then
- # first argument exists and does not start with a "-" and is not "open"
- OPEN="-open"
-fi
-
-# don't quote $OPEN (don't want it accidentally mistaken as an empty string arg!)
-"${JAVA}" "${JVMARGS[@]}" -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "${ARGS[@]}"
+"${JAVA}" "${JVMARGS[@]}" -cp "${CLASSPATH}" jalview.bin.Launcher "${ARGS[@]}"