The behavior is a bit different from source
, as source runs the content of a script, while fs
runs the script, pipes the output to a file, and then runs the output. So the script being run through fs
must use echo export A=hello
instead of using export A=hello
.
Ideally, we want to use a pure source
. We can do this instead by using the bass plugin. Setup:
fisher install edc/bass
alias fs="bass source"
funcsave fs
The alias stuff is just so we don't have to write the lengthy bass source mycommand
when we want to source mycommand
.
Fish source ("fs
") emulates source
. It executes the output of a command in the current Fish shell.
Example:
We have a file some-command
somewhere in the $PATH, and it contains this:
cd /
If you run this command from the directory /tmp
/tmp $ fs some-command
then your shell will now be in the root directory:
/ $
Just like source
.
TL;DR: source
in Fish shell ignores $PATH, but fs
does not.
Fish's documentation states
fish will search the working directory to resolve relative paths but will not search
PATH
.
This is very unhandy, as being able to source the output of all commands in $PATH
is very useful. fs
solves this.
Install the the bass plugin, and use bass source mycommand
.
Using fisher
fisher install yngvark/fs
Put fs.fish into ~/.config/fish/functions
:
wget https://raw.githubusercontent.com/yngvark/fish-source/main/functions/fs.fish -O ~/.config/fish/functions/fs.fish