Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the current script's path in Fish shell

Tags:

fish

In bash, we can retrieve the current script's path by $0 variable, so if any script has a dependency resource which is under the same directory as the script directory, we can use it even when we're not executing the script in the script's directory.

How can I retrieve the current script's path in fish shell?

like image 457
Adam Avatar asked Dec 10 '15 07:12

Adam


People also ask

How do you set the path on a fish shell?

It does this by adding the components either to $fish_user_paths or directly to $PATH (if the --path switch is given). It is (by default) safe to use fish_add_path in config. fish, or it can be used once, interactively, and the paths will stay in future because of universal variables.

How do you get off the fish path?

At least by default, PATH is a global variable, which means it is per-session. That means to change something from $PATH, either remove it from where it is added (which is likely outside of fish since it inherits it), or put the set -e call in your ~/. config/fish/config. fish so it will be executed on every start.

How do you find a fish shell?

Pressing Control + S (the pager-toggle-search binding - / in vi-mode) opens up a search menu that you can use to filter the list. Fish provides some general purpose completions: Commands (builtins, functions and regular programs). Shell variable names.

How do you export a variable from fish?

To give a variable to an external command, it needs to be “exported”. Unlike other shells, fish does not have an export command. Instead, a variable is exported via an option to set , either --export or just -x .


1 Answers

status --current-filename is what you're looking for.

Note that this handles both sourced and executed files, while $0 in bash is only for executed files.

like image 160
ridiculous_fish Avatar answered Oct 21 '22 10:10

ridiculous_fish