5
votes

I'm trying to get SBT running using the Fish shell. Below is the equivalent Bash script of what I'm trying to achieve:

java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"

I see in the Fish documentation that $@ in Bash can be replaced with $argv in Fish. But I cannot see what to replace dirname $0 with.

Does anyone know the equivalent script in Fish?

3
I suggest to edit the question to highlight the $0 conversion to (status -f), that is separate that from the java invocation that is specific to your case. That apart, really useful topic!anddam

3 Answers

5
votes

$_ only seems to work directly via the reader/command line, or when the script is sourced, for me.

Maybe this will work for you:

java -Xmx512M -jar (dirname (status -f))/sbt-launch.jar "$argv"      # fish
1
votes

The fish equivalent to this:

java -Xmx512M -jar $(dirname $0)/sbt-launch.jar "$@"     # Bash, et al

is

java -Xmx512M -jar (dirname $_)/sbt-launch.jar "$argv"      # fish
0
votes

Use status Builtin and argv Variable

The fish shell uses the status command to return information about a number of things, including the filename or directory of the currently-running script. It also uses the argv variable rather than Bash's $@. Additionally, fish's variables are lists, so you don't want to quote them the way you do in Bash unless you're trying to treat all the contents of the list as a single string.

Assuming you're running this from a file such as foo.fish, the way to do this would be to include the following line in your script file:

java -Xmx512M -jar (status dirname)/sbt-launch.jar $argv