docs/docs/3.0/faq.html
fish shell | Documentation | Tutorial | Design | Commands | FAQ | License
Frequently asked questions
.bashrc?set -Ux (exported universal variables) seem to work?- as a shortcut for cd -?Use the set command:
set-xkeyvalueset-ekey
Edit the file ~/.config/fish/config.fish, creating it if it does not exist (Note the leading period).
The prompt is the output of the fish_prompt function. Put it in ~/.config/fish/functions/fish_prompt.fish. For example, a simple prompt is:
functionfish\_promptset\_color$fish\_color\_cwdecho-n(prompt\_pwd)set\_colornormalecho-n' \> 'end
You can also use the Web configuration tool, fish_config, to preview and choose from a gallery of sample prompts.
Type some part of the command, and then hit the ↑ or ↓ arrow keys to navigate through history matches.
fish uses parentheses for subcommands. For example:
foriin(ls)echo$iend
Unlike other shells, fish splits command substitutions only on newlines, not spaces or tabs or the characters in $IFS.
That means if you run
echox(printf'%s 'abc)x
It will print xa b c x. But if you do
echox(printf'%s\n'abc)x
it will print xax xbx xcx.
In the overwhelming majority of cases, splitting on spaces is unwanted, so this is an improvement.
However sometimes, especially with pkg-config and related tools, splitting on spaces is needed.
In these cases use string split " " like:
g++example\_01.cpp(pkg-config--cflags--libsgtk+-2.0|stringsplit" ")
Use the $status variable. This replaces the $? variable used in some other shells.
somecommandiftest$status-eq7echo"That's my lucky number!"end
If you are just interested in success or failure, you can run the command directly as the if-condition:
ifsomecommandecho"Command succeeded"elseecho"Command failed"end
See the documentation for test and if for more information.
SOME_VAR=1 command produces an error: Unknown command "SOME_VAR=1".
Use the env command.
env SOME_VAR=1 command
You can also declare a local variable in a block:
beginset-lxSOME\_VAR1commandend
set -Ux (exported universal variables) seem to work?A global variable of the same name already exists.
Environment variables such as EDITOR or TZ can be set universally using set -Ux. However, if there is an environment variable already set before fish starts (such as by login scripts or system administrators), it is imported into fish as a global variable. The variable scopes are searched from the "inside out", which means that local variables are checked first, followed by global variables, and finally universal variables.
This means that the global value takes precedence over the universal value.
To avoid this problem, consider changing the setting which fish inherits. If this is not possible, add a statement to your user initialization file (usually ~/.config/fish/config.fish):
set-gxEDITORvim
Use the web configuration tool, fish_config, or alter the fish_color family of environment variables.
Use the fish_update_completions command.
If fish is unable to locate a command with a given name, and it starts with '.', '/' or '~', fish will test if a directory of that name exists. If it does, it is implicitly assumed that you want to change working directory. For example, the fastest way to switch to your home directory is to simply press ~ and enter.
The open command uses the MIME type database and the .desktop files used by Gnome and KDE to identify filetypes and default actions. If at least one of these environments is installed, but the open command is not working, this probably means that the relevant files are installed in a non-standard location. Consider asking for more help.
If you installed fish manually (e.g. by compiling it, not by using a package manager), you first need to add fish to the list of shells by executing the following command (assuming you installed fish in /usr/local):
echo/usr/local/bin/fish|sudotee-a/etc/shells
If you installed a prepackaged version of fish, the package manager should have already done this for you.
In order to change your default shell, type:
chsh-s/usr/local/bin/fish
You may need to adjust the above path to e.g. /usr/bin/fish. Use the command which fish if you are unsure of where fish is installed.
Unfortunately, there is no way to make the changes take effect at once. You will need to log out and back in again.
Quick answer:
Run the following command in fish:
functionfish\_title;end;funcsavefish\_title
Problem solved!
The long answer:
Fish is trying to set the titlebar message of your terminal. While screen itself supports this feature, your terminal does not. Unfortunately, when the underlying terminal doesn't support setting the titlebar, screen simply passes through the escape codes and text to the underlying terminal instead of ignoring them. It is impossible to detect and resolve this problem from inside fish since fish has no way of knowing what the underlying terminal type is. For now, the only way to fix this is to unset the titlebar message, as suggested above.
Note that fish has a default titlebar message, which will be used if the fish_title function is undefined. So simply unsetting the fish_title function will not work.
Change the value of the variable fish_greeting or create a fish_greeting function. For example, to remove the greeting use:
setfish\_greeting
Because history substitution is an awkward interface that was invented before interactive line editing was even possible. Fish drops it in favor of perfecting the interactive history recall interface. Switching requires a small change of habits: if you want to modify an old line/word, first recall it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then type "sudo ".
Fish history recall is very simple yet effective:
As in any modern shell, the Up arrow, ↑ recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like.
Alt- ↑ recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like.
See documentation for more details about line editing in fish.
- as a shortcut for cd -?In fish versions prior to 2.5.0 it was possible to create a function named - that would do cd -. Changes in the 2.5.0 release included several bug fixes that enforce the rule that a bare hyphen is not a valid function (or variable) name. However, you can achieve the same effect via an abbreviation:
abbr-a---'cd -'
Should you wish to uninstall fish, first ensure fish is not set as your shell. Run chsh -s /bin/bash if you are not sure.
Next, do the following (assuming fish was installed to /usr/local):
rm-Rf/usr/local/etc/fish/usr/local/share/fish~/.config/fishrm/usr/local/share/man/man1/fish\*.1cd/usr/local/binrm-ffishfish\_indent
Fish reserves the Unicode private-use character range from U+F600 thru U+F73F for internal use. Any attempt to feed characters in that range to fish will result in them being replaced by the Unicode "replacement character" U+FFFD. This includes both interactive input as well as any file read by fish (but not programs run by fish).
The fish user community extends fish in unique and useful ways via scripts that aren't always appropriate for bundling with the fish package. Typically because they solve a niche problem unlikely to appeal to a broad audience. You can find those extensions, including prompts, themes and useful functions, in various third-party repositories. These include:
This is not an exhaustive list and the fish project has no opinion regarding the merits of the repositories listed above or the scripts found therein.