6

When I start fish, I'd like it to print every location it's reading configuration, profiles, and customizations from, so that I can:

  • understand which specific paths I need to backup if I want to preserve my shell experience, and
  • determine where variables and colors are being set

Is this possible, and if so, how?

2 Answers 2

2

How can I ask fish to enumerate the locations it's reading configuration from?

I don't believe this is possible.

Which specific paths I need to backup if I want to preserve my shell experience,

These are all listed in the documentation, but the most important ones are probably your own configuration files:

  • ~/.config/fish/config.fish
  • ~/.config/fish/completions
  • ~/.config/fish/functions

Initialization files

Configuration files are evaluated in the following order:

  • Configuration shipped with fish, which should not be edited, in $__fish_data_dir/config.fish (usually /usr/share/fish/config.fish).

  • Configuration snippets in files ending in .fish, in the directories:

    • $__fish_config_dir/conf.d (by default, ~/.config/fish/conf.d/)

    • $__fish_sysconf_dir/conf.d (by default, /etc/fish/conf.d/)

    • Directories for third-party software vendors to ship their own configuration snippets for their software. Fish searches the directories in the XDG_DATA_DIRS environment variable for a fish/vendor_conf.d directory; if this variable is not defined, the default is usually to search /usr/share/fish/vendor_conf.d and /usr/local/share/fish/vendor_conf.d

      If there are multiple files with the same name in these directories, only the first will be executed. They are executed in order of their filename, sorted (like globs) in a natural order (i.e. "01" sorts before "2").

  • System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to /etc/profile for POSIX-style shells - in $__fish_sysconf_dir (usually /etc/fish/config.fish).

  • User initialization, usually in ~/.config/fish/config.fish (controlled by the XDG_CONFIG_HOME environment variable, and accessible as $__fish_config_dir).

These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above.

This wide search may be confusing. If you are unsure where to put your own customisations, use ~/.config/fish/config.fish.

Note that ~/.config/fish/config.fish is sourced after the snippets. This is so users can copy snippets and override some of their behavior.

Source: Introduction — fish-shell 3.1.2 documentation

Where to put completions

Completions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. Fish automatically searches through any directories in the list variable $fish_complete_path, and any completions defined are automatically loaded when needed. A completion file must have a filename consisting of the name of the command to complete and the suffix '.fish'.

By default, Fish searches the following for completions, using the first available file that it finds:

  • A directory for end-users to keep their own completions, usually ~/.config/fish/completions (controlled by the XDG_CONFIG_HOME environment variable);
  • A directory for systems administrators to install completions for all users on the system, usually /etc/fish/completions;
  • Directories for third-party software vendors to ship their own completions for their software. Fish searches the directories in the XDG_DATA_DIRS environment variable for a fish/vendor_completions.d directory; if this variable is not defined, the default is usually to search /usr/share/fish/vendor_completions.d and /usr/local/share/fish/vendor_completions.d;
  • The completions shipped with fish, usually installed in /usr/share/fish/completions; and
  • Completions automatically generated from the operating system's manuals, usually stored in ~/.local/share/fish/generated_completions.

These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above.

This wide search may be confusing. If you are unsure, your completions probably belong in ~/.config/fish/completions.

Source: Introduction — fish-shell 3.1.2 documentation

Autoloading functions

Functions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. This has some advantages:

  • An autoloaded function becomes available automatically to all running shells.
  • If the function definition is changed, all running shells will automatically reload the altered version.
  • Startup time and memory usage is improved, etc.

When fish needs to load a function, it searches through any directories in the list variable $fish_function_path for a file with a name consisting of the name of the function plus the suffix '.fish' and loads the first it finds.

By default $fish_function_path contains the following:

  • A directory for end-users to keep their own functions, usually ~/.config/fish/functions (controlled by the XDG_CONFIG_HOME environment variable).
  • A directory for systems administrators to install functions for all users on the system, usually /etc/fish/functions (really $__fish_sysconfdir/functions).
  • Directories for third-party software vendors to ship their own functions for their software. Fish searches the directories in the XDG_DATA_DIRS environment variable for a fish/vendor_functions.d directory; if this variable is not defined, the default is usually to search /usr/share/fish/vendor_functions.d and /usr/local/share/fish/vendor_functions.d.
  • The functions shipped with fish, usually installed in /usr/share/fish/functions (really $__fish_data_dir/functions).

These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above.

This wide search may be confusing. If you are unsure, your functions probably belong in ~/.config/fish/functions.

Source: Introduction — fish-shell 3.1.2 documentation

How can I determine where variables and colors are being set

Look in the initialisation files listed above.

1

There's a few things you can try. Using fish 3.1.2.

  1. Set debug level on startup.

https://fishshell.com/docs/current/cmds/fish.html

-d or --debug=CATEGORY_GLOB enables debug output and specifies a glob for matching debug categories (like fish -d). Defaults to empty.

> fish -d 2
<2> fish: exec_path: '/usr/bin/fish', argv[0]: 'fish'
<2> fish: Using compiled in paths:
<2> fish: determine_config_directory_paths() results:
paths.data: /usr/share/fish
paths.sysconf: /etc/fish
paths.doc: /usr/share/doc/fish
paths.bin: /usr/bin
<2> fish: sourcing /usr/share/fish/config.fish
<2> fish: sourcing /etc/fish/config.fish
<2> fish: sourcing /home/x/.config/fish/config.fish
  1. Set fish_trace.

https://fishshell.com/docs/current/index.html#special-variables

fish_trace, if set and not empty, will cause fish to print commands before they execute, similar to set -x in bash.

This command has been helpful to me--

> fish_trace=1 fish -lic 'echo' &| grep "source /home"
++++ source /home/x/.config/fish/conf.d/fzf.fish
+ source /home/x/.config/fish/config.fish
+++++++ source /home/x/.config/fish/functions/bass.fish
...

This launches a new fish instance that's both a login and interactive shell, and grep's only what's being source'd in your home directory.

  1. To determine where variables and colors are being set, use set -S|--show.

https://fishshell.com/docs/current/cmds/set.html#description

-S or --show Shows information about the given variables. If no variable names are given then all variables are shown in sorted order. No other flags can be used with this option. The information shown includes whether or not it is set in each of the local, global, and universal scopes. If it is set in one of those scopes whether or not it is exported is reported. The individual elements are also shown along with the length of each element.

> set -S
...
$fish_color_cancel: not set in local scope
$fish_color_cancel: not set in global scope
$fish_color_cancel: set in universal scope, unexported, with 1 elements
$fish_color_cancel[1]: length=2 value=|-r|
...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .