Search code examples
linuxshelldockerdebianfish

Using fish shell function within a script


I have a bunch of shell scripts, the first being one which installs the popular Fish shell. Once this step completes I copy a functions/ directory to the appropriate location. I then want to use the spin function to call each shell script and display a spinner, while each script is executing. However after I get passed the initial installation of Fish and configuration I am unable to use the functions i.e. spin <command> results in command not found.

NOTE This is happening within an ephemeral docker container for testing.

Any pointers or help with this, would be greatly appreciated.


Solution

  • If you want to run fish functions from outside fish, use fish -c with a fish command line as one string.

    For example, this fails...

    env __fish_pwd
    

    ...but this works:

    env fish -c __fish_pwd
    

    This is because env runs executables, not fish functions. I assume spin is like this too.