This page describes the Spacefish API for creating plugins and tweaking Spacefish's behavior.

Spacefish uses the SPACEFISH_ prefix for variables and the __sf_ prefix for functions to avoid namespace collisions. All sections, including custom ones, are required to use the __sf_ prefix before their name to load correctly.

Example section

Below is an example of a typical section for Spacefish. Pay attention to a few critical aspects:

  • Variables used for configuration should start with SPACEFISH_.
  • The section's name should start with __sf_.
  • Only show the section as is needed (only in directories containing specific files, when a specific command is available, etc).

Take a look at Contribution guidelines for further details.

# Foobar
# Foobar is a supa-dupa cool tool for making you development easier.
# Link: https://www.foobar.xyz

# __sf_ prefix before section's name is required!
# Otherwise this section won't be loaded.
function __sf_section_foobar -d "Show foobar status"
  # ------------------------------------------------------------------------------
  # Configuration
  # ------------------------------------------------------------------------------

  __sf_util_set_default SPACEFISH_FOOBAR_SHOW true
  __sf_util_set_default SPACEFISH_FOOBAR_SYMBOL "🍷 "
  __sf_util_set_default SPACEFISH_FOOBAR_COLOR white

  # ------------------------------------------------------------------------------
  # Section
  # ------------------------------------------------------------------------------

  # If SPACEFISH_FOOBAR_SHOW is false, don't show the foobar section
  [ $SPACEFISH_FOOBAR_SHOW = false ]; and return

  # If the foobar command doesn't exist, don't show the foobar section
  type -q foobar; or return

  # Here some of the various expressions that can be tested
  # The full list can be found here:
  # https://fishshell.com/docs/current/commands.html#test
  type -q command          # test that a command exists
  test -e /path/to/file    # test that a file exists
  test -d /path/to/dir     # test that a directory exists
  test operand1 = operand2 # that for two equal strings
  test -n "$variable"      # test that a variable exists

  # Use `set -l` to define local variables to avoid populating
  # the global namespace
  set -l foobar_status

  if test "$SOME_CONDITION" = "true"
    set foobar_status (foobar baz)
    set foobar_status (foobar foo)

  # Display the foobar section
  __sf_lib_section \


An environment variable that defines the version of currently running Spacefish prompt. Can be used for issue reporting or debugging purposes.

Accessible to any program or script running in a current shell session.


#> 0.1.0

__sf_lib_section <color> [prefix] <content> [suffix]

This function prints out the prompt section prefixed with prefix, suffixed with suffix and content formatted to display in color. The Bold style is applied by default.

prefix, suffix and content can contain set_color to set an additional foreground color, background color or other formatting styles. Read more about set_color in the set_color - set the terminal color section of the Fish Shell documentation.

If SPACEFISH_PROMPT_PREFIXES_SHOW is false or if the section is the first to appear in the prompt, then prefix will be omitted.

If SPACEFISH_PROMPT_SUFFIXES_SHOW is false, then suffix will be omitted.

Both prefix and suffix are optional. They are equal to empty strings by default.


  1. color Required — The color used when displaying the content. Can be any of the valid basic colors or can be any valid RGB hex code.
  2. prefix Optional — The prefix shown before content. Usually, it's the value of SPACEFISH_*_PREFIX.
  3. content Required — The content of the section. Can be any valid value or the result of command execution.
  4. suffix Optional — The suffix shown after content. Usually, it's the value of SPACEFISH_*_SUFFIX.


# Display the prompt section with a prefix and suffix
# Backslash is used to escape the line endings
__sf_lib_section \

# Display prompt section without prefix and suffix
__sf_lib_section $color $SPACEFISH_CHAR_SYMBOL

__sf_util_set_default <variable_name> <value>

This utility function is used to define a default value for a variable while allowing it to be overwritten by a user's personal configuration files (e.g. setting it in their config.fish)


  1. variable_name Required — the name of the configuration variable.
  2. value Required — the value to be assigned by default.


# Preassign a value to `SPACEFISH_CHAR_SYMBOL`

# Assign a value if one doesn't already exist
__sf_util_set_default SPACEFISH_CHAR_SYMBOL ■
__sf_util_set_default SPACEFISH_RUBY_SYMBOL 💎

# The original value assigned is used
#> ❯

#> 💎


This utility returns the current branch name if the current working directory is a Git repository, and will return nothing if it's not.


# Return if the current working directory is not a Git repository
[ -z (__sf_util_git_branch) ]; and return

# Print the Git branch name of the current working directory
echo (__sf_util_git_branch)
#> master

results matching ""

    No results matching ""