Can a Fish script tell what directory it's stored in?

status --current-filename will output the path to the currently executing script.

For more information on the status command, you can run man status or see the documentation at http://fishshell.com/docs/current/commands.html#status


In fish shell,

set DIR (cd (dirname (status -f)); and pwd) 

is an equivalent to the BASH one liner

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

mentioned in Can a Bash script tell what directory it's stored in?.

NOTE: fish shell will cd into that dir and stay there. Bash will cd but it stays contained in subcommand.


File path

To get the full path of the script, use status --current-filename, or set FILE (status --current-filename) to declare a variable.

Directory path

To get the full path to the directory the script is stored in, use dirname (status --current-filename), or set DIR (dirname (status --current-filename)) to declare a variable.

The equivalent to this question is the following:

set DIR (dirname (status --current-filename)) is the equivalent

Tags:

Fish