'\" t
.\" Man page generated from reStructuredText
.\" by the Docutils 0.23 manpage writer.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "FISH-DOC" "1" "Sep 07, 2026" "4.9" "fish-shell"
.sp
This is the documentation for \fBfish\fP, the \fBf\fPriendly \fBi\fPnteractive \fBsh\fPell.
.sp
A shell is a program that helps you operate your computer by starting other programs. fish offers a command\-line interface focused on usability and interactive use.
.sp
Some of the special features of fish are:
.INDENT 0.0
.IP \(bu 2
\fBExtensive UI\fP: Syntax highlighting \%<#\:syntax-highlighting>, Autosuggestions \%<#\:autosuggestions>, tab completion \%<#\:tab-completion> and selection lists that can be navigated and filtered.
.IP \(bu 2
\fBNo configuration needed\fP: fish is designed to be ready to use immediately, without requiring extensive configuration.
.IP \(bu 2
\fBEasy scripting\fP: New functions \%<#\:syntax-function> can be added on the fly. The syntax is easy to learn and use.
.UNINDENT
.sp
This page explains how to install and set up fish and where to get more information.
.SH WHERE TO GO?
.sp
If this is your first time using fish, see the tutorial \%<>\&.
.sp
If you are already familiar with other shells like bash and want to see the scripting differences, see Fish For Bash Users \%<>\&.
.sp
For an overview of fish\(aqs scripting language, see The Fish Language \%<>\&. If it would be useful in a script file, it\(aqs here.
.sp
For information on using fish interactively, see Interactive use \%<>\&. If it\(aqs about key presses, syntax highlighting or anything else that needs an interactive terminal session, look here.
.sp
If you need to install fish first, read on, the rest of this document will tell you how to get, install and configure fish.
.SH SETUP
.sp
This section describes how to install, uninstall, start, and exit \fBfish\fP\&. It also explains how to make fish the default shell.
.SS Installation
.sp
Up\-to\-date instructions for installing the latest version of fish are on the fish homepage \%\&.
.sp
To install the development version of fish, see the instructions on the project\(aqs GitHub page \%\&.
.SS Starting and Exiting
.sp
Once fish has been installed, open a terminal. If fish is not the default shell:
.INDENT 0.0
.IP \(bu 2
Type \fBfish\fP to start a shell:
.INDENT 2.0
.INDENT 3.5
.sp
.EX
> fish
.EE
.UNINDENT
.UNINDENT
.IP \(bu 2
Type \fBexit\fP to end the session:
.INDENT 2.0
.INDENT 3.5
.sp
.EX
> exit
.EE
.UNINDENT
.UNINDENT
.UNINDENT
.SS Default Shell
.sp
There are multiple ways to switch to fish (or any other shell) as your default.
.sp
The simplest method is to set your terminal emulator (e.g. GNOME Terminal, Apple\(aqs Terminal.app, or Konsole) to start fish directly. See its configuration and set the program to start to \fB/usr/local/bin/fish\fP (the exact path depends on how you installed fish).
.sp
Alternatively, you can set fish as your login shell so that it will be started by all terminal logins, including SSH.
.sp
\fBWarning:\fP
.INDENT 0.0
.INDENT 3.5
Setting fish as your login shell may cause issues, such as an incorrect \fBPATH\fP \%<#\:envvar-PATH>\&. Some operating systems, including a number of Linux distributions, require the login shell to be Bourne\-compatible and to read configuration from \fB/etc/profile\fP\&. fish may not be suitable as a login shell on these systems.
.UNINDENT
.UNINDENT
.sp
To change your login shell to fish:
.INDENT 0.0
.IP 1. 3
Add the shell to \fB/etc/shells\fP with:
.INDENT 3.0
.INDENT 3.5
.sp
.EX
> command \-v fish | sudo tee \-a /etc/shells
.EE
.UNINDENT
.UNINDENT
.IP 2. 3
Change your default shell with:
.INDENT 3.0
.INDENT 3.5
.sp
.EX
> chsh \-s \(dq$(command \-v fish)\(dq
.EE
.UNINDENT
.UNINDENT
.UNINDENT
.sp
To change it back to another shell, substitute \fBfish\fP with \fBbash\fP, \fBtcsh\fP or \fBzsh\fP as appropriate in the above command.
.SS Uninstalling
.sp
For uninstalling fish: see FAQ: Uninstalling fish \%<#\:faq-uninstalling>\&.
.SS Shebang Line
.sp
Because shell scripts are written in many different languages, they need to carry information about which interpreter should be used to execute them. For this, they are expected to have a first line, the shebang line, which names the interpreter executable.
.sp
A script written in \fBbash\fP would need a first line like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
#!/bin/bash
.EE
.UNINDENT
.UNINDENT
.sp
When the shell tells the kernel to execute the file, it will use the interpreter \fB/bin/bash\fP\&.
.sp
For a script written in another language, just replace \fB/bin/bash\fP with the interpreter for that language. For example: \fB/usr/bin/python\fP for a python script, or \fB/usr/local/bin/fish\fP for a fish script, if that is where you have them installed.
.sp
If you want to share your script with others, you might want to use \fBenv\fP to allow for the interpreter to be installed in other locations. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
#!/usr/bin/env fish
echo Hello from fish $version
.EE
.UNINDENT
.UNINDENT
.sp
This will call \fBenv\fP, which then goes through \fBPATH\fP \%<#\:envvar-PATH> to find a program called \(dqfish\(dq. This makes it work, whether fish is installed in (for example) \fB/usr/local/bin/fish\fP, \fB/usr/bin/fish\fP, or \fB~/.local/bin/fish\fP, as long as that directory is in \fBPATH\fP \%<#\:envvar-PATH>\&.
.sp
The shebang line is only used when scripts are executed without specifying the interpreter. For functions inside fish or when executing a script with \fBfish /path/to/script\fP, a shebang is not required (but it doesn\(aqt hurt!).
.sp
When executing files without an interpreter, fish, like other shells, tries your system shell, typically \fB/bin/sh\fP\&. This is needed because some scripts are shipped without a shebang line.
.SH CONFIGURATION
.sp
To store configuration write it to a file called \fB~/.config/fish/config.fish\fP\&.
.sp
\fB\&.fish\fP scripts in \fB~/.config/fish/conf.d/\fP are also automatically executed before \fBconfig.fish\fP\&.
.sp
These files are read on the startup of every shell, whether interactive and/or if they\(aqre login shells. Use \fBstatus \-\-is\-interactive\fP and \fBstatus \-\-is\-login\fP to do things only in interactive/login shells, respectively.
.sp
This is the short version; for a full explanation, like for sysadmins or integration for developers of other software, see Configuration files \%<#\:configuration>\&.
.sp
If you want to see what you changed over fish\(aqs defaults, see fish_delta \%<>\&.
.SS Examples:
.sp
To add \fB~/linux/bin\fP to PATH variable when using a login shell, add this to \fB~/.config/fish/config.fish\fP file:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if status \-\-is\-login
set \-gx PATH $PATH ~/linux/bin
end
.EE
.UNINDENT
.UNINDENT
.sp
This is just an example; using fish_add_path \%<> e.g. \fBfish_add_path ~/linux/bin\fP which only adds the path if it isn\(aqt included yet is easier.
.sp
To run commands on exit, use an event handler \%<#\:event> that is triggered by the exit of the shell:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function on_exit \-\-on\-event fish_exit
echo fish is now exiting
end
.EE
.UNINDENT
.UNINDENT
.SH RESOURCES
.INDENT 0.0
.IP \(bu 2
The GitHub page \%
.IP \(bu 2
The official Matrix room \%
.IP \(bu 2
The official mailing list at fish\-users@lists.sourceforge.net \%
.UNINDENT
.sp
If you have an improvement for fish, you can submit it via the GitHub page.
.SH OTHER HELP PAGES
.SS Frequently asked questions
.SS What is the equivalent to this thing from bash (or other shells)?
.sp
See fish for bash users \%<>
.SS How do I set or clear an environment variable?
.sp
Use the set \%<> command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-x key value # typically set \-gx key value
set \-e key
.EE
.UNINDENT
.UNINDENT
.sp
Since fish 3.1 you can set an environment variable for one command using the \fBkey=value some command\fP syntax, like in other shells. The two lines below behave identically \- unlike other shells, fish will output \fBvalue\fP both times:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
key=value echo $key
begin; set \-lx key value; echo $key; end
.EE
.UNINDENT
.UNINDENT
.sp
Note that \(dqexported\(dq is not a scope \%<#\:variables-scope>, but an additional bit of state. A variable can be global and exported or local and exported or even universal and exported. Typically it makes sense to make an exported variable global.
.SS How do I check whether a variable is defined?
.sp
Use \fBset \-q var\fP\&. For example, \fBif set \-q var; echo variable defined; end\fP\&. To check multiple variables you can combine with \fBand\fP and \fBor\fP like so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if set \-q var1; or set \-q var2
echo either variable defined
end
.EE
.UNINDENT
.UNINDENT
.sp
Keep in mind that a defined variable could also be empty, either by having no elements (if set like \fBset var\fP) or only empty elements (if set like \fBset var \(dq\(dq\fP). Read on for how to deal with those.
.SS How do I check whether a variable is not empty?
.sp
Use \fBstring length \-q \-\- $var\fP\&. For example, \fBif string length \-q \-\- $var; echo not empty; end\fP\&. Note that \fBstring length\fP will interpret a list of multiple variables as a disjunction (meaning any/or):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if string length \-q \-\- $var1 $var2 $var3
echo at least one of these variables is not empty
end
.EE
.UNINDENT
.UNINDENT
.sp
Alternatively, use \fBtest \-n \(dq$var\(dq\fP, but remember that \fBthe variable must be double\-quoted\fP\&. For example, \fBif test \-n \(dq$var\(dq; echo not empty; end\fP\&. The \fBtest\fP command provides its own and (\-a) and or (\-o):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-n \(dq$var1\(dq \-o \-n \(dq$var2\(dq \-o \-n \(dq$var3\(dq
echo at least one of these variables is not empty
end
.EE
.UNINDENT
.UNINDENT
.sp
If you want to know if a variable has \fIno elements\fP, use \fBset \-q var[1]\fP\&.
.SS Why doesn\(aqt \fBset \-Ux\fP (exported universal variables) seem to work?
.sp
A global variable of the same name already exists.
.sp
Environment variables such as \fBEDITOR\fP or \fBTZ\fP can be set universally using \fBset \-Ux\fP\&. 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 \%<#\:variables-scope> are searched from the \(dqinside out\(dq, which
means that local variables are checked first, followed by global variables, and finally universal
variables.
.sp
This means that the global value takes precedence over the universal value.
.sp
To avoid this problem, consider changing the setting which fish inherits. If this is not possible,
add a statement to your configuration file \%<#\:configuration> (usually
\fB~/.config/fish/config.fish\fP):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-gx EDITOR vim
.EE
.UNINDENT
.UNINDENT
.SS How do I run a command every login? What\(aqs fish\(aqs equivalent to .bashrc or .profile?
.sp
Edit the file \fB~/.config/fish/config.fish\fP [1], creating it if it does not exist (Note the leading period).
.sp
Unlike .bashrc and .profile, this file is always read, even in non\-interactive or login shells.
.sp
To do something only in interactive shells, check \fBstatus is\-interactive\fP like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if status is\-interactive
# use the coolbeans theme
fish_config theme choose coolbeans
end
.EE
.UNINDENT
.UNINDENT
.IP [1] 5
The \(dq~/.config\(dq part of this can be set via $XDG_CONFIG_HOME, that\(aqs just the default.
.SS How do I set my prompt?
.sp
The prompt is the output of the \fBfish_prompt\fP function. Put it in \fB~/.config/fish/functions/fish_prompt.fish\fP\&. For example, a simple prompt is:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
set_color $fish_color_cwd
echo \-n (prompt_pwd)
set_color \-\-reset
echo \-n \(aq > \(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
You can also use the Web configuration tool, fish_config \%<>, to preview and choose from a gallery of sample prompts.
.sp
Or you can use fish_config from the commandline:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish_config prompt show
# displays all the prompts fish ships with
> fish_config prompt choose disco
# loads the disco prompt in the current shell
> fish_config prompt save
# makes the change permanent
.EE
.UNINDENT
.UNINDENT
.sp
If you want to modify your existing prompt, you can use funced \%<> and funcsave \%<> like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ funced fish_prompt
# This opens up your editor (set in $EDITOR).
# Modify the function,
# save the file and repeat to your liking.
# Once you are happy with it:
>_ funcsave fish_prompt
.EE
.UNINDENT
.UNINDENT
.sp
This also applies to fish_right_prompt \%<> and fish_mode_prompt \%<>\&.
.SS Why does my prompt show a \fB[I]\fP?
.sp
That\(aqs the fish_mode_prompt \%<>\&. It is displayed by default when you\(aqve activated vi mode using \fBfish_vi_key_bindings\fP\&.
.sp
If you haven\(aqt activated vi mode on purpose, you might have installed a third\-party theme or plugin that does it.
.sp
If you want to change or disable this display, modify the \fBfish_mode_prompt\fP function, for instance via funced \%<>\&.
.SS How do I customize my syntax highlighting colors?
.sp
Use the web configuration tool started by fish_config \%<>,
or alter the fish_color family of environment variables \%<#\:variables-color>,
or use the fish_config theme \%<> subcommand, like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish_config theme show
# to demonstrate all the colorschemes
> fish_config theme choose coolbeans
# to load the \(dqcoolbeans\(dq theme
.EE
.UNINDENT
.UNINDENT
.SS How do I change the greeting message?
.sp
Change the value of the variable \fBfish_greeting\fP or create a fish_greeting \%<> function. For example, to remove the greeting use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-U fish_greeting
.EE
.UNINDENT
.UNINDENT
.sp
Or if you prefer not to use a universal variable, use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_greeting
.EE
.UNINDENT
.UNINDENT
.sp
in config.fish \%<#\:configuration>\&.
.SS How do I run a command from history?
.sp
Type some part of the command, and then hit the \fBup\fP (\fB↑\fP) or \fBdown\fP (\fB↓\fP) arrow keys to navigate through history matches, or press \fBctrl\fP\-\fBr\fP to open the history in a searchable pager. In this pager you can press \fBctrl\fP\-\fBr\fP or \fBctrl\fP\-\fBs\fP to move to older or younger history respectively.
.sp
Additional default key bindings include \fBctrl\fP\-\fBp\fP (up) and \fBctrl\fP\-\fBn\fP (down). See Searchable command history \%<#\:history-search> for more information.
.SS Why doesn\(aqt history substitution (\(dq!$\(dq etc.) work?
.sp
Because history substitution is an awkward interface that was invented before interactive line editing was even possible. Instead of adding this pseudo\-syntax, fish opts for nice history searching and recall features. Switching requires a small change of habits: if you want to modify an old line/word, first recall it, then edit.
.sp
As a special case, most of the time history substitution is used as \fBsudo !!\fP\&. In that case press \fBalt\fP\-\fBs\fP, and it will recall your last commandline with \fBsudo\fP prefixed (or toggle a \fBsudo\fP prefix on the current commandline if there is anything).
.sp
In general, fish\(aqs history recall works like this:
.INDENT 0.0
.IP \(bu 2
Like other shells, the Up arrow, \fBup\fP recalls whole lines, starting from the last executed line. So instead of typing \fB!!\fP, you would hit the up\-arrow.
.IP \(bu 2
If the line you want is far back in the history, type any part of the line and then press Up one or more times. This will filter the recalled lines to ones that include this text, and you will get to the line you want much faster. This replaces \(dq!vi\(dq, \(dq!?bar.c\(dq and the like. If you want to see more context, you can press \fBctrl\-r\fP to open the history in the pager.
.IP \(bu 2
\fBalt\-up\fP recalls individual arguments, starting from the last argument in the last executed line. This can be used instead of \(dq!$\(dq.
.UNINDENT
.sp
See documentation \%<#\:editor> for more details about line editing in fish.
.sp
That being said, you can use Abbreviations \%<#\:abbreviations> to implement history substitution. Here\(aqs \fB!!\fP only:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function last_history_item; echo $history[1]; end
abbr \-a !! \-\-position anywhere \-\-function last_history_item
.EE
.UNINDENT
.UNINDENT
.sp
Run this and \fB!!\fP will be replaced with the last history entry, anywhere on the commandline. Put it into config.fish \%<#\:configuration> to keep it.
.SS How do I run a subcommand? The backtick doesn\(aqt work!
.sp
\fBfish\fP uses parentheses for subcommands. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in (ls)
echo $i
end
.EE
.UNINDENT
.UNINDENT
.sp
It also supports the familiar \fB$()\fP syntax, even in quotes. Backticks are not supported because they are discouraged even in POSIX shells. They nest poorly and are hard to tell from single quotes (\fB\(aq\(aq\fP).
.SS My command (pkg\-config) gives its output as a single long string?
.sp
Unlike other shells, fish splits command substitutions only on newlines, not spaces or tabs or the characters in $IFS.
.sp
That means if you run
.INDENT 0.0
.INDENT 3.5
.sp
.EX
count (printf \(aq%s \(aq a b c)
.EE
.UNINDENT
.UNINDENT
.sp
It will print \fB1\fP, because the \(dqa b c \(dq is used in one piece. But if you do
.INDENT 0.0
.INDENT 3.5
.sp
.EX
count (printf \(aq%s\en\(aq a b c)
.EE
.UNINDENT
.UNINDENT
.sp
it will print \fB3\fP, because it gave \fBcount\fP the arguments \(dqa\(dq, \(dqb\(dq and \(dqc\(dq separately.
.sp
In the overwhelming majority of cases, splitting on spaces is unwanted, so this is an improvement. This is why you hear about problems with filenames with spaces, after all.
.sp
However sometimes, especially with \fBpkg\-config\fP and related tools, splitting on spaces is needed.
.sp
In these cases use \fBstring split \-n \(dq \(dq\fP like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
g++ example_01.cpp (pkg\-config \-\-cflags \-\-libs gtk+\-2.0 | string split \-n \(dq \(dq)
.EE
.UNINDENT
.UNINDENT
.sp
The \fB\-n\fP is so empty elements are removed like POSIX shells would do.
.SS How do I get the exit status of a command?
.sp
Use the \fB$status\fP variable. This replaces the \fB$?\fP variable used in other shells.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
somecommand
if test $status \-eq 7
echo \(dqThat\(aqs my lucky number!\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
If you are only interested in success or failure, you can run the command directly as the if\-condition:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if somecommand
echo \(dqCommand succeeded\(dq
else
echo \(dqCommand failed\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
Or if you just want to do one command in case the first succeeded or failed, use \fBand\fP or \fBor\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
somecommand
or someothercommand
.EE
.UNINDENT
.UNINDENT
.sp
See the Conditions \%<#\:syntax-conditional> and the documentation for test \%<> and if \%<> for more information.
.SS My command prints \(dqNo matches for wildcard\(dq but works in bash
.sp
In short: quote \%<#\:quotes> or escape \%<#\:escapes> the wildcard:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
scp user@ip:/dir/\(dqstring\-*\(dq
.EE
.UNINDENT
.UNINDENT
.sp
When fish sees an unquoted \fB*\fP, it performs wildcard expansion \%<#\:expand-wildcard>\&. That means it tries to match filenames to the given string.
.sp
If the wildcard doesn\(aqt match any files, fish prints an error instead of running the command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo *this*does*not*exist
fish: No matches for wildcard \(aq*this*does*not*exist\(aq. See \(gahelp expand\(ga.
echo *this*does*not*exist
^
.EE
.UNINDENT
.UNINDENT
.sp
Now, bash also tries to match files in this case, but when it doesn\(aqt find a match, it passes along the literal wildcard string instead.
.sp
That means that commands like the above
.INDENT 0.0
.INDENT 3.5
.sp
.EX
scp user@ip:/dir/string\-*
.EE
.UNINDENT
.UNINDENT
.sp
or
.INDENT 0.0
.INDENT 3.5
.sp
.EX
apt install postgres\-*
.EE
.UNINDENT
.UNINDENT
.sp
appear to work, because most of the time the string doesn\(aqt match and so it passes along the \fBstring\-*\fP, which is then interpreted by the receiving program.
.sp
But it also means that these commands can stop working at any moment once a matching file is encountered (because it has been created or the command is executed in a different working directory), and to deal with that bash needs workarounds like
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for f in ./*.mpg; do
# We need to test if the file really exists because
# the wildcard might have failed to match.
test \-f \(dq$f\(dq || continue
mympgviewer \(dq$f\(dq
done
.EE
.UNINDENT
.UNINDENT
.sp
(from \%)
.sp
For these reasons, fish does not do this, and instead expects asterisks to be quoted or escaped if they aren\(aqt supposed to be expanded.
.sp
This is similar to bash\(aqs \(dqfailglob\(dq option.
.SS Why won\(aqt SSH/SCP/rsync connect properly when fish is my login shell?
.sp
This problem may show up as messages like \(dq\fBReceived message too long\fP\(dq, \(dq\fBopen terminal
failed: not a terminal\fP\(dq, \(dq\fBBad packet length\fP\(dq, or \(dq\fBConnection refused\fP\(dq with strange output
in \fBssh_exchange_identification\fP messages in the debug log.
.sp
This usually happens because fish reads the user configuration file \%<#\:configuration> (\fB~/.config/fish/config.fish\fP) \fIalways\fP,
whether it\(aqs in an interactive or login or non\-interactive or non\-login shell.
.sp
This simplifies matters, but it also means when config.fish generates output, it will do that even in non\-interactive shells like the one ssh/scp/rsync start when they connect.
.sp
Anything in config.fish that produces output should be guarded with \fBstatus is\-interactive\fP (or \fBstatus is\-login\fP if you prefer):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if status is\-interactive
...
end
.EE
.UNINDENT
.UNINDENT
.sp
The same applies for example when you start \fBtmux\fP in config.fish without guards, which will cause a message like \fBsessions should be nested with care, unset $TMUX to force\fP\&.
.SS I\(aqm getting weird graphical glitches (a staircase effect, ghost characters, cursor in the wrong position,...)?
.sp
In a terminal, the application running inside it and the terminal itself need to agree on the width of characters in order to handle cursor movement.
.sp
This is more important to fish than other shells because features like syntax highlighting and autosuggestions are implemented by moving the cursor.
.sp
Sometimes, there is disagreement on the width. There are numerous causes and fixes for this:
.INDENT 0.0
.IP \(bu 2
It is possible the character is too new for your system to know \- in this case you need to refrain from using it.
.IP \(bu 2
fish or your terminal might not know about the character or handle it wrong \- in this case fish or your terminal needs to be fixed, or you need to update to a fixed version.
.IP \(bu 2
The character has an \(dqambiguous\(dq width and fish thinks that means a width of X while your terminal thinks it\(aqs Y. In this case you either need to change your terminal\(aqs configuration or set $fish_ambiguous_width to the correct value.
.IP \(bu 2
The character is an emoji and your system only supports Unicode 8. In this case set $fish_emoji_width to 1.
.UNINDENT
.sp
This also means that a few things are unsupportable:
.INDENT 0.0
.IP \(bu 2
Non\-monospace fonts \- there is \fIno way\fP for fish to figure out what width a specific character has as it has no influence on the terminal\(aqs font rendering.
.IP \(bu 2
Different widths for multiple ambiguous width characters \- there is no way for fish to know which width you assign to each character.
.UNINDENT
.SS fish does not work in a specific terminal
.sp
The terminal might not meet all of fish\(aqs requirements \%<>\&.
Please report this to your terminal\(aqs and to fish\(aqs issue tracker.
.SS Uninstalling fish
.sp
If you want to uninstall fish, first make sure fish is not set as your shell. Run \fBchsh \-s /bin/bash\fP if you are not sure.
.sp
If you installed it with a package manager, use that package manager\(aqs uninstall function. If you built fish yourself, assuming you installed it to /usr/local, do this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
rm \-Rf /usr/local/etc/fish /usr/local/share/fish ~/.config/fish
rm /usr/local/share/man/man1/fish*.1
cd /usr/local/bin
rm \-f fish fish_indent
.EE
.UNINDENT
.UNINDENT
.SS Interactive use
.sp
fish prides itself on being really nice to use interactively. That\(aqs down to a few features we\(aqll explain in the next few sections.
.sp
fish is used by giving commands in the fish language, see The fish Language \%<> for information on that.
.SS Help
.sp
fish has an extensive help system. Use the help \%<> command to obtain help on a specific subject or command. For instance, writing \fBhelp syntax\fP displays the syntax section \%<#\:syntax> of this documentation.
.sp
fish also has man pages for its commands, and translates the help pages to man pages. For example, \fBman set\fP will show the documentation for \fBset\fP as a man page.
.sp
Help on a specific builtin can also be obtained with the \fB\-h\fP parameter. For instance, to obtain help on the fg \%<> builtin, either type \fBfg \-h\fP or \fBhelp fg\fP\&.
.sp
The main page can be viewed via \fBhelp index\fP (or just \fBhelp\fP) or \fBman fish\-doc\fP\&. The tutorial can be viewed with \fBhelp tutorial\fP or \fBman fish\-tutorial\fP\&.
.SS Autosuggestions
.sp
fish suggests commands as you type, based on command history, completions, and valid file paths. As you type commands, you will see a suggestion offered after the cursor, in a muted gray color (which can be changed with the \fBfish_color_autosuggestion\fP variable).
.sp
To accept the autosuggestion (replacing the command line contents), press \fBright\fP (\fB→\fP) or \fBctrl\fP\-\fBf\fP\&. To accept the first suggested word, press \fBalt\fP\-\fBright\fP (\fB→\fP) or \fBalt\fP\-\fBf\fP\&. If the autosuggestion is not what you want, ignore it: it won\(aqt execute unless you accept it.
.sp
Autosuggestions are a powerful way to quickly summon frequently entered commands, by typing the first few characters. They are also an efficient technique for navigating through directory hierarchies.
.sp
If you don\(aqt like autosuggestions, you can disable them by setting \fB$fish_autosuggestion_enabled\fP to 0:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_autosuggestion_enabled 0
.EE
.UNINDENT
.UNINDENT
.SS Tab Completion
.sp
Tab completion is a time saving feature of any modern shell. When you type \fBtab\fP, fish tries to guess the rest of the word under the cursor. If it finds exactly one possibility, it inserts it. If it finds more, it inserts the longest unambiguous part and then opens a menu (the \(dqpager\(dq) that you can navigate to find what you\(aqre looking for.
.sp
The pager can be navigated with the arrow keys, \fBpageup\fP / \fBpagedown\fP, \fBtab\fP or \fBshift\fP\-\fBtab\fP\&. Pressing \fBctrl\fP\-\fBs\fP (the \fBpager\-toggle\-search\fP binding \- \fB/\fP in vi mode) opens up a search menu that you can use to filter the list.
.sp
fish provides some general purpose completions, like for commands, variable names, usernames or files.
.sp
It also provides a large number of program specific scripted completions. Most of these completions are simple options like the \fB\-l\fP option for \fBls\fP, but a lot are more advanced. For example:
.INDENT 0.0
.IP \(bu 2
\fBman\fP and \fBwhatis\fP show the installed manual pages as completions.
.IP \(bu 2
\fBmake\fP uses targets in the Makefile in the current directory as completions.
.IP \(bu 2
\fBmount\fP uses mount points specified in fstab as completions.
.IP \(bu 2
\fBapt\fP, \fBrpm\fP and \fByum\fP show installed or installable packages
.UNINDENT
.sp
You can also write your own completions or install some you got from someone else. For that, see Writing your own completions \%<>\&.
.sp
Completion scripts are loaded on demand, like functions are \%<#\:syntax-function-autoloading>\&. The difference is the \fB$fish_complete_path\fP list \%<#\:variables-lists> is used instead of \fB$fish_function_path\fP\&. Typically you can drop new completions in \fB~/.config/fish/completions/.fish\fP and fish will find them automatically.
.SS Syntax highlighting
.sp
fish interprets the command line as it is typed and uses syntax highlighting to provide feedback. The most important feedback is the detection of potential errors. By default, errors are marked red.
.sp
Detected errors include:
.INDENT 0.0
.IP \(bu 2
Non\-existing commands.
.IP \(bu 2
Reading from or appending to a non\-existing file.
.IP \(bu 2
Incorrect use of output redirects
.IP \(bu 2
Mismatched parenthesis
.UNINDENT
.sp
To customize the syntax highlighting, you can set the environment variables listed in the Variables for changing highlighting colors section.
.sp
fish also provides pre\-made color themes you can pick with fish_config \%<>\&.
Running just \fBfish_config\fP opens a browser interface, or you can use \fBfish_config theme\fP from fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# disable nearly all coloring
fish_config theme choose none
# restore fish\(aqs default theme
fish_config theme choose default
.EE
.UNINDENT
.UNINDENT
.sp
Or, to see all themes, right in your terminal:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_config theme show
.EE
.UNINDENT
.UNINDENT
.sp
To update the theme of all shell sessions without restarting them,
first have those sessions define an event handler \%<#\:event> by adding the following to your config.fish \%<#\:configuration> and restarting them:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function apply\-my\-theme \-\-on\-variable=my_theme
fish_config theme choose $my_theme
end
.EE
.UNINDENT
.UNINDENT
.sp
Then, set the corresponding universal variable \%<#\:variables-universal> from any session:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-U my_theme lava
> set \-U my_theme snow\-day
.EE
.UNINDENT
.UNINDENT
.SS Syntax highlighting variables
.sp
The colors used by fish for syntax highlighting can be configured by changing the values of various variables. The value of these variables can be one of the colors accepted by the set_color \%<> command.
Options accepted by \fBset_color\fP like
\fB\-\-foreground=\fP,
\fB\-\-background=\fP,
\fB\-\-bold\fP,
\fB\-\-dim\fP,
\fB\-\-italics\fP,
\fB\-\-reverse\fP,
\fB\-\-strikethrough\fP,
\fB\-\-underline\fP and
\fB\-\-underline\-color=\fP
are also accepted.
.sp
Example: to make errors highlighted and red, use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set fish_color_error red \-\-bold
.EE
.UNINDENT
.UNINDENT
.sp
The following variables are available to change the highlighting colors in fish:
.TS
box center;
l|l.
T{
Variable
T} T{
Meaning
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_normal
.UNINDENT
T} T{
default color
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_command
.UNINDENT
T} T{
commands like echo
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_builtin
.UNINDENT
T} T{
builtin commands like cd and set \- this falls back on the command color if unset
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_function
.UNINDENT
T} T{
user\-defined functions \- this falls back on the command color if unset
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_keyword
.UNINDENT
T} T{
keywords like if \- this falls back on the command color if unset
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_quote
.UNINDENT
T} T{
quoted text like \fB\(dqabc\(dq\fP
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_redirection
.UNINDENT
T} T{
IO redirections like >/dev/null
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_end
.UNINDENT
T} T{
process separators like \fB;\fP and \fB&\fP
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_error
.UNINDENT
T} T{
syntax errors
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_param
.UNINDENT
T} T{
ordinary command parameters
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_valid_path
.UNINDENT
T} T{
parameters and redirection targets that are filenames (if the file exists)
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_option
.UNINDENT
T} T{
options starting with \(dq\-\(dq, up to the first \(dq\-\-\(dq parameter
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_comment
.UNINDENT
T} T{
comments like \(aq# important\(aq
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_selection
.UNINDENT
T} T{
selected text in vi visual mode
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_operator
.UNINDENT
T} T{
parameter expansion operators like \fB*\fP and \fB~\fP
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_escape
.UNINDENT
T} T{
character escapes like \fB\en\fP and \fB\ex70\fP
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_autosuggestion
.UNINDENT
T} T{
autosuggestions (the proposed rest of a command)
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_cwd
.UNINDENT
T} T{
the current working directory in the default prompt
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_cwd_root
.UNINDENT
T} T{
the current working directory in the default prompt for the root user
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_user
.UNINDENT
T} T{
the username in the default prompt
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_host
.UNINDENT
T} T{
the hostname in the default prompt
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_host_remote
.UNINDENT
T} T{
the hostname in the default prompt for remote sessions (like ssh)
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_status
.UNINDENT
T} T{
the last command\(aqs nonzero exit code in the default prompt
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_cancel
.UNINDENT
T} T{
the \(aq^C\(aq indicator on a canceled command
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_search_match
.UNINDENT
T} T{
history search matches and selected pager items (background only)
T}
_
T{
.INDENT 0.0
.TP
.B fish_color_history_current
.UNINDENT
T} T{
the current position in the history for commands like \fBdirh\fP and \fBcdh\fP
T}
.TE
.sp
If a variable isn\(aqt set or is empty after subtracting any \fB\-\-theme=THEME\fP options,
fish usually tries \fB$fish_color_normal\fP, except for:
.INDENT 0.0
.IP \(bu 2
\fB$fish_color_builtin\fP and \fB$fish_color_function\fP, where they try \fB$fish_color_command\fP first.
.IP \(bu 2
\fB$fish_color_keyword\fP, where it tries \fB$fish_color_command\fP first.
.IP \(bu 2
\fB$fish_color_option\fP, where it tries \fB$fish_color_param\fP first.
.IP \(bu 2
For \fB$fish_color_valid_path\fP, if that doesn\(aqt have a color, but only modifiers, it adds those to the color that would otherwise be used,
like \fB$fish_color_param\fP\&. But if valid paths have a color, it uses that and adds in modifiers from the other color.
.UNINDENT
.SS Pager color variables
.sp
fish will sometimes present a list of choices in a table, called the pager.
.sp
Example: to set the background of each pager row, use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set fish_pager_color_background \-\-background=white
.EE
.UNINDENT
.UNINDENT
.sp
To have black text on alternating white and gray backgrounds:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set fish_pager_color_prefix black
set fish_pager_color_completion black
set fish_pager_color_description black
set fish_pager_color_background \-\-background=white
set fish_pager_color_secondary_background \-\-background=brwhite
.EE
.UNINDENT
.UNINDENT
.sp
Variables affecting the pager colors:
.TS
box center;
l|l.
T{
Variable
T} T{
Meaning
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_progress
.UNINDENT
T} T{
the progress bar at the bottom left corner
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_background
.UNINDENT
T} T{
the background color of a line
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_prefix
.UNINDENT
T} T{
the prefix string, i.e. the string that is to be completed
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_completion
.UNINDENT
T} T{
the completion itself, i.e. the proposed rest of the string
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_description
.UNINDENT
T} T{
the completion description
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_selected_background
.UNINDENT
T} T{
background of the selected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_selected_prefix
.UNINDENT
T} T{
prefix of the selected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_selected_completion
.UNINDENT
T} T{
suffix of the selected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_selected_description
.UNINDENT
T} T{
description of the selected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_secondary_background
.UNINDENT
T} T{
background of every second unselected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_secondary_prefix
.UNINDENT
T} T{
prefix of every second unselected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_secondary_completion
.UNINDENT
T} T{
suffix of every second unselected completion
T}
_
T{
.INDENT 0.0
.TP
.B fish_pager_color_secondary_description
.UNINDENT
T} T{
description of every second unselected completion
T}
.TE
.sp
When the secondary or selected variables aren\(aqt set or are empty, the normal variables are used, except for \fB$fish_pager_color_selected_background\fP, where the background of \fB$fish_color_search_match\fP is tried first.
.SS Abbreviations
.sp
To avoid needless typing, a frequently\-run command like \fBgit checkout\fP can be abbreviated to \fBgco\fP using the abbr \%<> command.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-a gco git checkout
.EE
.UNINDENT
.UNINDENT
.sp
After entering \fBgco\fP and pressing \fBspace\fP or \fBenter\fP, a \fBgco\fP in command position will turn into \fBgit checkout\fP in the command line. If you want to use a literal \fBgco\fP sometimes, use \fBctrl\fP\-\fBspace\fP [1]\&.
.sp
Abbreviations are a lot more powerful than just replacing literal strings. For example you can make going up a number of directories easier with this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function multicd
echo cd (string repeat \-n (math (string length \-\- $argv[1]) \- 1) ../)
end
abbr \-\-add dotdot \-\-regex \(aq^\e.\e.+$\(aq \-\-function multicd
.EE
.UNINDENT
.UNINDENT
.sp
Now, \fB\&..\fP transforms to \fBcd ../\fP, while \fB\&...\fP turns into \fBcd ../../\fP and \fB\&....\fP expands to \fBcd ../../../\fP\&.
.sp
The advantage over aliases is that you can see the actual command before using it, add to it or change it, and the actual command will be stored in history.
.IP [1] 5
Any binding that executes the \fBexpand\-abbr\fP or \fBexecute\fP bind function \%<> will expand abbreviations. By default \fBctrl\fP\-\fBspace\fP is bound to just inserting a space.
.SS Programmable prompt
.sp
When it is fish\(aqs turn to ask for input (like after it started or the command ended), it will show a prompt. Often this looks something like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
you@hostname ~>
.EE
.UNINDENT
.UNINDENT
.sp
This prompt is determined by running the fish_prompt \%<> and fish_right_prompt \%<> functions.
.sp
The output of the former is displayed on the left and the latter\(aqs output on the right side of the terminal.
For vi mode, the output of fish_mode_prompt \%<> will be prepended on the left.
.sp
If \fBfish_transient_prompt\fP \%<#\:envvar-fish_transient_prompt> is set to 1, fish will redraw the prompt with a \fB\-\-final\-rendering\fP argument before running a commandline, allowing you to change it before pushing it to the scrollback.
.sp
fish ships with a few prompts which you can see with fish_config \%<>\&. If you run just \fBfish_config\fP it will open a web interface [2] where you\(aqll be shown the prompts and can pick which one you want. \fBfish_config prompt show\fP will show you the prompts right in your terminal.
.sp
For example \fBfish_config prompt choose disco\fP will temporarily select the \(dqdisco\(dq prompt. If you like it and decide to keep it, run \fBfish_config prompt save\fP\&.
.sp
You can also change these functions yourself by running \fBfunced fish_prompt\fP and \fBfuncsave fish_prompt\fP once you are happy with the result (or \fBfish_right_prompt\fP if you want to change that).
.IP [2] 5
The web interface runs purely locally on your computer and requires python to be installed.
.SS Configurable greeting
.sp
When it is started interactively, fish tries to run the fish_greeting \%<> function. The default fish_greeting prints a simple message. You can change its text by changing the \fB$fish_greeting\fP variable, for instance using a universal variable \%<#\:variables-universal>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-U fish_greeting
.EE
.UNINDENT
.UNINDENT
.sp
or you can set it globally \%<#\:variables-scope> in config.fish \%<#\:configuration>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_greeting \(aqHey, stranger!\(aq
.EE
.UNINDENT
.UNINDENT
.sp
or you can script it by changing the function:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_greeting
random choice \(dqHello!\(dq \(dqHi\(dq \(dqG\(aqday\(dq \(dqHowdy\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
save this in config.fish or a function file \%<#\:syntax-function-autoloading>\&. You can also use funced \%<> and funcsave \%<> to edit it easily.
.SS Programmable title
.sp
Most terminals allow setting the text displayed in the titlebar of the terminal window.
fish does this by running the fish_title \%<> function.
It is executed before and after a command and the output is used as a titlebar message.
.sp
The status current\-command \%<> builtin will always return the name of the job to be put into the foreground (or \fBfish\fP if control is returning to the shell) when the fish_title \%<> function is called. The first argument will contain the most recently executed foreground command as a string.
.sp
The default title shows the hostname if connected via ssh, the currently running command (unless it is fish) and the current working directory. All of this is shortened to not make the tab too wide.
.sp
Examples:
.sp
To show the last command and working directory in the title:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
# \(gaprompt_pwd\(ga shortens the title. This helps prevent tabs from becoming very wide.
echo $argv[1] (prompt_pwd)
pwd
end
.EE
.UNINDENT
.UNINDENT
.SS Command line editor
.sp
The fish editor features copy and paste, a searchable history and many editor functions that can be bound to special keyboard shortcuts.
.sp
Like bash and other shells, fish includes two sets of keyboard shortcuts (or key bindings): one inspired by the Emacs text editor, and one by the vi text editor. The default editing mode is Emacs. You can switch to vi mode by running fish_vi_key_bindings \%<> and switch back with fish_default_key_bindings \%<>\&. You can also make your own key bindings by creating a function and setting the \fBfish_key_bindings\fP variable to its name. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_hybrid_key_bindings \-\-description \e
\(dqVi\-style bindings that inherit emacs\-style bindings in all modes\(dq
for mode in default insert visual
fish_default_key_bindings \-M $mode
end
fish_vi_key_bindings \-\-no\-erase
end
set \-g fish_key_bindings fish_hybrid_key_bindings
.EE
.UNINDENT
.UNINDENT
.sp
While the key bindings included with fish include many of the shortcuts popular from the respective text editors, they are not a complete implementation. They include a shortcut to open the current command line in your preferred editor (\fBalt\fP\-\fBe\fP by default) if you need the full power of your editor.
.SS Shared bindings
.sp
Some bindings are common across Emacs and vi mode, because they aren\(aqt text editing bindings, or because what vi/Vim does for a particular key doesn\(aqt make sense for a shell.
.INDENT 0.0
.IP \(bu 2
\fBtab\fP completes the current token. \fBshift\fP\-\fBtab\fP completes the current token and starts the pager\(aqs search mode. \fBtab\fP is the same as \fBctrl\fP\-\fBi\fP\&.
.IP \(bu 2
\fBleft\fP (\fB←\fP) and \fBright\fP (\fB→\fP) move the cursor left or right by one character. If the cursor is already at the end of the line, and an autosuggestion is available, \fBright\fP (\fB→\fP) accepts the autosuggestion.
.IP \(bu 2
\fBenter\fP executes the current commandline or inserts a newline if it\(aqs not complete yet (e.g. a \fB)\fP or \fBend\fP is missing).
.IP \(bu 2
\fBalt\fP\-\fBenter\fP inserts a newline at the cursor position. This is useful to add a line to a commandline that\(aqs already complete.
.IP \(bu 2
\fBalt\fP\-\fBleft\fP (\fB←\fP) and \fBalt\fP\-\fBright\fP (\fB→\fP) move the cursor left or right by one word.
If the command line is empty, they move forward/backward in the directory history.
If the cursor is already at the end of the line, and an autosuggestion is available, \fBalt\fP\-\fBright\fP (\fB→\fP) (or \fBalt\fP\-\fBf\fP) accepts the first word in the suggestion.
.IP \(bu 2
\fBctrl\fP\-\fBleft\fP (\fB←\fP) and \fBctrl\fP\-\fBright\fP (\fB→\fP) move the cursor left or right by one token. These accept one token of the autosuggestion \- the part they\(aqd move over.
.IP \(bu 2
\fBshift\fP\-\fBleft\fP (\fB←\fP) and \fBshift\fP\-\fBright\fP (\fB→\fP) move the cursor one word left or right, without stopping on punctuation. These accept one big word of the autosuggestion.
.IP \(bu 2
\fBup\fP (\fB↑\fP) and \fBdown\fP (\fB↓\fP) (or \fBctrl\fP\-\fBp\fP and \fBctrl\fP\-\fBn\fP for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the history section for more information on history searching.
.IP \(bu 2
\fBalt\fP\-\fBup\fP (\fB↑\fP) and \fBalt\fP\-\fBdown\fP (\fB↓\fP) search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the history section for more information on history searching.
.IP \(bu 2
\fBctrl\fP\-\fBc\fP interrupts/kills whatever is running (SIGINT).
.IP \(bu 2
\fBctrl\fP\-\fBd\fP deletes one character to the right of the cursor. If the command line is empty, \fBctrl\fP\-\fBd\fP will exit fish.
.IP \(bu 2
\fBctrl\fP\-\fBu\fP removes contents from the beginning of line to the cursor (moving it to the killring).
.IP \(bu 2
\fBctrl\fP\-\fBl\fP pushes any text above the prompt to the terminal\(aqs scrollback,
then clears and repaints the screen.
.IP \(bu 2
\fBctrl\fP\-\fBw\fP removes the previous path component (everything up to the previous \(dq/\(dq, \(dq:\(dq or \(dq@\(dq) (moving it to the Copy and paste (Kill Ring)).
.IP \(bu 2
\fBctrl\fP\-\fBx\fP copies the current buffer to the system\(aqs clipboard, \fBctrl\fP\-\fBv\fP inserts the clipboard contents. (see fish_clipboard_copy \%<> and fish_clipboard_paste \%<>)
.IP \(bu 2
\fBalt\fP\-\fBd\fP moves the next word to the Copy and paste (Kill Ring)\&.
.IP \(bu 2
\fBctrl\fP\-\fBdelete\fP moves the next word (or next argument on macOS) to the Copy and paste (Kill Ring)\&.
.IP \(bu 2
\fBalt\fP\-\fBd\fP lists the directory history if the command line is empty.
.IP \(bu 2
\fBalt\fP\-\fBdelete\fP moves the next argument (or word on macOS) to the Copy and paste (Kill Ring)\&.
.IP \(bu 2
\fBshift\fP\-\fBdelete\fP removes the current history item or autosuggestion from the command history.
.IP \(bu 2
\fBalt\fP\-\fBh\fP (or \fBf1\fP) shows the manual page for the current command, if one exists.
.IP \(bu 2
\fBalt\fP\-\fBl\fP lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed.
.UNINDENT
.INDENT 0.0
.IP \(bu 2
\fBalt\fP\-\fBo\fP opens the file at the cursor in a pager. If the cursor is in command position and the command is a script, it will instead open that script in your editor. The editor is chosen from the first available of the \fB$VISUAL\fP or \fB$EDITOR\fP variables.
.IP \(bu 2
\fBalt\fP\-\fBp\fP adds the string \fB&| less;\fP to the end of the job under the cursor. The result is that the output of the command will be paged. If you set the \fBPAGER\fP variable, its value is used instead of \fBless\fP\&.
.IP \(bu 2
\fBalt\fP\-\fBw\fP prints a short description of the command under the cursor.
.IP \(bu 2
\fBalt\fP\-\fBe\fP edits the current command line in an external editor. The editor is chosen from the first available of the \fB$VISUAL\fP or \fB$EDITOR\fP variables.
.IP \(bu 2
\fBalt\fP\-\fBv\fP Same as \fBalt\fP\-\fBe\fP\&.
.IP \(bu 2
\fBalt\fP\-\fBs\fP Prepends \fBsudo\fP to the current commandline. If the commandline is empty, prepend \fBsudo\fP to the last commandline. If \fBsudo\fP is not installed, various similar commands are tried: \fBdoas\fP, \fBplease\fP, and \fBrun0\fP\&.
.IP \(bu 2
\fBctrl\fP\-\fBspace\fP Inserts a space without expanding an abbreviation\&. For vi mode, this only applies to insert\-mode.
.UNINDENT
.SS Emacs mode commands
.sp
To enable emacs mode, use fish_default_key_bindings \%<>\&. This is also the default.
.INDENT 0.0
.IP \(bu 2
\fBhome\fP or \fBctrl\fP\-\fBa\fP moves the cursor to the beginning of the line.
.IP \(bu 2
\fBend\fP or \fBctrl\fP\-\fBe\fP moves to the end of line. If the cursor is already at the end of the line, and an autosuggestion is available, \fBend\fP or \fBctrl\fP\-\fBe\fP accepts the autosuggestion.
.IP \(bu 2
\fBctrl\fP\-\fBb\fP, \fBctrl\fP\-\fBf\fP move the cursor one character left or right or accept the autosuggestion just like the \fBleft\fP (\fB←\fP) and \fBright\fP (\fB→\fP) shared bindings (which are available as well).
.IP \(bu 2
\fBalt\fP\-\fBb\fP, \fBalt\fP\-\fBf\fP move the cursor one word left or right, or accept one word of the autosuggestion. If the command line is empty, moves forward/backward in the directory history instead.
.IP \(bu 2
\fBctrl\fP\-\fBn\fP, \fBctrl\fP\-\fBp\fP move the cursor up/down or through history, like the up and down arrow shared bindings.
.IP \(bu 2
\fBdelete\fP or \fBbackspace\fP or \fBctrl\fP\-\fBh\fP removes one character forwards or backwards respectively.
.IP \(bu 2
\fBalt\fP\-\fBbackspace\fP removes one word backwards and \fBctrl\fP\-\fBbackspace\fP removes one argument backwards.
.IP \(bu 2
\fBalt\fP\-\fB<\fP moves to the beginning of the commandline, \fBalt\fP\-\fB>\fP moves to the end.
.IP \(bu 2
\fBctrl\fP\-\fBk\fP deletes from the cursor to the end of line (moving it to the Copy and paste (Kill Ring)).
.IP \(bu 2
\fBescape\fP and \fBctrl\fP\-\fBg\fP cancel the current operation. Immediately after an unambiguous completion this undoes it.
.IP \(bu 2
\fBalt\fP\-\fBc\fP capitalizes the current word.
.IP \(bu 2
\fBalt\fP\-\fBu\fP makes the current word uppercase.
.IP \(bu 2
\fBctrl\fP\-\fBt\fP transposes the last two characters.
.IP \(bu 2
\fBalt\fP\-\fBt\fP transposes the last two words.
.IP \(bu 2
\fBctrl\fP\-\fBz\fP, \fBctrl\fP\-\fB_\fP (\fBctrl\fP\-\fB/\fP on some terminals) undo the most recent edit of the line.
.IP \(bu 2
\fBalt\fP\-\fB/\fP or \fBctrl\fP\-\fBshift\fP\-\fBz\fP reverts the most recent undo.
.IP \(bu 2
\fBctrl\fP\-\fBr\fP opens the history in a pager. This will show history entries matching the search, a few at a time. Pressing \fBctrl\fP\-\fBr\fP again will search older entries, pressing \fBctrl\fP\-\fBs\fP (that otherwise toggles pager search) will go to newer entries. The search bar will always be selected.
.UNINDENT
.sp
You can change these key bindings using the bind \%<> builtin.
.SS Vi mode commands
.sp
Vi mode allows for the use of vi\-like commands at the prompt. Initially, insert mode is active. \fBescape\fP enters command mode\&. The commands available in command, insert and visual mode are described below. Vi mode shares some bindings with Emacs mode\&.
.sp
To enable vi mode, use fish_vi_key_bindings \%<>\&.
It is also possible to add all Emacs mode bindings to vi mode by using something like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_user_key_bindings
# Execute this once per mode that emacs bindings should be used in
fish_default_key_bindings \-M insert
# Then execute the vi\-bindings so they take precedence when there\(aqs a conflict.
# Without \-\-no\-erase fish_vi_key_bindings will default to
# resetting all bindings.
# The argument specifies the initial mode (insert, \(dqdefault\(dq or visual).
fish_vi_key_bindings \-\-no\-erase insert
end
.EE
.UNINDENT
.UNINDENT
.sp
When in vi mode, the fish_mode_prompt \%<> function will display a mode indicator to the left of the prompt. To disable this feature, override it with an empty function. To display the mode elsewhere (like in your right prompt), use the output of the \fBfish_default_mode_prompt\fP function.
.sp
When a binding switches the mode, it will repaint the mode\-prompt if it exists, and the rest of the prompt only if it doesn\(aqt. So if you want a mode\-indicator in your \fBfish_prompt\fP, you need to erase \fBfish_mode_prompt\fP e.g. by adding an empty file at \fB~/.config/fish/functions/fish_mode_prompt.fish\fP\&. (Bindings that change the mode are supposed to call the \fIrepaint\-mode\fP bind function, see bind \%<>)
.sp
The \fBfish_vi_cursor\fP function will be used to change the cursor\(aqs shape depending on the mode in supported terminals. The following snippet can be used to manually configure cursors after enabling vi mode:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Emulates vim\(aqs cursor shape behavior
# Set the normal and visual mode cursors to a block
set fish_cursor_default block
# Set the insert mode cursor to a line
set fish_cursor_insert line
# Set the replace mode cursors to an underscore
set fish_cursor_replace_one underscore
set fish_cursor_replace underscore
# Set the external cursor to a line. The external cursor appears when a command is started.
# The cursor shape takes the value of fish_cursor_default when fish_cursor_external is not specified.
set fish_cursor_external line
# The following variable can be used to configure cursor shape in
# visual mode, but due to fish_cursor_default, is redundant here
set fish_cursor_visual block
.EE
.UNINDENT
.UNINDENT
.sp
Additionally, \fBblink\fP can be added after each of the cursor shape parameters to set a blinking cursor in the specified shape.
.sp
fish knows the shapes \(dqblock\(dq, \(dqline\(dq and \(dqunderscore\(dq, other values will be ignored.
.sp
If the cursor shape does not appear to be changing after setting the above variables, it\(aqs likely your terminal emulator does not support the capabilities necessary to do this.
.SS Command mode
.sp
Command mode is also known as normal mode.
.INDENT 0.0
.IP \(bu 2
\fBh\fP moves the cursor left.
.IP \(bu 2
\fBl\fP moves the cursor right.
.IP \(bu 2
\fBk\fP and \fBj\fP search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the history section for more information on history searching. In multi\-line commands, they move the cursor up and down respectively.
.IP \(bu 2
\fBi\fP enters insert mode at the current cursor position.
.IP \(bu 2
\fBI\fP enters insert mode at the beginning of the line.
.IP \(bu 2
\fBv\fP enters visual mode at the current cursor position.
.IP \(bu 2
\fBa\fP enters insert mode after the current cursor position.
.IP \(bu 2
\fBA\fP enters insert mode at the end of the line.
.IP \(bu 2
\fBo\fP inserts a new line under the current one and enters insert mode
.IP \(bu 2
\fBO\fP (capital\-\(dqo\(dq) inserts a new line above the current one and enters insert mode
.IP \(bu 2
\fB0\fP (zero) moves the cursor to beginning of line (remaining in command mode).
.IP \(bu 2
\fBd,d\fP deletes the current line and moves it to the Copy and paste (Kill Ring)\&.
.IP \(bu 2
\fBD\fP deletes text after the current cursor position and moves it to the Copy and paste (Kill Ring)\&.
.IP \(bu 2
\fBp\fP pastes text from the Copy and paste (Kill Ring)\&.
.IP \(bu 2
\fBu\fP undoes the most recent edit of the command line.
.IP \(bu 2
\fBctrl\fP\-\fBr\fP redoes the most recent edit.
.IP \(bu 2
\fB[\fP and \fB]\fP search the command history for the previous/next token containing the token under the cursor before the search was started. See the history section for more information on history searching.
.IP \(bu 2
\fB/\fP opens the history in a pager. This will show history entries matching the search, a few at a time. Pressing it again will search older entries, pressing \fBctrl\fP\-\fBs\fP (that otherwise toggles pager search) will go to newer entries. The search bar will always be selected.
.IP \(bu 2
\fBbackspace\fP moves the cursor left.
.IP \(bu 2
\fBg,g\fP / \fBG\fP moves the cursor to the beginning/end of the commandline, respectively.
.IP \(bu 2
\fB~\fP toggles the case (upper/lower) of the character and moves to the next character.
.IP \(bu 2
\fBg,u\fP lowercases to the end of the word.
.IP \(bu 2
\fBg,U\fP uppercases to the end of the word.
.IP \(bu 2
\fB:,q\fP exits fish.
.UNINDENT
.SS Insert mode
.INDENT 0.0
.IP \(bu 2
\fBescape\fP enters command mode\&.
.IP \(bu 2
\fBbackspace\fP removes one character to the left.
.IP \(bu 2
\fBctrl\fP\-\fBn\fP accepts the autosuggestion.
.UNINDENT
.SS Visual mode
.INDENT 0.0
.IP \(bu 2
\fBleft\fP \fB(\(ga\(ga←\(ga\fP) and \fBright\(ga(\(ga\(ga→\(ga\fP) extend the selection backward/forward by one character.
.IP \(bu 2
\fBh\fP moves the cursor left.
.IP \(bu 2
\fBl\fP moves the cursor right.
.IP \(bu 2
\fBk\fP moves the cursor up.
.IP \(bu 2
\fBj\fP moves the cursor down.
.IP \(bu 2
\fBb\fP and \fBw\fP extend the selection backward/forward by one word.
.IP \(bu 2
\fBd\fP and \fBx\fP move the selection to the Copy and paste (Kill Ring) and enter command mode\&.
.IP \(bu 2
\fBescape\fP and \fBctrl\fP\-\fBc\fP enter command mode\&.
.IP \(bu 2
\fBc\fP and \fBs\fP remove the selection and switch to insert mode.
.IP \(bu 2
\fBX\fP moves the entire line to the Copy and paste (Kill Ring), and enters command mode\&.
.IP \(bu 2
\fBy\fP copies the selection to the Copy and paste (Kill Ring), and enters command mode\&.
.IP \(bu 2
\fB~\fP toggles the case (upper/lower) on the selection, and enters command mode\&.
.IP \(bu 2
\fBg,u\fP lowercases the selection, and enters command mode\&.
.IP \(bu 2
\fBg,U\fP uppercases the selection, and enters command mode\&.
.IP \(bu 2
\fB\(dq,*,y\fP copies the selection to the clipboard, and enters command mode\&.
.UNINDENT
.SS Custom bindings
.sp
In addition to the standard bindings listed here, you can also define your own with bind \%<>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Prints \(ga\(ga^C\(ga\(ga and a new prompt
bind ctrl\-c cancel\-commandline
.EE
.UNINDENT
.UNINDENT
.sp
Put \fBbind\fP statements into config.fish \%<#\:configuration> or a function called \fBfish_user_key_bindings\fP\&.
.sp
If you change your mind on a binding and want to go back to fish\(aqs default, you can erase it again:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind \-\-erase ctrl\-c
.EE
.UNINDENT
.UNINDENT
.sp
fish remembers its preset bindings and so it will take effect again. This saves you from having to remember what it was before and add it again yourself.
.sp
If you use vi bindings, note that \fBbind\fP will by default bind keys in command mode\&. To bind something in insert mode:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind \-\-mode insert ctrl\-c \(aqcommandline \-r \(dq\(dq\(aq
.EE
.UNINDENT
.UNINDENT
.SS Key sequences
.sp
To find out the name of a key, you can use fish_key_reader \%<>\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish_key_reader # Press Alt + right\-arrow
Press a key:
bind alt\-right \(aqdo something\(aq
.EE
.UNINDENT
.UNINDENT
.sp
Note that the historical way the terminal encodes keys and sends them to the application (fish, in this case) makes a lot of combinations indistinguishable or unbindable. In the usual encoding, \fBctrl\fP\-\fBi\fP \fIis the same\fP as the tab key, and shift cannot be detected when ctrl is also pressed.
.sp
There are more powerful encoding schemes, and fish tries to tell the terminal to turn them on, but there are still many terminals that do not support them. When \fBfish_key_reader\fP prints the same sequence for two different keys, then that is because your terminal sends the same sequence for them, and there isn\(aqt anything fish can do about it. It is our hope that these schemes will become more widespread, making input more flexible.
.sp
In the historical scheme, \fBescape\fP is the same thing as \fBalt\fP in a terminal. To distinguish between pressing \fBescape\fP and then another key, and pressing \fBalt\fP and that key (or an escape sequence the key sends), fish waits for a certain time after seeing an escape character. This is configurable via the \fBfish_escape_delay_ms\fP \%<#\:envvar-fish_escape_delay_ms> variable.
.sp
If you want to be able to press \fBescape\fP and then a character and have it count as \fBalt\fP+that character, set it to a higher value, e.g.:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_escape_delay_ms 100
.EE
.UNINDENT
.UNINDENT
.sp
Similarly, to disambiguate \fIother\fP keypresses where you\(aqve bound a subsequence and a longer sequence, fish has \fBfish_sequence_key_delay_ms\fP \%<#\:envvar-fish_sequence_key_delay_ms>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# This binds the sequence j,k to switch to normal mode in vi mode.
# If you kept it like that, every time you press \(dqj\(dq,
# fish would wait for a \(dqk\(dq or other key to disambiguate
bind \-M insert \-m default j,k cancel repaint\-mode
# After setting this, fish only waits 200ms for the \(dqk\(dq,
# or decides to treat the \(dqj\(dq as a separate sequence, inserting it.
set \-g fish_sequence_key_delay_ms 200
.EE
.UNINDENT
.UNINDENT
.SS Copy and paste (Kill Ring)
.sp
fish uses an Emacs\-style kill ring for copy and paste functionality. For example, use \fBctrl\fP\-\fBk\fP (\fIkill\-line\fP) to cut from the current cursor position to the end of the line. The string that is cut (a.k.a. killed in emacs\-ese) is inserted into a list of kills, called the kill ring. To paste the latest value from the kill ring (emacs calls this \(dqyanking\(dq) use \fBctrl\fP\-\fBy\fP (the \fByank\fP input function). After pasting, use \fBalt\fP\-\fBy\fP (\fByank\-pop\fP) to rotate to the previous kill.
.sp
Copy and paste from outside are also supported, both via the \fBctrl\fP\-\fBx\fP / \fBctrl\fP\-\fBv\fP bindings (the \fBfish_clipboard_copy\fP and \fBfish_clipboard_paste\fP functions [3]) and via the terminal\(aqs paste function, for which fish enables \(dqBracketed Paste Mode\(dq, so it can tell a paste from manually entered text.
In addition, when pasting inside single quotes, pasted single quotes and backslashes are automatically escaped so that the result can be used as a single token by closing the quote after.
Kill ring entries are stored in \fBfish_killring\fP variable.
.sp
The commands \fBbegin\-selection\fP and \fBend\-selection\fP (unbound by default; used for selection in vi visual mode) control text selection together with cursor movement commands that extend the current selection.
The variable \fBfish_cursor_selection_mode\fP \%<#\:envvar-fish_cursor_selection_mode> can be used to configure if that selection should include the character under the cursor (\fBinclusive\fP) or not (\fBexclusive\fP). The default is \fBexclusive\fP, which works well with any cursor shape. For vi mode, and particularly for the \fBblock\fP or \fBunderscore\fP cursor shapes you may prefer \fBinclusive\fP\&.
.IP [3] 5
These rely on external tools. Currently xsel, xclip, wl\-copy/wl\-paste and pbcopy/pbpaste are supported.
.SS Multiline editing
.sp
The fish commandline editor can be used to work on commands that are several lines long. There are three ways to make a command span more than a single line:
.INDENT 0.0
.IP \(bu 2
Pressing the \fBenter\fP key while a block of commands is unclosed, such as when one or more block commands such as \fBfor\fP, \fBbegin\fP or \fBif\fP do not have a corresponding end \%<> command.
.IP \(bu 2
Pressing \fBalt\fP\-\fBenter\fP instead of pressing the \fBenter\fP key.
.IP \(bu 2
By inserting a backslash (\fB\e\fP) character before pressing the \fBenter\fP key, escaping the newline.
.UNINDENT
.sp
The fish commandline editor works exactly the same in single line mode and in multiline mode. To move between lines use the left and right arrow keys and other such keyboard shortcuts.
.SS Searchable command history
.sp
After a command has been executed, it is remembered in the history list. Any duplicate history items are automatically removed. By pressing the up and down keys, you can search forwards and backwards in the history. If the current command line is not empty when starting a history search, only the commands containing the string entered into the command line are shown.
.sp
By pressing \fBalt\fP\-\fBup\fP (\fB↑\fP) and \fBalt\fP\-\fBdown\fP (\fB↓\fP), a history search is also performed, but instead of searching for a complete commandline, each commandline is broken into separate elements like it would be before execution, and the history is searched for an element matching that under the cursor.
.sp
For more complicated searches, you can press \fBctrl\fP\-\fBr\fP to open a pager that allows you to search the history. It shows a limited number of entries in one page, press \fBctrl\fP\-\fBr\fP [4] again to move to the next page and \fBctrl\fP\-\fBs\fP [5] to move to the previous page. You can change the text to refine your search.
.sp
History searches are case\-insensitive unless the search string contains an uppercase character. You can stop a search to edit your search string by pressing \fBescape\fP or \fBpagedown\fP\&.
.sp
Prefixing the commandline with a space will prevent the entire line from being stored in the history. It will still be available for recall until the next command is executed, but will not be stored on disk. This is to allow you to fix misspellings and such.
.sp
The command history is stored in the file \fB~/.local/share/fish/fish_history\fP (or
\fB$XDG_DATA_HOME/fish/fish_history\fP if that variable is set) by default. However, you can set the
\fBfish_history\fP environment variable to change the name of the history session (resulting in a
\fB_history\fP file); both before starting the shell and while the shell is running.
.sp
See the history \%<> command for other manipulations.
.sp
Examples:
.sp
To search for previous entries containing the word \(aqmake\(aq, type \fBmake\fP in the console and press the up key.
.sp
If the commandline reads \fBcd m\fP, place the cursor over the \fBm\fP character and press \fBalt\fP\-\fBup\fP (\fB↑\fP) to search for previously typed words containing \(aqm\(aq.
.IP [4] 5
Or another binding that triggers the \fBhistory\-pager\fP input function. See bind \%<> for a list.
.IP [5] 5
Or another binding that triggers the \fBpager\-toggle\-search\fP input function.
.SS Private mode
.sp
fish has a private mode, in which command history will not be written to the history file on disk. To enable it, either set \fB$fish_private_mode\fP to a non\-empty value, or launch with \fBfish \-\-private\fP (or \fBfish \-P\fP for short).
.sp
If you launch fish with \fB\-P\fP, it both hides old history and prevents writing history to disk. This is useful to avoid leaking personal information (e.g. for screencasts) or when dealing with sensitive information.
.sp
You can query the variable \fBfish_private_mode\fP (\fBif test \-n \(dq$fish_private_mode\(dq ...\fP) if you would like to respect the user\(aqs wish for privacy and alter the behavior of your own fish scripts.
.SS Navigating directories
.sp
Navigating directories is usually done with the cd \%<> command, but fish offers some advanced features as well.
.sp
The current working directory can be displayed with the pwd \%<> command, or the \fB$PWD\fP special variable \%<#\:variables-special>\&. Usually your prompt already does this.
.SS Directory history
.sp
fish automatically keeps a trail of the recent visited directories with cd \%<> by storing this history in the \fBdirprev\fP and \fBdirnext\fP variables.
.sp
Several commands are provided to interact with this directory history:
.INDENT 0.0
.IP \(bu 2
dirh \%<> prints the history
.IP \(bu 2
cdh \%<> displays a prompt to quickly navigate the history
.IP \(bu 2
prevd \%<> moves backward through the history. It is bound to \fBalt\fP\-\fBleft\fP (\fB←\fP)
.IP \(bu 2
nextd \%<> moves forward through the history. It is bound to \fBalt\fP\-\fBright\fP (\fB→\fP)
.UNINDENT
.SS Directory stack
.sp
Another set of commands, usually also available in other shells like bash, deal with the directory stack. Stack handling is not automatic and needs explicit calls of the following commands:
.INDENT 0.0
.IP \(bu 2
dirs \%<> prints the stack
.IP \(bu 2
pushd \%<> adds a directory on top of the stack and makes it the current working directory
.IP \(bu 2
popd \%<> removes the directory on top of the stack and changes the current working directory
.UNINDENT
.SS The fish language
.sp
This document is a comprehensive overview of fish\(aqs scripting language.
.sp
For interactive features see Interactive use \%<>\&.
.SS Syntax overview
.sp
Shells like fish are used by giving them commands. A command is executed by writing the name of the command followed by any arguments. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo hello world
.EE
.UNINDENT
.UNINDENT
.sp
echo \%<> command writes its arguments to the screen. In this example the output is \fBhello world\fP\&.
.sp
Everything in fish is done with commands. There are commands for repeating other commands, commands for assigning variables, commands for treating a group of commands as a single command, etc. All of these commands follow the same basic syntax.
.sp
Every program on your computer can be used as a command in fish. If the program file is located in one of the \fBPATH\fP directories, you can just type the name of the program to use it. Otherwise the whole filename, including the directory (like \fB/home/me/code/checkers/checkers\fP or \fB\&../checkers\fP) is required.
.sp
Here is a list of some useful commands:
.INDENT 0.0
.IP \(bu 2
cd \%<>: Change the current directory
.IP \(bu 2
\fBls\fP: List files and directories
.IP \(bu 2
\fBman\fP: Display a manual page \- try \fBman ls\fP to get help on your \(dqls\(dq command, or \fBman mv\fP to get information about \(dqmv\(dq.
.IP \(bu 2
\fBmv\fP: Move (rename) files
.IP \(bu 2
\fBcp\fP: Copy files
.IP \(bu 2
open \%<>: Open files with the default application associated with each filetype
.IP \(bu 2
\fBless\fP: Display the contents of files
.UNINDENT
.sp
Commands and arguments are separated by the space character \fB\(aq \(aq\fP\&. Every command ends with either a newline (by pressing the return key) or a semicolon \fB;\fP\&. Multiple commands can be written on the same line by separating them with semicolons.
.sp
A switch is a very common special type of argument. Switches almost always start with one or more hyphens \fB\-\fP and alter the way a command operates. For example, the \fBls\fP command usually lists the names of all files and directories in the current working directory. By using the \fB\-l\fP switch, the behavior of \fBls\fP is changed to not only display the filename, but also the size, permissions, owner, and modification time of each file.
.sp
Switches differ between commands and are usually documented on a command\(aqs manual page. There are some switches, however, that are common to most commands. For example, \fB\-\-help\fP will usually display a help text, \fB\-\-version\fP will usually display the command version, and \fB\-i\fP will often turn on interactive prompting before taking action. Try \fBman your\-command\-here\fP to get information on your command\(aqs switches.
.sp
So the basic idea of fish is the same as with other unix shells: It gets a commandline, runs expansions, and the result is then run as a command.
.SS Terminology
.sp
Here we define some of the terms used on this page and throughout the rest of the fish documentation:
.INDENT 0.0
.IP \(bu 2
\fBArgument\fP: A parameter given to a command. In \fBecho foo\fP, the \(dqfoo\(dq is an argument.
.IP \(bu 2
\fBBuiltin\fP: A command that is implemented by the shell. Builtins are so closely tied to the operation of the shell that it is impossible to implement them as external commands. In \fBecho foo\fP, the \(dqecho\(dq is a builtin.
.IP \(bu 2
\fBCommand\fP: A program that the shell can run, or more specifically an external program that the shell runs in another process. External commands are provided on your system, as executable files. In \fBecho foo\fP the \(dqecho\(dq is a builtin command, in \fBcommand echo foo\fP the \(dqecho\(dq is an external command, provided by a file like /bin/echo.
.IP \(bu 2
\fBFunction\fP: A block of commands that can be called as if they were a single command. By using functions, it is possible to string together multiple simple commands into one more advanced command.
.IP \(bu 2
\fBJob\fP: A running pipeline or command.
.IP \(bu 2
\fBPipeline\fP: A set of commands strung together so that the output of one command is the input of the next command. \fBecho foo | grep foo\fP is a pipeline.
.IP \(bu 2
\fBRedirection\fP: An operation that changes one of the input or output streams associated with a job.
.IP \(bu 2
\fBSwitch\fP or \fBOption\fP: A special kind of argument that alters the behavior of a command. A switch almost always begins with one or two hyphens. In \fBecho \-n foo\fP the \(dq\-n\(dq is an option.
.UNINDENT
.SS Quotes
.sp
Sometimes you want to give a command an argument that contains characters special to fish, like spaces or \fB$\fP or \fB*\fP\&. To do that, you can use quotes:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
rm \(dqmy file.txt\(dq
.EE
.UNINDENT
.UNINDENT
.sp
to remove a file called \fBmy file.txt\fP instead of trying to remove two files, \fBmy\fP and \fBfile.txt\fP\&.
.sp
fish understands two kinds of quotes: Single (\fB\(aq\fP) and double (\fB\(dq\fP), and both work slightly differently.
.sp
Between single quotes, fish performs no expansions. Between double quotes, fish only performs variable expansion and command substitution in the \fB$(command)\fP\&. No other kind of expansion (including brace expansion or parameter expansion) is performed, and escape sequences (for example, \fB\en\fP) are ignored. Within quotes, whitespace is not used to separate arguments, allowing quoted arguments to contain spaces.
.sp
The only meaningful escape sequences in single quotes are \fB\e\(aq\fP, which escapes a single quote and \fB\e\e\fP, which escapes the backslash symbol. The only meaningful escapes in double quotes are \fB\e\(dq\fP, which escapes a double quote, \fB\e$\fP, which escapes a dollar character, \fB\e\fP followed by a newline, which deletes the backslash and the newline, and \fB\e\e\fP, which escapes the backslash symbol.
.sp
Single quotes have no special meaning within double quotes and vice versa.
.sp
More examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
grep \(aqenabled)$\(aq foo.txt
.EE
.UNINDENT
.UNINDENT
.sp
searches for lines ending in \fBenabled)\fP in \fBfoo.txt\fP (the \fB$\fP is special to \fBgrep\fP: it matches the end of the line).
.INDENT 0.0
.INDENT 3.5
.sp
.EX
apt install \(dqpostgres\-*\(dq
.EE
.UNINDENT
.UNINDENT
.sp
installs all packages with a name starting with \(dqpostgres\-\(dq, instead of looking through the current directory for files named \(dqpostgres\-something\(dq.
.SS Escaping Characters
.sp
Some characters cannot be written directly on the command line. For these characters, so\-called escape sequences are provided. These are:
.INDENT 0.0
.IP \(bu 2
\fB\ea\fP represents the alert character.
.IP \(bu 2
\fB\ee\fP represents the escape character.
.IP \(bu 2
\fB\ef\fP represents the form feed character.
.IP \(bu 2
\fB\en\fP represents a newline character.
.IP \(bu 2
\fB\er\fP represents the carriage return character.
.IP \(bu 2
\fB\et\fP represents the tab character.
.IP \(bu 2
\fB\ev\fP represents the vertical tab character.
.IP \(bu 2
\fB\exHH\fP or \fB\eXHH\fP, where \fBHH\fP is a hexadecimal number, represents a byte of data with the specified value. For example, \fB\ex9\fP is the tab character. If you are using a multibyte encoding, this can be used to enter invalid strings. Typically fish is run with the ASCII or UTF\-8 encoding, so anything up to \fB\eX7f\fP is an ASCII character.
.IP \(bu 2
\fB\eooo\fP, where \fBooo\fP is an octal number, represents the ASCII character with the specified value. For example, \fB\e011\fP is the tab character. The highest allowed value is \fB\e177\fP\&.
.IP \(bu 2
\fB\euXXXX\fP, where \fBXXXX\fP is a hexadecimal number, represents the 16\-bit Unicode character with the specified value. For example, \fB\eu9\fP is the tab character.
.IP \(bu 2
\fB\eUXXXXXXXX\fP, where \fBXXXXXXXX\fP is a hexadecimal number, represents the 32\-bit Unicode character with the specified value. For example, \fB\eU9\fP is the tab character. The highest allowed value is U10FFFF.
.IP \(bu 2
\fB\ecX\fP, where \fBX\fP is a letter of the alphabet, represents the control sequence generated by pressing the control key and the specified letter.
For example, \fB\eci\fP is the tab character.
See C0 controls codes \% on Wikipedia.
.UNINDENT
.sp
Some characters have special meaning to the shell. For example, an apostrophe \fB\(aq\fP disables expansion (see Quotes). To tell the shell to treat these characters literally, escape them with a backslash. For example, the command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo \e\(aqhello world\e\(aq
.EE
.UNINDENT
.UNINDENT
.sp
outputs \fB\(aqhello world\(aq\fP (including the apostrophes), while the command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo \(aqhello world\(aq
.EE
.UNINDENT
.UNINDENT
.sp
outputs \fBhello world\fP (without the apostrophes). In the former case the shell treats the apostrophes as literal \fB\(aq\fP characters, while in the latter case it treats them as special expansion modifiers.
.sp
The special characters and their escape sequences are:
.INDENT 0.0
.IP \(bu 2
\fB\e\ \fP (backslash space) escapes the space character. This keeps the shell from splitting arguments on the escaped space.
.IP \(bu 2
\fB\e$\fP escapes the dollar character.
.IP \(bu 2
\fB\e\e\fP escapes the backslash character.
.IP \(bu 2
\fB\e*\fP escapes the star character.
.IP \(bu 2
\fB\e?\fP escapes the question mark character (this is not necessary if the \fBqmark\-noglob\fP feature flag is enabled).
.IP \(bu 2
\fB\e~\fP escapes the tilde character.
.IP \(bu 2
\fB\e#\fP escapes the hash character.
.IP \(bu 2
\fB\e(\fP escapes the left parenthesis character.
.IP \(bu 2
\fB\e)\fP escapes the right parenthesis character.
.IP \(bu 2
\fB\e{\fP escapes the left curly bracket character.
.IP \(bu 2
\fB\e}\fP escapes the right curly bracket character.
.IP \(bu 2
\fB\e[\fP escapes the left bracket character.
.IP \(bu 2
\fB\e]\fP escapes the right bracket character.
.IP \(bu 2
\fB\e<\fP escapes the less than character.
.IP \(bu 2
\fB\e>\fP escapes the more than character.
.IP \(bu 2
\fB\e&\fP escapes the ampersand character.
.IP \(bu 2
\fB\e|\fP escapes the vertical bar character.
.IP \(bu 2
\fB\e;\fP escapes the semicolon character.
.IP \(bu 2
\fB\e\(dq\fP escapes the quote character.
.IP \(bu 2
\fB\e\(aq\fP escapes the apostrophe character.
.UNINDENT
.sp
As a special case, \fB\e\fP immediately followed by a literal new line is a \(dqcontinuation\(dq and tells fish to ignore the line break and resume input at the start of the next line (without introducing any whitespace or terminating a token).
.SS Input/Output Redirection
.sp
Most programs use three input/output (I/O) streams:
.INDENT 0.0
.IP \(bu 2
Standard input (stdin) for reading. Defaults to reading from the keyboard.
.IP \(bu 2
Standard output (stdout) for writing output. Defaults to writing to the screen.
.IP \(bu 2
Standard error (stderr) for writing errors and warnings. Defaults to writing to the screen.
.UNINDENT
.sp
Each stream has a number called the file descriptor (FD): 0 for stdin, 1 for stdout, and 2 for stderr.
.sp
The destination of a stream can be changed using something called \fIredirection\fP\&. For example, \fBecho hello > output.txt\fP, redirects the standard output of the \fBecho\fP command to a text file.
.INDENT 0.0
.IP \(bu 2
To read standard input from a file, use \fBDESTINATION\fP\&.
.IP \(bu 2
To write standard error to a file, use \fB2>DESTINATION\fP\&. [1]
.IP \(bu 2
To append standard output to a file, use \fB>>DESTINATION_FILE\fP\&.
.IP \(bu 2
To append standard error to a file, use \fB2>>DESTINATION_FILE\fP\&.
.IP \(bu 2
To not overwrite (\(dqclobber\(dq) an existing file, use \fB>?DESTINATION\fP or \fB2>?DESTINATION\fP\&. This is known as the \(dqnoclobber\(dq redirection.
.UNINDENT
.sp
\fBDESTINATION\fP can be one of the following:
.INDENT 0.0
.IP \(bu 2
A filename to write the output to. Often \fB>/dev/null\fP to silence output by writing it to the special \(dqsinkhole\(dq file.
.IP \(bu 2
An ampersand (\fB&\fP) followed by the number of another file descriptor like \fB&2\fP for standard error. The output will be written to the destination descriptor.
.IP \(bu 2
An ampersand followed by a minus sign (\fB&\-\fP). The file descriptor will be closed. Note: This may cause the program to fail because its writes will be unsuccessful.
.UNINDENT
.sp
As a convenience, the redirection \fB&>\fP can be used to direct both stdout and stderr to the same destination. For example, \fBecho hello &> all_output.txt\fP redirects both stdout and stderr to the file \fBall_output.txt\fP\&. This is equivalent to \fBecho hello > all_output.txt 2>&1\fP\&. You can also use \fB&>>\fP to append both stdout and stderr to the same destination.
.sp
Any arbitrary file descriptor can be used in a redirection by prefixing the redirection with the FD number.
.INDENT 0.0
.IP \(bu 2
To redirect the input of descriptor N, use \fBNDESTINATION\fP\&.
.IP \(bu 2
To append the output of descriptor N to a file, use \fBN>>DESTINATION_FILE\fP\&.
.UNINDENT
.sp
File descriptors cannot be used with a \fB\fP input redirection, only a regular \fB<\fP one.
.sp
For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Write \(gafoo\(ga\(aqs standard error (file descriptor 2)
# to a file called \(dqoutput.stderr\(dq:
foo 2> output.stderr
# if $num doesn\(aqt contain a number,
# this test will be false and print an error,
# so by ignoring the error we can be sure that we\(aqre dealing
# with a number in the \(dqif\(dq block:
if test \(dq$num\(dq \-gt 2 2>/dev/null
# do things with $num as a number greater than 2
else
# do things if $num is <= 2 or not a number
end
# Save \(gamake\(gas output in a file:
make &>/log
# Redirections stack and can be used with blocks:
begin
echo stdout
echo stderr >&2 # <\- this goes to stderr!
end >/dev/null # ignore stdout, so this prints \(dqstderr\(dq
# print all lines that include \(dqfoo\(dq from myfile, or nothing if it doesn\(aqt exist.
string match \(aq*foo*\(aq | less
.EE
.UNINDENT
.UNINDENT
.sp
will attempt to build \fBfish\fP, and any errors will be shown using the \fBless\fP pager. [2]
.sp
As a convenience, the pipe \fB&|\fP (as well as the \fB|&\fP alias which is also supported by Bash) both redirect stdout and stderr to the same process.
.IP [2] 5
A \(dqpager\(dq here is a program that takes output and \(dqpaginates\(dq it. \fBless\fP doesn\(aqt just do pages, it allows arbitrary scrolling (even back!).
.SS Combining pipes and redirections
.sp
It is possible to use multiple redirections and a pipe at the same time. In that case, they are read in this order:
.INDENT 0.0
.IP 1. 3
First the pipe is set up.
.IP 2. 3
Then the redirections are evaluated from left\-to\-right.
.UNINDENT
.sp
This is important when any redirections reference other file descriptors with the \fB&N\fP syntax. When you say \fB>&2\fP, that will redirect stdout to where stderr is pointing to \fIat that time\fP\&.
.sp
Consider this helper function:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Make a function that prints something to stdout and stderr
function print
echo out
echo err >&2
end
.EE
.UNINDENT
.UNINDENT
.sp
Now let\(aqs see a few cases:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Redirect both stderr and stdout to less
print 2>&1 | less
# or
print &| less
# Show the \(dqout\(dq on stderr, silence the \(dqerr\(dq
print >&2 2>/dev/null
# Silence both
print >/dev/null 2>&1
.EE
.UNINDENT
.UNINDENT
.SS Job control
.sp
When you start a job in fish, fish itself will pause, and give control of the terminal to the program it just started. Sometimes, you want to continue using the commandline, and have the job run in the background. To create a background job, append an \fB&\fP (ampersand) to your command. This will tell fish to run the job in the background. Background jobs are very useful when running programs that have a graphical user interface.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
emacs &
.EE
.UNINDENT
.UNINDENT
.sp
will start the emacs text editor in the background. fg \%<> can be used to bring it into the foreground again when needed.
.sp
Most programs allow you to suspend the program\(aqs execution and return control to fish by pressing \fBctrl\fP\-\fBz\fP (also referred to as \fB^Z\fP). Once back at the fish commandline, you can start other programs and do anything you want. If you then want you can go back to the suspended command by using the fg \%<> (foreground) command.
.sp
If you instead want to put a suspended job into the background, use the bg \%<> command.
.sp
To get a listing of all currently started jobs, use the jobs \%<> command.
These listed jobs can be removed with the disown \%<> command.
.sp
At the moment, functions cannot be started in the background. Functions that are stopped and then restarted in the background using the bg \%<> command will not execute correctly.
.sp
If the \fB&\fP character is followed by a non\-separating character, it is not interpreted as background operator. Separating characters are whitespace and the characters \fB;<>&|\fP\&.
.SS Functions
.sp
Functions are programs written in the fish syntax. They group together various commands and their arguments using a single name.
.sp
For example, here\(aqs a simple function to list directories:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function ll
ls \-l $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
The first line tells fish to define a function by the name of \fBll\fP, so it can be used by writing \fBll\fP on the commandline. The second line tells fish that the command \fBls \-l $argv\fP should be called when \fBll\fP is invoked. $argv is a list variable, which always contains all arguments sent to the function. In the example above, these are passed on to the \fBls\fP command. The \fBend\fP on the third line ends the definition.
.sp
Calling this as \fBll /tmp/\fP will end up running \fBls \-l /tmp/\fP, which will list the contents of /tmp.
.sp
This is a kind of function known as an alias\&.
.sp
fish\(aqs prompt is also defined in a function, called fish_prompt \%<>\&. It is run when the prompt is about to be displayed and its output forms the prompt:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
# A simple prompt. Displays the current directory
# (which fish stores in the $PWD variable)
# and then a user symbol \- a \(aq►\(aq for a normal user and a \(aq#\(aq for root.
set \-l user_char \(aq►\(aq
if fish_is_root_user
set user_char \(aq#\(aq
end
echo (set_color yellow)$PWD (set_color purple)$user_char
end
.EE
.UNINDENT
.UNINDENT
.sp
To edit a function, you can use funced \%<>, and to save a function funcsave \%<>\&. This will store it in a function file that fish will autoload when needed.
.sp
The functions \%<> builtin can show a function\(aqs current definition (and type \%<> will also do if given a function).
.sp
For more information on functions, see the documentation for the function \%<> builtin.
.SS Defining aliases
.sp
One of the most common uses for functions is to slightly alter the behavior of an already existing command. For example, one might want to redefine the \fBls\fP command to display colors. The switch for turning on colors on GNU systems is \fB\-\-color=auto\fP\&. An alias around \fBls\fP might look like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function ls
command ls \-\-color=auto $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
There are a few important things that need to be noted about aliases:
.INDENT 0.0
.IP \(bu 2
Always take care to add the $argv variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command.
.IP \(bu 2
If the alias has the same name as the aliased command, you need to prefix the call to the program with \fBcommand\fP to tell fish that the function should not call itself, but rather a command with the same name. If you forget to do so, the function would call itself until the end of time. Usually fish is smart enough to figure this out and will refrain from doing so (which is hopefully in your interest).
.UNINDENT
.sp
To easily create a function of this form, you can use the alias \%<> command. Unlike other shells, this just makes functions \- fish has no separate concept of an \(dqalias\(dq, we just use the word for a simple wrapping function like this. alias \%<> immediately creates a function. Consider using \fBalias \-\-save\fP or funcsave \%<> to save the created function into an autoload file instead of recreating the alias each time.
.sp
For an alternative, try abbreviations \%<#\:abbreviations>\&. These are words that are expanded while you type, instead of being actual functions inside the shell.
.SS Autoloading functions
.sp
Functions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. This has some advantages:
.INDENT 0.0
.IP \(bu 2
An autoloaded function becomes available automatically to all running shells.
.IP \(bu 2
If the function definition is changed, all running shells will automatically reload the altered version, after a while.
.IP \(bu 2
Startup time and memory usage is improved, etc.
.UNINDENT
.sp
When fish needs to load a function, it searches through any directories in the list variable \fB$fish_function_path\fP for a file with a name consisting of the name of the function plus the suffix \fB\&.fish\fP and loads the first it finds.
.sp
For example if you try to execute something called \fBbanana\fP, fish will go through all directories in $fish_function_path looking for a file called \fBbanana.fish\fP and load the first one it finds.
.sp
By default \fB$fish_function_path\fP contains the following:
.INDENT 0.0
.IP \(bu 2
A directory for users to keep their own functions, usually \fB~/.config/fish/functions\fP (controlled by the \fBXDG_CONFIG_HOME\fP environment variable).
.IP \(bu 2
A directory for functions for all users on the system, usually \fB/etc/fish/functions\fP (really \fB$__fish_sysconfdir/functions\fP).
.IP \(bu 2
Directories for other software to put their own functions. These are in the directories under \fB$__fish_user_data_dir\fP (usually \fB~/.local/share/fish\fP, controlled by the \fBXDG_DATA_HOME\fP environment variable) and in the \fBXDG_DATA_DIRS\fP environment variable, in a subdirectory called \fBfish/vendor_functions.d\fP\&. The default value for \fBXDG_DATA_DIRS\fP is usually \fB/usr/share/fish/vendor_functions.d\fP and \fB/usr/local/share/fish/vendor_functions.d\fP\&.
.UNINDENT
.sp
If you are unsure, your functions probably belong in \fB~/.config/fish/functions\fP\&.
.sp
As we\(aqve explained, autoload files are loaded \fIby name\fP, so, while you can put multiple functions into one file, the file will only be loaded automatically once you try to execute the one that shares the name.
.sp
Autoloading also won\(aqt work for event handlers, since fish cannot know that a function is supposed to be executed when an event occurs when it hasn\(aqt yet loaded the function. See the event handlers section for more information.
.sp
If a file of the right name doesn\(aqt define the function, fish will not read other autoload files, instead it will go on to try builtins and finally commands. This allows masking a function defined later in $fish_function_path, e.g. if your administrator has put something into /etc/fish/functions that you want to skip.
.sp
If you are developing another program and want to install fish functions for it, install them to the \(dqvendor\(dq functions directory. As this path varies from system to system, you can use \fBpkgconfig\fP to discover it with the output of \fBpkg\-config \-\-variable functionsdir fish\fP\&. Your installation system should support a custom path to override the pkgconfig path, as other distributors may need to alter it easily.
.SS Comments
.sp
Anything after a \fB#\fP until the end of the line is a comment. That means it\(aqs purely for the reader\(aqs benefit, fish ignores it.
.sp
This is useful to explain what and why you are doing something:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function ls
# The function is called ls,
# so we have to explicitly call \(gacommand ls\(ga to avoid calling ourselves.
command ls \-\-color=auto $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
There are no multiline comments. If you want to make a comment span multiple lines, start each line with a \fB#\fP\&.
.sp
Comments can also appear after a line like so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-gx EDITOR emacs # I don\(aqt like vim.
.EE
.UNINDENT
.UNINDENT
.SS Conditions
.sp
fish has some builtins that let you execute commands only if a specific criterion is met: if \%<>, switch \%<>, and \%<> and or \%<>, and also the familiar &&/|| syntax.
.SS The \fBif\fP statement
.sp
The if \%<> statement runs a block of commands if the condition was true.
.sp
Like other shells, but unlike typical programming languages you might know, the condition here is a \fIcommand\fP\&. fish runs it, and if it returns a true exit status (that\(aqs 0), the if\-block is run. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-e /etc/os\-release
cat /etc/os\-release
end
.EE
.UNINDENT
.UNINDENT
.sp
This uses the test \%<> command to see if the file /etc/os\-release exists. If it does, it runs \fBcat\fP, which prints it on the screen.
.sp
Unlike other shells, the condition command ends after the first job, there is no \fBthen\fP here. Combiners like \fBand\fP and \fBor\fP extend the condition.
.sp
A more complicated example with a command substitution:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \(dq$(uname)\(dq = Linux
echo I like penguins
end
.EE
.UNINDENT
.UNINDENT
.sp
Because \fBtest\fP can be used for many different tests, it is important to quote variables and command substitutions. If the \fB$(uname)\fP was not quoted, and \fBuname\fP printed nothing it would run \fBtest = Linux\fP, which is an error.
.sp
\fBif\fP can also take \fBelse if\fP clauses with additional conditions and an else \%<> clause that is executed when everything else was false:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \(dq$number\(dq \-gt 10
echo Your number was greater than 10
else if test \(dq$number\(dq \-gt 5
echo Your number was greater than 5
else if test \(dq$number\(dq \-gt 1
echo Your number was greater than 1
else
echo Your number was smaller or equal to 1
end
.EE
.UNINDENT
.UNINDENT
.sp
The not \%<> keyword can be used to invert the status:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Check if the file contains the string \(dqfish\(dq anywhere.
# This executes the \(gagrep\(ga command, which searches for a string,
# and if it finds it returns a status of 0.
# The \(ganot\(ga then turns 0 into 1 or anything else into 0.
# The \(ga\-q\(ga switch stops it from printing any matches.
if not grep \-q fish myanimals
echo \(dqYou don\(aqt have fish!\(dq
else
echo \(dqYou have fish!\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
Other things commonly used in if\-conditions:
.INDENT 0.0
.IP \(bu 2
contains \%<> \- to see if a list contains a specific element (\fBif contains \-\- /usr/bin $PATH\fP)
.IP \(bu 2
string \%<> \- to e.g. match strings (\fBif string match \-q \-\- \(aq*\-\(aq $arg\fP)
.IP \(bu 2
path \%<> \- to check if paths of some criteria exist (\fBif path is \-rf \-\- ~/.config/fish/config.fish\fP)
.IP \(bu 2
type \%<> \- to see if a command, function or builtin exists (\fBif type \-q git\fP)
.UNINDENT
.SS The \fBswitch\fP statement
.sp
The switch \%<> command is used to execute one of possibly many blocks of commands depending on the value of a string. It can take multiple case \%<> blocks that are executed when the string matches. They can take wildcards\&. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
switch (uname)
case Linux
echo Hi Tux!
case Darwin
echo Hi Hexley!
case DragonFly \(aq*BSD\(aq
echo Hi Beastie! # this also works for FreeBSD and NetBSD
case \(aq*\(aq
echo Hi, stranger!
end
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells or programming languages, there is no fallthrough \- the first matching \fBcase\fP block is executed and then control jumps out of the \fBswitch\fP\&.
.SS Combiners (\fBand\fP / \fBor\fP / \fB&&\fP / \fB||\fP)
.sp
For simple checks, you can use combiners. and \%<> or \fB&&\fP run the second command if the first succeeded, while or \%<> or \fB||\fP run it if the first failed. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# $XDG_CONFIG_HOME is a standard place to store configuration.
# If it\(aqs not set applications should use ~/.config.
set \-q XDG_CONFIG_HOME; and set \-l configdir $XDG_CONFIG_HOME
or set \-l configdir ~/.config
.EE
.UNINDENT
.UNINDENT
.sp
Note that combiners are \fIlazy\fP \- only the part that is necessary to determine the final status is run.
.sp
Compare:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if sleep 2; and false
echo \(aqHow did I get here? This should be impossible\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
and:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if false; and sleep 2
echo \(aqHow did I get here? This should be impossible\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
These do essentially the same thing, but the former takes 2 seconds longer because the \fBsleep\fP always needs to run.
.sp
Or you can have a case where it is necessary to stop early:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if command \-sq foo; and foo
.EE
.UNINDENT
.UNINDENT
.sp
If this went on after seeing that the command \(dqfoo\(dq doesn\(aqt exist, it would try to run \fBfoo\fP and error because it wasn\(aqt found!
.sp
Combiners execute step\-by\-step, so it isn\(aqt recommended to build longer chains of them because they might do something you don\(aqt want. Consider:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
test \-e /etc/my.config
or echo \(dqOH NO WE NEED A CONFIG FILE\(dq
and return 1
.EE
.UNINDENT
.UNINDENT
.sp
This will execute \fBreturn 1\fP also if the \fBtest\fP succeeded. This is because fish runs \fBtest \-e /etc/my.config\fP, sets $status to 0, then skips the \fBecho\fP, keeps $status at 0, and then executes the \fBreturn 1\fP because $status is still 0.
.sp
So if you have more complex conditions or want to run multiple things after something failed, consider using an if\&. Here that would be:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if not test \-e /etc/my.config
echo \(dqOH NO WE NEED A CONFIG FILE\(dq
return 1
end
.EE
.UNINDENT
.UNINDENT
.SS Loops and blocks
.sp
Like most programming language, fish also has the familiar while \%<> and for \%<> loops.
.sp
\fBwhile\fP works like a repeated if:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
while true
echo Still running
sleep 1
end
.EE
.UNINDENT
.UNINDENT
.sp
will print \(dqStill running\(dq once a second. You can abort it with ctrl\-c.
.sp
\fBfor\fP loops work like in other shells, which is more like python\(aqs for\-loops than e.g. C\(aqs:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for file in *
echo file: $file
end
.EE
.UNINDENT
.UNINDENT
.sp
will print each file in the current directory. The part after the \fBin\fP is a list of arguments, so you can use any expansions there:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set moreanimals bird fox
for animal in {cat,}fish dog $moreanimals
echo I like the $animal
end
.EE
.UNINDENT
.UNINDENT
.sp
If you need a list of numbers, you can use the \fBseq\fP command to create one:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in (seq 1 5)
echo $i
end
.EE
.UNINDENT
.UNINDENT
.sp
break \%<> is available to break out of a loop, and continue \%<> to jump to the next iteration.
.sp
Input and output redirections (including pipes) can also be applied to loops:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
while read \-l line
echo line: $line
end < file
.EE
.UNINDENT
.UNINDENT
.sp
In addition there\(aqs a begin \%<> block that just groups commands together so you can redirect to a block or use a new variable scope without any repetition:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
begin
set \-l foo bar # this variable will only be available in this block!
end
.EE
.UNINDENT
.UNINDENT
.SS Parameter expansion
.sp
When fish is given a commandline, it expands the parameters before sending them to the command. There are multiple different kinds of expansions:
.INDENT 0.0
.IP \(bu 2
Wildcards, to create filenames from patterns \- \fB*.jpg\fP
.IP \(bu 2
Variable expansion, to use the value of a variable \- \fB$HOME\fP
.IP \(bu 2
Command substitution, to use the output of another command \- \fB$(cat /path/to/file)\fP
.IP \(bu 2
Brace expansion, to write lists with common pre\- or suffixes in a shorter way \fB{/usr,}/bin\fP
.IP \(bu 2
Tilde expansion, to turn the \fB~\fP at the beginning of paths into the path to the home directory \fB~/bin\fP
.UNINDENT
.sp
Parameter expansion is limited to 524288 items. There is a limit to how many arguments the operating system allows for any command, and 524288 is far above it. This is a measure to stop the shell from hanging doing useless computation.
.SS Wildcards (\(dqGlobbing\(dq)
.sp
When a parameter includes an unquoted \fB*\fP star (or \(dqasterisk\(dq) or a \fB?\fP question mark, fish uses it as a wildcard to match files.
.INDENT 0.0
.IP \(bu 2
\fB*\fP matches any number of characters (including zero) in a file name, not including \fB/\fP\&.
.IP \(bu 2
\fB**\fP matches any number of characters (including zero), and also descends into subdirectories. If \fB**\fP is a segment by itself, that segment may match zero times, for compatibility with other shells.
.IP \(bu 2
\fB?\fP can match any single character except \fB/\fP\&. This is deprecated and can be disabled via the \fBqmark\-noglob\fP feature flag, so \fB?\fP will be an ordinary character.
.UNINDENT
.sp
Wildcard matches are sorted case insensitively. When sorting matches containing numbers, they are naturally sorted, so that the strings \(aq1\(aq \(aq5\(aq and \(aq12\(aq would be sorted like 1, 5, 12.
.sp
Hidden files (where the name begins with a dot) are not considered when wildcarding unless the wildcard string has a dot in that place.
.sp
Wildcards never expand to \fB\&.\fP (current directory) or \fB\&..\fP (parent directory).
.sp
Examples:
.INDENT 0.0
.IP \(bu 2
\fBa*\fP matches any files beginning with an \(aqa\(aq in the current directory.
.IP \(bu 2
\fB**\fP matches any files and directories in the current directory and all of its subdirectories.
.IP \(bu 2
\fB~/.*\fP matches all hidden files (also known as \(dqdotfiles\(dq) and directories in your home directory.
.UNINDENT
.sp
For most commands, if any wildcard fails to expand, the command is not executed, $status is set to nonzero, and a warning is printed. This behavior is like what bash does with \fBshopt \-s failglob\fP\&. There are exceptions, namely set \%<> and path \%<>, overriding variables in overrides, count \%<> and for \%<>\&. Their globs will instead expand to zero arguments (so the command won\(aqt see them at all), like with \fBshopt \-s nullglob\fP in bash.
.sp
Examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# List the .foo files, or warns if there aren\(aqt any.
ls *.foo
# List the .foo files, if any.
set foos *.foo
if count $foos >/dev/null
ls $foos
end
.EE
.UNINDENT
.UNINDENT
.sp
Unlike bash (by default), fish will not pass on the literal glob character if no match was found, so for a command like \fBapt install\fP that does the matching itself, you need to add quotes:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
apt install \(dqncurses\-*\(dq
.EE
.UNINDENT
.UNINDENT
.SS Variable expansion
.sp
One of the most important expansions in fish is the \(dqvariable expansion\(dq. This is the replacing of a dollar sign (\fB$\fP) followed by a variable name with the _value_ of that variable.
.sp
A simple example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo $HOME
.EE
.UNINDENT
.UNINDENT
.sp
which will replace \fB$HOME\fP with the home directory of the current user, and pass it to echo \%<>, which will then print it.
.sp
Some variables like \fB$HOME\fP are already set because fish sets them by default or because fish\(aqs parent process passed them to fish when it started it. You can define your own variables by setting them with set \%<>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set my_directory /home/cooluser/mystuff
ls $my_directory
# shows the contents of /home/cooluser/mystuff
.EE
.UNINDENT
.UNINDENT
.sp
For more on how setting variables works, see Shell variables and the following sections.
.sp
Sometimes a variable has no value because it is undefined or empty, and it expands to nothing:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo $nonexistentvariable
# Prints no output.
.EE
.UNINDENT
.UNINDENT
.sp
To separate a variable name from text you can encase the variable within double\-quotes or braces:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set WORD cat
echo The plural of $WORD is \(dq$WORD\(dqs
# Prints \(dqThe plural of cat is cats\(dq because $WORD is set to \(dqcat\(dq.
echo The plural of $WORD is {$WORD}s
# ditto
.EE
.UNINDENT
.UNINDENT
.sp
Without the quotes or braces, fish will try to expand a variable called \fB$WORDs\fP, which may not exist.
.sp
The latter syntax \fB{$WORD}\fP is a special case of brace expansion\&.
.sp
If $WORD here is undefined or an empty list, the \(dqs\(dq is not printed. However, it is printed if $WORD is the empty string (like after \fBset WORD \(dq\(dq\fP).
.sp
For more on shell variables, read the Shell variables section.
.SS Quoting variables
.sp
Variable expansion also happens in double quoted strings. Inside double quotes (\fB\(dqthese\(dq\fP), variables will always expand to exactly one argument. If they are empty or undefined, it will result in an empty string. If they have one element, they\(aqll expand to that element. If they have more than that, the elements will be joined with spaces, unless the variable is a path variable \- in that case it will use a colon (\fB:\fP) instead [3]\&.
.sp
fish variables are all lists, and they are split into elements when they are \fIset\fP \- that means it is important to decide whether to use quotes or not with set \%<>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set foo 1 2 3 # a variable with three elements
rm $foo # runs the equivalent of \(garm 1 2 3\(ga \- trying to delete three files: 1, 2 and 3.
rm \(dq$foo\(dq # runs \(garm \(aq1 2 3\(aq\(ga \- trying to delete one file called \(aq1 2 3\(aq
set foo # an empty variable
rm $foo # runs \(garm\(ga without arguments
rm \(dq$foo\(dq # runs the equivalent of \(garm \(aq\(aq\(ga
set foo \(dq1 2 3\(dq
rm $foo # runs the equivalent of \(garm \(aq1 2 3\(aq\(ga \- trying to delete one file
rm \(dq$foo\(dq # same thing
.EE
.UNINDENT
.UNINDENT
.sp
This is unlike other shells, which do what is known as \(dqWord Splitting\(dq, where they split the variable when it is \fIused\fP in an expansion. E.g. in bash:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
foo=\(dq1 2 3\(dq
rm $foo # runs the equivalent of \(garm 1 2 3\(ga
rm \(dq$foo\(dq # runs the equivalent of \(garm \(aq1 2 3\(aq\(ga
.EE
.UNINDENT
.UNINDENT
.sp
This is the cause of very common problems with filenames with spaces in bash scripts.
.sp
In fish, unquoted variables will expand to as many arguments as they have elements. That means an empty list will expand to nothing, a variable with one element will expand to that element, and a variable with multiple elements will expand to each of those elements separately.
.sp
If a variable expands to nothing, it will cancel out any other strings attached to it. See the Combining Lists section for more information.
.sp
Most of the time, not quoting a variable is correct. The exception is when you need to ensure that the variable is passed as one element, even if it might be unset or have multiple elements. This happens often with test \%<>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l foo one two three
test \-n $foo
# prints an error that it got too many arguments, because it was executed like
test \-n one two three
test \-n \(dq$foo\(dq
# works, because it was executed like
test \-n \(dqone two three\(dq
.EE
.UNINDENT
.UNINDENT
.IP [3] 5
Unlike bash or zsh, which will join with the first character of $IFS (which usually is space).
.SS Dereferencing variables
.sp
The \fB$\fP symbol can also be used multiple times, as a kind of \(dqdereference\(dq operator (the \fB*\fP in C or C++), like in the following code:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set foo a b c
set a 10; set b 20; set c 30
for i in (seq (count $$foo))
echo $$foo[$i]
end
# Output is:
# 10
# 20
# 30
.EE
.UNINDENT
.UNINDENT
.sp
\fB$$foo[$i]\fP is \(dqthe value of the variable named by \fB$foo[$i]\fP\(dq.
.sp
This can also be used to give a variable name to a function:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function print_var
for arg in $argv
echo Variable $arg is $$arg
end
end
set \-g foo 1 2 3
set \-g bar a b c
print_var foo bar
# prints \(dqVariable foo is 1 2 3\(dq and \(dqVariable bar is a b c\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Of course the variable will have to be accessible from the function, so it needs to be global/universal or exported\&. It also can\(aqt clash with a variable name used inside the function. So if we had made $foo there a local variable, or if we had named it \(dqarg\(dq instead, it would not have worked.
.sp
When using this feature together with slices, the slices will be used from the inside out. \fB$$foo[5]\fP will use the fifth element of \fB$foo\fP as a variable name, instead of giving the fifth element of all the variables $foo refers to. That would instead be expressed as \fB$$foo[1..\-1][5]\fP (take all elements of \fB$foo\fP, use them as variable names, then give the fifth element of those).
.sp
Some more examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set listone 1 2 3
set listtwo 4 5 6
set var listone listtwo
echo $$var
# Output is 1 2 3 4 5 6
echo $$var[1]
# Output is 1 2 3
echo $$var[2][3]
# $var[2] is listtwo, third element of that is 6, output is 6
echo $$var[..][2]
# The second element of every variable, so output is 2 5
.EE
.UNINDENT
.UNINDENT
.SS Variables as command
.sp
Like other shells, you can run the value of a variable as a command.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-g EDITOR emacs
> $EDITOR foo # opens emacs, possibly the GUI version
.EE
.UNINDENT
.UNINDENT
.sp
If you want to give the command an argument inside the variable it needs to be a separate element:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set EDITOR emacs \-nw
> $EDITOR foo # opens emacs in the terminal even if the GUI is installed
> set EDITOR \(dqemacs \-nw\(dq
> $EDITOR foo # tries to find a command called \(dqemacs \-nw\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Also like other shells, this only works with commands, builtins and functions \- it will not work with keywords because they have syntactical importance.
.sp
For instance \fBset if $if\fP won\(aqt allow you to make an if\-block, and \fBset cmd command\fP won\(aqt allow you to use the command \%<> decorator, but only uses like \fB$cmd \-q foo\fP\&.
.SS Command substitution
.sp
A \fBcommand substitution\fP is an expansion that uses the \fIoutput\fP of a command as the arguments to another. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo $(pwd)
.EE
.UNINDENT
.UNINDENT
.sp
This executes the pwd \%<> command, takes its output (more specifically what it wrote to the standard output \(dqstdout\(dq stream) and uses it as arguments to echo \%<>\&. So the inner command (the \fBpwd\fP) is run first and has to complete before the outer command can even be started.
.sp
If the inner command prints multiple lines, fish will use each separate line as a separate argument to the outer command. Unlike other shells, the value of \fB$IFS\fP is not used [4], fish splits on newlines.
.sp
Command substitutions can also be double\-quoted:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo \(dq$(pwd)\(dq
.EE
.UNINDENT
.UNINDENT
.sp
When using double quotes, the command output is not split up by lines, but trailing empty lines are still removed.
.sp
If the output is piped to string split or string split0 \%<> as the last step, those splits are used as they appear instead of splitting lines.
.sp
fish also allows spelling command substitutions without the dollar, like \fBecho (pwd)\fP\&. This variant will not be expanded in double\-quotes (\fBecho \(dq(pwd)\(dq\fP will print \fB(pwd)\fP).
.sp
The exit status of the last run command substitution is available in the status variable if the substitution happens in the context of a set \%<> command (so \fBif set \-l (something)\fP checks if \fBsomething\fP returned true).
.sp
To use only some lines of the output, refer to slices\&.
.sp
Examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Outputs \(aqimage.png\(aq.
echo (basename image.jpg .jpg).png
# Convert all JPEG files in the current directory to the
# PNG format using the \(aqconvert\(aq program.
for i in *.jpg; convert $i (basename $i .jpg).png; end
# Set the \(ga\(gadata\(ga\(ga variable to the contents of \(aqdata.txt\(aq
# without splitting it into a list.
set data \(dq$(cat data.txt)\(dq
# Set \(ga\(ga$data\(ga\(ga to the contents of data, splitting on NUL\-bytes.
set data (cat data | string split0)
.EE
.UNINDENT
.UNINDENT
.sp
Sometimes you want to pass the output of a command to another command that only accepts files. If it\(aqs just one file, you can usually pass it via a pipe, like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
grep fish myanimallist1 | wc \-l
.EE
.UNINDENT
.UNINDENT
.sp
but if you need multiple or the command doesn\(aqt read from standard input, \(dqprocess substitution\(dq is useful. Other shells allow this via \fBfoo <(bar) <(baz)\fP, and fish uses the psub \%<> command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Compare only the lines containing \(dqfish\(dq in two files:
diff \-u (grep fish myanimallist1 | psub) (grep fish myanimallist2 | psub)
.EE
.UNINDENT
.UNINDENT
.sp
This creates a temporary file, stores the output of the command in that file and prints the filename, so it is given to the outer command.
.sp
fish has a default limit of 1 GiB on the data it will read in a command substitution. If that limit is reached the command (all of it, not just the command substitution \- the outer command won\(aqt be executed at all) fails and \fB$status\fP is set to 122. This is so command substitutions can\(aqt cause the system to go out of memory, because typically your operating system has a much lower limit, so reading more than that would be useless and harmful. This limit can be adjusted with the \fBfish_read_limit\fP variable (\fI0\fP meaning no limit). This limit also affects the read \%<> command.
.IP [4] 5
One exception: Setting \fB$IFS\fP to empty will disable line splitting. This is deprecated, use string split \%<> instead.
.SS Brace expansion
.sp
Curly braces can be used to write comma\-separated lists. They will be expanded with each element becoming a new parameter, with the surrounding string attached. This is useful to save on typing, and to separate a variable name from surrounding text.
.sp
Examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo input.{c,h,txt}
input.c input.h input.txt
# Move all files with the suffix \(aq.c\(aq or \(aq.h\(aq to the subdirectory src.
> mv *.{c,h} src/
# Make a copy of \(gafile\(ga at \(gafile.bak\(ga.
> cp file{,.bak}
> set \-l dogs hot cool cute \(dqgood \(dq
> echo {$dogs}dog
hotdog cooldog cutedog good dog
.EE
.UNINDENT
.UNINDENT
.sp
If there is no \(dq,\(dq or variable expansion between the curly braces, they will not be expanded:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# This {} isn\(aqt special
> echo foo\-{}
foo\-{}
# This passes \(dqHEAD@{2}\(dq to git
> git reset \-\-hard HEAD@{2}
> echo {{a,b}}
{a} {b} # because the inner brace pair is expanded, but the outer isn\(aqt.
.EE
.UNINDENT
.UNINDENT
.sp
If after expansion there is nothing between the braces, the argument will be removed (see the Combining Lists section):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo foo\-{$undefinedvar}
# Output is an empty line, like a bare \(gaecho\(ga.
.EE
.UNINDENT
.UNINDENT
.sp
If there is nothing between a brace and a comma or two commas, it\(aqs interpreted as an empty element:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo {,,/usr}/bin
/bin /bin /usr/bin
.EE
.UNINDENT
.UNINDENT
.sp
To use a \(dq,\(dq as an element, quote or escape it.
.sp
The very first character of a command token is never interpreted as expanding brace, because it\(aqs the beginning of a compound statement \%<>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> {echo hello, && echo world}
hello,
world
.EE
.UNINDENT
.UNINDENT
.SS Combining lists
.sp
fish expands lists like brace expansions:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ set \-l foo x y z
>_ echo 1$foo
# Any element of $foo is combined with the \(dq1\(dq:
1x 1y 1z
>_ echo {good,bad}\(dq apples\(dq
# Any element of the {} is combined with the \(dq apples\(dq:
good apples bad apples
# Or we can mix the two:
>_ echo {good,bad}\(dq \(dq$foo
good x bad x good y bad y good z bad z
.EE
.UNINDENT
.UNINDENT
.sp
Any string attached to a list will be concatenated to each element.
.sp
Two lists will be expanded in all combinations \- every element of the first with every element of the second:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ set \-l a x y z; set \-l b 1 2 3
>_ echo $a$b # same as {x,y,z}{1,2,3}
x1 y1 z1 x2 y2 z2 x3 y3 z3
.EE
.UNINDENT
.UNINDENT
.sp
A result of this is that, if a list has no elements, this combines the string with no elements, which means the entire token is removed!
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ set \-l c # <\- this list is empty!
>_ echo {$c}word
# Output is an empty line \- the \(dqword\(dq part is gone
.EE
.UNINDENT
.UNINDENT
.sp
This can be quite useful. For example, if you want to go through all the files in all the directories in \fBPATH\fP, use
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for file in $PATH/*
.EE
.UNINDENT
.UNINDENT
.sp
Because \fBPATH\fP is a list, this expands to all the files in all the directories in it. And if there are no directories in \fBPATH\fP, the right answer here is to expand to no files.
.sp
Sometimes this may be unwanted, especially that tokens can disappear after expansion. In those cases, you should double\-quote variables \- \fBecho \(dq$c\(dqword\fP\&.
.sp
This also happens after command substitution\&. To avoid tokens disappearing there, make the inner command return a trailing newline, or double\-quote it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ set b 1 2 3
>_ echo (echo x)$b
x1 x2 x3
>_ echo (printf \(aq%s\(aq \(aq\(aq)banana
# the printf prints nothing, so this is nothing times \(dqbanana\(dq,
# which is nothing.
>_ echo (printf \(aq%s\en\(aq \(aq\(aq)banana
# the printf prints a newline,
# so the command substitution expands to an empty string,
# so this is \(ga\(aq\(aqbanana\(ga
banana
>_ echo \(dq$(printf \(aq%s\(aq \(aq\(aq)\(dqbanana
# quotes mean this is one argument, the banana stays
.EE
.UNINDENT
.UNINDENT
.SS Slices
.sp
Sometimes it\(aqs necessary to access only some of the elements of a list (all fish variables are lists), or some of the lines a command substitution outputs. Both are possible in fish by writing a set of indices in brackets, like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Make $var a list of four elements
set var one two three four
# Print the second:
echo $var[2]
# prints \(dqtwo\(dq
# or print the first three:
echo $var[1..3]
# prints \(dqone two three\(dq
.EE
.UNINDENT
.UNINDENT
.sp
In index brackets, fish understands ranges written like \fBa..b\fP (\(aqa\(aq and \(aqb\(aq being indices). They are expanded into a sequence of indices from a to b (so \fBa a+1 a+2 ... b\fP), going up if b is larger and going down if a is larger. Negative indices can also be used \- they are taken from the end of the list, so \fB\-1\fP is the last element, and \fB\-2\fP the one before it. If an index doesn\(aqt exist the range is clamped to the next possible index.
.sp
If a list has 5 elements the indices go from 1 to 5, so a range of \fB2..16\fP will only go from element 2 to element 5.
.sp
If the end is negative the range always goes up, so \fB2..\-2\fP will go from element 2 to 4, and \fB2..\-16\fP won\(aqt go anywhere because there is no way to go from the second element to one that doesn\(aqt exist, while going up.
If the start is negative the range always goes down, so \fB\-2..1\fP will go from element 4 to 1, and \fB\-16..2\fP won\(aqt go anywhere because there is no way to go from an element that doesn\(aqt exist to the second element, while going down.
.sp
A missing starting index in a range defaults to 1. This is allowed if the range is the first index expression of the sequence. Similarly, a missing ending index, defaulting to \-1 is allowed for the last index in the sequence.
.sp
Multiple ranges are also possible, separated with a space.
.sp
Some examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo (seq 10)[1 2 3]
# Prints: 1 2 3
# Limit the command substitution output
echo (seq 10)[2..5]
# Uses elements from 2 to 5
# Output is: 2 3 4 5
echo (seq 10)[7..]
# Prints: 7 8 9 10
# Use overlapping ranges:
echo (seq 10)[2..5 1..3]
# Takes elements from 2 to 5 and then elements from 1 to 3
# Output is: 2 3 4 5 1 2 3
# Reverse output
echo (seq 10)[\-1..1]
# Uses elements from the last output line to
# the first one in reverse direction
# Output is: 10 9 8 7 6 5 4 3 2 1
# The command substitution has only one line,
# so these will result in empty output:
echo (echo one)[2..\-1]
echo (echo one)[\-3..1]
.EE
.UNINDENT
.UNINDENT
.sp
The same works when setting or expanding variables:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Reverse path variable
set PATH $PATH[\-1..1]
# or
set PATH[\-1..1] $PATH
# Use only n last items of the PATH
set n \-3
echo $PATH[$n..\-1]
.EE
.UNINDENT
.UNINDENT
.sp
Variables can be used as indices for expansion of variables, like so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set index 2
set letters a b c d
echo $letters[$index] # returns \(aqb\(aq
.EE
.UNINDENT
.UNINDENT
.sp
However using variables as indices for command substitution is currently not supported, so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo (seq 5)[$index] # This won\(aqt work
set sequence (seq 5) # It needs to be written on two lines like this.
echo $sequence[$index] # returns \(aq2\(aq
.EE
.UNINDENT
.UNINDENT
.sp
When using indirect variable expansion with multiple \fB$\fP (\fB$$name\fP), you have to give all indices up to the variable you want to slice:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-l list 1 2 3 4 5
> set \-l name list
> echo $$name[1]
1 2 3 4 5
> echo $$name[1..\-1][1..3] # or $$name[1][1..3], since $name only has one element.
1 2 3
.EE
.UNINDENT
.UNINDENT
.SS Home directory expansion
.sp
The \fB~\fP (tilde) character at the beginning of a parameter, followed by a username, is expanded into the home directory of the specified user. A lone \fB~\fP, or a \fB~\fP followed by a slash, is expanded into the home directory of the process owner:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
ls ~/Music # lists my music directory
echo ~root # prints root\(aqs home directory, probably \(dq/root\(dq
.EE
.UNINDENT
.UNINDENT
.SS Combining different expansions
.sp
All of the above expansions can be combined. If several expansions result in more than one parameter, all possible combinations are created.
.sp
When combining multiple parameter expansions, expansions are performed in the following order:
.INDENT 0.0
.IP \(bu 2
Command substitutions
.IP \(bu 2
Variable expansions
.IP \(bu 2
Bracket expansion
.IP \(bu 2
Wildcard expansion
.UNINDENT
.sp
Expansions are performed from right to left, nested bracket expansions and command substitutions are performed from the inside and out.
.sp
Example:
.sp
If the current directory contains the files \(aqfoo\(aq and \(aqbar\(aq, the command \fBecho a(ls){1,2,3}\fP will output \fBabar1 abar2 abar3 afoo1 afoo2 afoo3\fP\&.
.SS Table Of Operators
.sp
Putting it together, here is a quick reference to fish\(aqs operators, all of the special symbols it uses:
.TS
box center;
l|l|l.
T{
Symbol
T} T{
Meaning
T} T{
Example
T}
_
T{
\fB$\fP
T} T{
Variable expansion
T} T{
\fBecho $foo\fP
T}
_
T{
\fB$()\fP and \fB()\fP
T} T{
Command substitution
T} T{
\fBcat (grep foo bar)\fP or \fBcat $(grep foo bar)\fP
T}
_
T{
\fB<\fP and \fB>\fP
T} T{
Redirection, like \fBcommand > file\fP
T} T{
\fBgit shortlog \-nse . > authors\fP
T}
_
T{
\fB|\fP
T} T{
Pipe, connect two or more commands
T} T{
\fBfoo | grep bar | grep baz\fP
T}
_
T{
\fB;\fP
T} T{
End of the command, instead of a newline
T} T{
\fBcommand1; command2\fP
T}
_
T{
\fB&\fP
T} T{
Backgrounding
T} T{
\fBsleep 5m &\fP
T}
_
T{
\fB{}\fP
T} T{
Brace expansion
T} T{
\fBls {/usr,}/bin\fP
T}
_
T{
\fB&&\fP and \fB||\fP
T} T{
Combiners
T} T{
\fBmkdir foo && cd foo\fP or \fBrm foo || exit\fP
T}
_
T{
\fB*\fP and \fB**\fP
T} T{
Wildcards
T} T{
\fBcat *.fish\fP or \fBcount **.jpg\fP
T}
_
T{
\fB\e\e\fP
T} T{
Escaping
T} T{
\fBecho foo\enbar\fP or \fBecho \e$foo\fP
T}
_
T{
\fB\(aq\(aq\fP and \fB\(dq\(dq\fP
T} T{
Quoting
T} T{
\fBrm \(dqfile with spaces\(dq\fP or \fBecho \(aq$foo\(aq\fP
T}
_
T{
\fB~\fP
T} T{
Home directory expansion
T} T{
\fBls ~/\fP or \fBls ~root/\fP
T}
_
T{
\fB#\fP
T} T{
Comments
T} T{
\fBecho Hello # this isn\(aqt printed\fP
T}
.TE
.SS Shell variables
.sp
Variables are a way to save data and pass it around. They can be used just by the shell, or they can be \(dqexported\(dq, so that a copy of the variable is available to any external command the shell starts. An exported variable is referred to as an \(dqenvironment variable\(dq.
.sp
To set a variable value, use the set \%<> command. A variable name can not be empty and can contain only letters, digits, and underscores. It may begin and end with any of those characters.
.sp
Example:
.sp
To set the variable \fBsmurf_color\fP to the value \fBblue\fP, use the command \fBset smurf_color blue\fP\&.
.sp
After a variable has been set, you can use the value of a variable in the shell through variable expansion\&.
.sp
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set smurf_color blue
echo Smurfs are usually $smurf_color
set pants_color red
echo Papa smurf, who is $smurf_color, wears $pants_color pants
.EE
.UNINDENT
.UNINDENT
.sp
So you set a variable with \fBset\fP, and use it with a \fB$\fP and the name.
.SS Variable Scope
.sp
All variables in fish have a scope. For example they can be global or local to a function or block:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# This variable is global, we can use it everywhere.
set \-\-global name Patrick
# This variable is local, it will not be visible in a function we call from here.
set \-\-local place \(dqat the Krusty Krab\(dq
function local
# This can find $name, but not $place
echo Hello this is $name $place
# This variable is local, it will not be available
# outside of this function
set \-\-local instrument mayonnaise
echo My favorite instrument is $instrument
# This creates a local $name, and won\(aqt touch the global one
set \-\-local name Spongebob
echo My best friend is $name
end
local
# Will print:
# Hello this is Patrick
# My favorite instrument is mayonnaise
# My best friend is Spongebob
echo $name, I am $place and my instrument is $instrument
# Will print:
# Patrick, I am at the Krusty Krab and my instrument is
.EE
.UNINDENT
.UNINDENT
.sp
There are four kinds of variable scopes in fish: universal, global, function and local variables.
.INDENT 0.0
.IP \(bu 2
Universal variables are shared between all fish sessions a user is running on one computer. They are stored on disk and persist even after reboot.
.IP \(bu 2
Global variables are specific to the current fish session. They can be erased by explicitly requesting \fBset \-e\fP\&.
.IP \(bu 2
Function variables are specific to the currently executing function. They are erased (\(dqgo out of scope\(dq) when the current function ends. Outside of a function, they don\(aqt go out of scope.
.IP \(bu 2
Local variables are specific to the current block of commands, and automatically erased when a specific block goes out of scope. A block of commands is a series of commands that begins with one of the commands \fBfor\fP, \fBwhile\fP , \fBif\fP, \fBfunction\fP, \fBbegin\fP or \fBswitch\fP, and ends with the command \fBend\fP\&. Outside of a block, this is the same as the function scope.
.UNINDENT
.sp
Variables can be explicitly set to be universal with the \fB\-U\fP or \fB\-\-universal\fP switch, global with \fB\-g\fP or \fB\-\-global\fP, function\-scoped with \fB\-f\fP or \fB\-\-function\fP and local to the current block with \fB\-l\fP or \fB\-\-local\fP\&. The scoping rules when creating or updating a variable are:
.INDENT 0.0
.IP \(bu 2
When a scope is explicitly given, it will be used. If a variable of the same name exists in a different scope, that variable will not be changed.
.IP \(bu 2
When no scope is given, but a variable of that name exists, the variable of the smallest scope will be modified. The scope will not be changed.
.IP \(bu 2
When no scope is given and no variable of that name exists, the variable is created in function scope if inside a function, or global scope if no function is executing.
.UNINDENT
.sp
There can be many variables with the same name, but different scopes. When you use a variable, the smallest scoped variable of that name will be used. If a local variable exists, it will be used instead of the global or universal variable of the same name.
.sp
Example:
.sp
There are a few possible uses for different scopes.
.sp
Typically inside functions you should use local scope:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function something
set \-l file /path/to/my/file
if not test \-e \(dq$file\(dq
set file /path/to/my/otherfile
end
end
# or
function something
if test \-e /path/to/my/file
set \-f file /path/to/my/file
else
set \-f file /path/to/my/otherfile
end
end
.EE
.UNINDENT
.UNINDENT
.sp
If you want to set something in config.fish, or set something in a function and have it available for the rest of the session, global scope is a good choice:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Don\(aqt shorten the working directory in the prompt
set \-g fish_prompt_pwd_dir_length 0
# Set my preferred cursor style:
function setcursors
set \-g fish_cursor_default block
set \-g fish_cursor_insert line
set \-g fish_cursor_visual underscore
end
# Set my language
set \-gx LANG de_DE.UTF\-8
.EE
.UNINDENT
.UNINDENT
.sp
Here is an example of local vs function\-scoped variables:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function test\-scopes
begin
# This is a nice local scope where all variables will die
set \-l pirate \(aqThere be treasure in them thar hills\(aq
set \-f captain Space, the final frontier
# If no variable of that name was defined, it is function\-local.
set gnu \(dqIn the beginning there was nothing, which exploded\(dq
end
# This will not output anything, since the pirate was local
echo $pirate
# This will output the good Captain\(aqs speech
# since $captain had function\-scope.
echo $captain
# This will output Sir Terry\(aqs wisdom.
echo $gnu
end
.EE
.UNINDENT
.UNINDENT
.sp
When a function calls another, local variables aren\(aqt visible:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function shiver
set phrase \(aqShiver me timbers\(aq
end
function avast
set \-\-local phrase \(aqAvast, mateys\(aq
# Calling the shiver function here can not
# change any variables in the local scope
# so phrase remains as we set it here.
shiver
echo $phrase
end
avast
# Outputs \(dqAvast, mateys\(dq
.EE
.UNINDENT
.UNINDENT
.sp
When in doubt, use function\-scoped variables. When you need to make a variable accessible everywhere, make it global. When you need to persistently store configuration, make it universal. When you want to use a variable only in a short block, make it local.
.SS Overriding variables for a single command
.sp
If you want to override a variable for a single command, you can use \(dqvar=val\(dq statements before the command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Call git status on another directory
# (can also be done via \(gagit \-C somerepo status\(ga)
GIT_DIR=somerepo git status
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells, fish will first set the variable and then perform other expansions on the line, so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set foo banana
foo=gagaga echo $foo
# prints gagaga, while in other shells it might print \(dqbanana\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Multiple elements can be given in a brace expansion:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Call bash with a reasonable default path.
PATH={/usr,}/{s,}bin bash
.EE
.UNINDENT
.UNINDENT
.sp
Or with a glob:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Run vlc on all mp3 files in the current directory
# If no file exists it will still be run with no arguments
mp3s=*.mp3 vlc $mp3s
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells, this does \fInot\fP inhibit any lookup (aliases or similar). Calling a command after setting a variable override will result in the exact same command being run.
.sp
This syntax is supported since fish 3.1.
.SS Universal Variables
.sp
Universal variables are variables that are shared between all the user\(aqs fish sessions on the computer.
All changes to universal variables are persistent and instantly propagated across fish sessions.
.sp
Universal variables are stored in the file \fB\&.config/fish/fish_variables\fP\&. Do not edit this file directly, as your edits may be overwritten. Edit the variables through fish scripts or by using fish interactively instead.
.sp
Do not append to universal variables in config.fish, because these variables will then get longer with each new shell instance. Instead, set them once at the command line.
.SS Exporting variables
.sp
Variables in fish can be exported, so they will be inherited by any commands started by fish. In particular, this is necessary for variables used to configure external commands like \fBPAGER\fP or \fBGOPATH\fP, but also for variables that contain general system settings like \fBPATH\fP or \fBLANGUAGE\fP\&. If an external command needs to know a variable, it needs to be exported. Exported variables are also often called \(dqenvironment variables\(dq.
.sp
This also applies to fish \- when it starts up, it receives environment variables from its parent (usually the terminal). These typically include system configuration like \fBPATH\fP and locale variables\&.
.sp
Variables can be explicitly set to be exported with the \fB\-x\fP or \fB\-\-export\fP switch, or not exported with the \fB\-u\fP or \fB\-\-unexport\fP switch. The exporting rules when setting a variable are similar to the scoping rules for variables \- when an option is passed it is respected, otherwise the variable\(aqs existing state is used. If no option is passed and the variable didn\(aqt exist yet it is not exported.
.sp
As a naming convention, exported variables are in uppercase and unexported variables are in lowercase.
.sp
For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-gx ANDROID_HOME ~/.android # /opt/android\-sdk
set \-gx CDPATH . ~ (test \-e ~/Videos; and echo ~/Videos)
set \-gx EDITOR emacs \-nw
set \-gx GOPATH ~/dev/go
set \-gx GTK2_RC_FILES \(dq$XDG_CONFIG_HOME/gtk\-2.0/gtkrc\(dq
set \-gx LESSHISTFILE \(dq\-\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Note: Exporting is not a scope, but an additional state. It typically makes sense to make exported variables global as well, but local\-exported variables can be useful if you need something more specific than Overrides\&. They are \fIcopied\fP to functions so the function can\(aqt alter them outside, and still available to commands. Global variables are accessible to functions whether they are exported or not.
.SS Lists
.sp
fish can store a list (or an \(dqarray\(dq if you wish) of multiple strings inside of a variable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set mylist first second third
> printf \(aq%s\en\(aq $mylist # prints each element on its own line
first
second
third
.EE
.UNINDENT
.UNINDENT
.sp
To access one element of a list, use the index of the element inside of square brackets, like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo $PATH[3]
.EE
.UNINDENT
.UNINDENT
.sp
List indices start at 1 in fish, not 0 like in other languages. This is because it requires less subtracting of 1 and many common Unix tools like \fBseq\fP work better with it (\fBseq 5\fP prints 1 to 5, not 0 to 5). An invalid index is silently ignored resulting in no value (not even an empty string, no argument at all).
.sp
If you don\(aqt use any brackets, all the elements of the list will be passed to the command as separate items. This means you can iterate over a list with \fBfor\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in $PATH
echo $i is in the path
end
.EE
.UNINDENT
.UNINDENT
.sp
This goes over every directory in \fBPATH\fP separately and prints a line saying it is in the path.
.sp
To create a variable \fBsmurf\fP, containing the items \fBblue\fP and \fBsmall\fP, write:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set smurf blue small
.EE
.UNINDENT
.UNINDENT
.sp
It is also possible to set or erase individual elements of a list:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Set smurf to be a list with the elements \(aqblue\(aq and \(aqsmall\(aq
set smurf blue small
# Change the second element of smurf to \(aqevil\(aq
set smurf[2] evil
# Erase the first element
set \-e smurf[1]
# Output \(aqevil\(aq
echo $smurf
.EE
.UNINDENT
.UNINDENT
.sp
If you specify a negative index when expanding or assigning to a list variable, the index will be taken from the \fIend\fP of the list. For example, the index \-1 is the last element of the list:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set fruit apple orange banana
> echo $fruit[\-1]
banana
> echo $fruit[\-2..\-1]
orange
banana
> echo $fruit[\-1..1] # reverses the list
banana
orange
apple
.EE
.UNINDENT
.UNINDENT
.sp
As you see, you can use a range of indices, see slices for details.
.sp
All lists are one\-dimensional and can\(aqt contain other lists, although it is possible to fake nested lists using dereferencing \- see variable expansion\&.
.sp
When a list is exported as an environment variable, it is either space or colon delimited, depending on whether it is a path variable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-x smurf blue small
> set \-x smurf_PATH forest mushroom
> env | grep smurf
smurf=blue small
smurf_PATH=forest:mushroom
.EE
.UNINDENT
.UNINDENT
.sp
fish automatically creates lists from all environment variables whose name ends in \fBPATH\fP (like \fBPATH\fP, \fBCDPATH\fP or \fBMANPATH\fP), by splitting them on colons. Other variables are not automatically split.
.sp
Lists can be inspected with the count \%<> or the contains \%<> commands:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> count $smurf
2
> contains blue $smurf
# blue was found, so it exits with status 0
# (without printing anything)
> echo $status
0
> contains \-i blue $smurf
1
.EE
.UNINDENT
.UNINDENT
.sp
A nice thing about lists is that they are passed to commands one element as one argument, so once you\(aqve set your list, you can pass it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l grep_args \-r \(dqmy string\(dq
grep $grep_args . # will run the same as \(gagrep \-r \(dqmy string\(dq\(ga .
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells, fish does not do \(dqword splitting\(dq \- elements in a list stay as they are, even if they contain spaces or tabs.
.SS Argument Handling
.sp
An important list is \fB$argv\fP, which contains the arguments to a function or script. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function myfunction
echo $argv[1]
echo $argv[3]
end
.EE
.UNINDENT
.UNINDENT
.sp
This function takes whatever arguments it gets and prints the first and third:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> myfunction first second third
first
third
> myfunction apple cucumber banana
apple
banana
.EE
.UNINDENT
.UNINDENT
.sp
That covers the positional arguments, but commandline tools often get various options and flags, and $argv would contain them intermingled with the positional arguments. Typical unix argument handling allows short options (\fB\-h\fP, also grouped like in \fBls \-lah\fP), long options (\fB\-\-help\fP) and allows those options to take arguments (\fB\-\-color=auto\fP or \fB\-\-position anywhere\fP or \fBcomplete \-C\(dqgit \(dq\fP) as well as a \fB\-\-\fP separator to signal the end of options. Handling all of these manually is tricky and error\-prone.
.sp
A more robust approach to option handling is argparse \%<>, which checks the defined options and puts them into various variables, leaving only the positional arguments in $argv. Here\(aqs a simple example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function mybetterfunction
# We tell argparse about \-h/\-\-help and \-s/\-\-second
# \- these are short and long forms of the same option.
# The \(dq\-\-\(dq here is mandatory,
# it tells it from where to read the arguments.
argparse h/help s/second \-\- $argv
# exit if argparse failed because
# it found an option it didn\(aqt recognize
# \- it will print an error
or return
# If \-h or \-\-help is given, we print a little help text and return
if set \-ql _flag_help
echo \(dqmybetterfunction [\-h|\-\-help] [\-s|\-\-second] [ARGUMENT ...]\(dq
return 0
end
# If \-s or \-\-second is given, we print the second argument,
# not the first and third.
# (this is also available as _flag_s because of the short version)
if set \-ql _flag_second
echo $argv[2]
else
echo $argv[1]
echo $argv[3]
end
end
.EE
.UNINDENT
.UNINDENT
.sp
The options will be \fIremoved\fP from $argv, so $argv[2] is the second \fIpositional\fP argument now:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> mybetterfunction first \-s second third
second
.EE
.UNINDENT
.UNINDENT
.sp
For more information on argparse, like how to handle option arguments, see the argparse documentation \%<>\&.
.SS PATH variables
.sp
Path variables are a special kind of variable used to support colon\-delimited path lists including \fBPATH\fP, \fBCDPATH\fP, \fBMANPATH\fP, \fBPYTHONPATH\fP, \fBLANGUAGE\fP (for localization \%<>) etc. All variables that end in \(dqPATH\(dq (case\-sensitive) become PATH variables by default.
.sp
PATH variables act as normal lists, except they are implicitly joined and split on colons.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set MYPATH 1 2 3
echo \(dq$MYPATH\(dq
# 1:2:3
set MYPATH \(dq$MYPATH:4:5\(dq
echo $MYPATH
# 1 2 3 4 5
echo \(dq$MYPATH\(dq
# 1:2:3:4:5
.EE
.UNINDENT
.UNINDENT
.sp
Path variables will also be exported in the colon form, so \fBset \-x MYPATH 1 2 3\fP will have external commands see it as \fB1:2:3\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-gx MYPATH /bin /usr/bin /sbin
> env | grep MYPATH
MYPATH=/bin:/usr/bin:/sbin
.EE
.UNINDENT
.UNINDENT
.sp
This is for compatibility with other tools. Unix doesn\(aqt have variables with multiple elements, the closest thing it has are colon\-lists like \fBPATH\fP\&. For obvious reasons this means no element can contain a \fB:\fP\&.
.sp
Variables can be marked or unmarked as PATH variables via the \fB\-\-path\fP and \fB\-\-unpath\fP options to \fBset\fP\&.
.SS Special variables
.sp
You can change the settings of fish by changing the values of certain variables.
.INDENT 0.0
.TP
.B PATH
A list of directories in which to search for commands. This is a common unix variable also used by other tools.
.UNINDENT
.INDENT 0.0
.TP
.B CDPATH
A list of directories in which the cd \%<> builtin looks for a new directory.
.UNINDENT
.INDENT 0.0
.TP
.B Locale Variables
Locale variables such as \fBLANG\fP, \fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLC_NUMERIC\fP and \fBLC_TIME\fP set the language option for the shell and subprograms.
See the section Locale variables and status language \%<#\:status-language> for more information.
.UNINDENT
.INDENT 0.0
.TP
.B Color variables
A number of variable starting with the prefixes \fBfish_color\fP and \fBfish_pager_color\fP\&. See Variables for changing highlighting colors \%<#\:variables-color> for more information.
.UNINDENT
.INDENT 0.0
.TP
.B fish_term24bit
If this is set to 0, fish will not output 24\-bit RGB true\-color sequences but the nearest color on the 256 color palette (or the 16 color palette, if \fBfish_term256\fP is 0).
See also set_color \%<>\&.
The default is 1 but for historical reasons, fish defaults to behaving as if it was 0 on some terminals that are known to not support true\-color sequences.
.UNINDENT
.INDENT 0.0
.TP
.B fish_term256
If this is set to 0 and \fBfish_term24bit\fP is 0, translate RGB colors down to the 16 color palette.
Also, if this is set to 0, set_color \%<> commands such as \fBset_color ff0000 red\fP will prefer the named color.
.UNINDENT
.INDENT 0.0
.TP
.B fish_ambiguous_width
controls the computed width of ambiguous\-width characters. This should be set to 1 if your terminal renders these characters as single\-width (typical), or 2 if double\-width.
.UNINDENT
.INDENT 0.0
.TP
.B fish_emoji_width
controls whether fish assumes emoji render as 2 cells or 1 cell wide. This is necessary because the correct value changed from 1 to 2 in Unicode 9, and some terminals may not be aware. Set this if you see graphical glitching related to emoji (or other \(dqspecial\(dq characters). It defaults to 2.
.UNINDENT
.INDENT 0.0
.TP
.B fish_autosuggestion_enabled
controls if Autosuggestions \%<#\:autosuggestions> are enabled. Set it to 0 to disable, anything else to enable. By default they are on.
.UNINDENT
.INDENT 0.0
.TP
.B fish_transient_prompt
If this is set to 1, fish will redraw prompts with a \fB\-\-final\-rendering\fP argument before running a commandline, allowing you to change it before pushing it to the scrollback. This enables transient prompts \%<#\:transient-prompt>\&.
.UNINDENT
.INDENT 0.0
.TP
.B fish_handle_reflow
determines whether fish should try to repaint the commandline when the terminal resizes. In terminals that reflow text this should be disabled. Set it to 1 to enable, anything else to disable.
.UNINDENT
.INDENT 0.0
.TP
.B fish_key_bindings
the name of the function that sets up the keyboard shortcuts for the command\-line editor \%<#\:editor>\&.
.UNINDENT
.INDENT 0.0
.TP
.B fish_escape_delay_ms
sets how long fish waits for another key after seeing an escape, to distinguish pressing the escape key from the start of an escape sequence. The default is 30ms. Increasing it increases the latency but allows pressing escape instead of alt for alt+character bindings. For more information, see the chapter in the bind documentation \%<#\:cmd-bind-escape>\&.
.UNINDENT
.INDENT 0.0
.TP
.B fish_sequence_key_delay_ms
sets how long fish waits for another key after seeing a key that is part of a longer sequence, to disambiguate. For instance if you had bound \fB\ecx\ece\fP to open an editor, fish would wait for this long in milliseconds to see a ctrl\-e after a ctrl\-x. If the time elapses, it will handle it as a ctrl\-x (by default this would copy the current commandline to the clipboard). See also Key sequences \%<#\:interactive-key-sequences>\&.
.UNINDENT
.INDENT 0.0
.TP
.B fish_complete_path
determines where fish looks for completion. When trying to complete for a command, fish looks for files in the directories in this variable.
.UNINDENT
.INDENT 0.0
.TP
.B fish_cursor_selection_mode
controls whether the selection is inclusive or exclusive of the character under the cursor (see Copy and Paste \%<#\:killring>).
.UNINDENT
.INDENT 0.0
.TP
.B fish_function_path
determines where fish looks for functions. When fish autoloads a function, it will look for files in these directories.
.UNINDENT
.INDENT 0.0
.TP
.B fish_greeting
the greeting message printed on startup. This is printed by a function of the same name that can be overridden for more complicated changes (see funced \%<>)
.UNINDENT
.INDENT 0.0
.TP
.B fish_history
the current history session name. If set, all subsequent commands within an
interactive fish session will be logged to a separate file identified by the value of the
variable. If unset, the default session name \(dqfish\(dq is used. If set to an
empty string, history is not saved to disk (but is still available within the interactive
session).
.UNINDENT
.INDENT 0.0
.TP
.B fish_trace
if set and not empty, will cause fish to print commands before they execute, similar to \fBset \-x\fP in bash.
The trace is printed to the path given by the \fI\-\-debug\-output\fP option to fish or the \fBFISH_DEBUG_OUTPUT\fP variable.
It goes to stderr by default.
Set it to \fBall\fP to also trace execution of key bindings, event handlers as well as prompt and title functions.
.UNINDENT
.INDENT 0.0
.TP
.B FISH_DEBUG
Controls which debug categories \fBfish\fP enables for output, analogous to the \fB\-\-debug\fP option.
.UNINDENT
.INDENT 0.0
.TP
.B FISH_DEBUG_OUTPUT
Specifies a file to direct debug output to.
.UNINDENT
.INDENT 0.0
.TP
.B fish_user_paths
a list of directories that are prepended to \fBPATH\fP\&. This can be a universal variable.
.UNINDENT
.INDENT 0.0
.TP
.B umask
the current file creation mask. The preferred way to change the umask variable is through the umask \%<> function. An attempt to set umask to an invalid value will always fail.
.UNINDENT
.INDENT 0.0
.TP
.B SHELL_PROMPT_PREFIX
if set, this string is automatically prepended to the left prompt. This is a standard environment variable that may be set by tools like systemd\(aqs \fBrun0\fP to indicate special shell sessions.
.UNINDENT
.INDENT 0.0
.TP
.B SHELL_PROMPT_SUFFIX
if set, this string is automatically appended to the left prompt. This is a standard environment variable that may be set by tools like systemd\(aqs \fBrun0\fP to indicate special shell sessions.
.UNINDENT
.INDENT 0.0
.TP
.B SHELL_WELCOME
if set, this string is displayed when an interactive shell starts, after the greeting. This is a standard environment variable that may be set by tools like systemd\(aqs \fBrun0\fP to display session information.
.UNINDENT
.INDENT 0.0
.TP
.B BROWSER
your preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
.UNINDENT
.sp
fish also provides additional information through the values of certain environment variables. Most of these variables are read\-only and their value can\(aqt be changed with \fBset\fP\&.
.INDENT 0.0
.TP
.B _
the name of the currently running command (though this is deprecated, and the use of \fBstatus current\-command\fP is preferred).
.UNINDENT
.INDENT 0.0
.TP
.B argv
a list of arguments to the shell or function. \fBargv\fP is only defined when inside a function call, or if fish was invoked with a list of arguments, like \fBfish myscript.fish foo bar\fP\&. This variable can be changed.
.UNINDENT
.INDENT 0.0
.TP
.B argv_opts
argparse \%<> sets this to the list of successfully parsed options, including option\-arguments. This variable can be changed.
.UNINDENT
.INDENT 0.0
.TP
.B CMD_DURATION
the runtime of the last command in milliseconds.
.UNINDENT
.INDENT 0.0
.TP
.B COLUMNS and LINES
the current size of the terminal in height and width. These values are only used by fish if the operating system does not report the size of the terminal. Both variables must be set in that case otherwise a default of 80x24 will be used. They are updated when the window size changes.
.UNINDENT
.INDENT 0.0
.TP
.B fish_kill_signal
the signal that terminated the last foreground job, or 0 if the job exited normally.
.UNINDENT
.INDENT 0.0
.TP
.B fish_killring
a list of entries in fish\(aqs kill ring \%<#\:killring> of cut text.
.UNINDENT
.INDENT 0.0
.TP
.B fish_read_limit
how many bytes fish will process with read \%<> or in a command substitution\&.
.UNINDENT
.INDENT 0.0
.TP
.B fish_pid
the process ID (PID) of the shell.
.UNINDENT
.INDENT 0.0
.TP
.B fish_terminal_color_theme
a read\-only variable;
set to \fBlight\fP or \fBdark\fP when the terminal uses a light or dark color theme respectively;
set to \fBunknown\fP if the terminal does not report its colors \%<#\:term-compat-query-background-color>\&.
Like status terminal \%<#\:status-terminal>, this is only populated once the first interactive prompt is shown.
This is used in an \-\-on\-variable event handler to update syntax highlighting \%<#\:syntax-highlighting> variables whenever the terminal\(aqs color theme changes.
See here \%<#\:fish-config-theme-files> for how to specify \fBlight\fP and \fBdark\fP variants in your theme.
.UNINDENT
.INDENT 0.0
.TP
.B history
a list containing the last commands that were entered.
.UNINDENT
.INDENT 0.0
.TP
.B HOME
the user\(aqs home directory. This variable can be changed.
.UNINDENT
.INDENT 0.0
.TP
.B hostname
the machine\(aqs hostname.
.UNINDENT
.INDENT 0.0
.TP
.B IFS
the internal field separator that is used for word splitting with the read \%<> builtin. Setting this to the empty string will also disable line splitting in command substitution\&. This variable can be changed.
.UNINDENT
.INDENT 0.0
.TP
.B last_pid
the process ID (PID) of the last background process.
.UNINDENT
.INDENT 0.0
.TP
.B PWD
the current working directory.
.UNINDENT
.INDENT 0.0
.TP
.B pipestatus
a list of exit statuses of all processes that made up the last executed pipe. See exit status\&.
.UNINDENT
.INDENT 0.0
.TP
.B SHLVL
the level of nesting of shells. fish increments this in interactive shells, otherwise it only passes it along.
.UNINDENT
.INDENT 0.0
.TP
.B status
the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number.
.UNINDENT
.INDENT 0.0
.TP
.B status_generation
the \(dqgeneration\(dq count of \fB$status\fP\&. This will be incremented only when the previous command produced an explicit status. (For example, background jobs will not increment this).
.UNINDENT
.INDENT 0.0
.TP
.B USER
the current username. This variable can be changed.
.UNINDENT
.INDENT 0.0
.TP
.B EUID
the current effective user id, set by fish at startup. This variable can be changed.
.UNINDENT
.INDENT 0.0
.TP
.B version
the version of the currently running fish (also available as \fBFISH_VERSION\fP for backward compatibility).
.UNINDENT
.sp
As a convention, an uppercase name is usually used for exported variables, while lowercase variables are not exported. (\fBCMD_DURATION\fP is an exception for historical reasons). This rule is not enforced by fish, but it is good coding practice to use casing to distinguish between exported and unexported variables.
.sp
fish also uses some variables internally, their name usually starting with \fB__fish\fP\&. These are internal and should not typically be modified directly.
.SS The status variable
.sp
Whenever a process exits, an exit status is returned to the program that started it (usually the shell). This exit status is an integer number, which tells the calling application how the execution of the command went. In general, a zero exit status means that the command executed without problem, but a non\-zero exit status means there was some form of problem.
.sp
fish stores the exit status of the last process in the last job to exit in the \fBstatus\fP variable.
.sp
If fish encounters a problem while executing a command, the status variable may also be set to a specific value:
.INDENT 0.0
.IP \(bu 2
0 is generally the exit status of commands if they successfully performed the requested operation.
.IP \(bu 2
1 is generally the exit status of commands if they failed to perform the requested operation.
.IP \(bu 2
121 is generally the exit status of commands if they were supplied with invalid arguments.
.IP \(bu 2
123 means that the command was not executed because the command name contained invalid characters.
.IP \(bu 2
124 means that the command was not executed because none of the wildcards in the command produced any matches.
.IP \(bu 2
125 means that while an executable with the specified name was located, the operating system could not actually execute the command.
.IP \(bu 2
126 means that while a file with the specified name was located, it was not executable.
.IP \(bu 2
127 means that no function, builtin or command with the given name could be located.
.UNINDENT
.sp
If a process exits through a signal, the exit status will be 128 plus the number of the signal.
.sp
The status can be negated with not \%<> (or \fB!\fP), which is useful in a condition\&. This turns a status of 0 into 1 and any non\-zero status into 0.
.sp
There is also \fB$pipestatus\fP, which is a list of all \fBstatus\fP values of processes in a pipe. One difference is that not \%<> applies to \fB$status\fP, but not \fB$pipestatus\fP, because it loses information.
.sp
For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
not cat file | grep \-q fish
echo status is: $status pipestatus is $pipestatus
.EE
.UNINDENT
.UNINDENT
.sp
Here \fB$status\fP reflects the status of \fBgrep\fP, which returns 0 if it found something, negated with \fBnot\fP (so 1 if it found something, 0 otherwise). \fB$pipestatus\fP reflects the status of \fBcat\fP (which returns non\-zero for example when it couldn\(aqt find the file) and \fBgrep\fP, without the negation.
.sp
So if both \fBcat\fP and \fBgrep\fP succeeded, \fB$status\fP would be 1 because of the \fBnot\fP, and \fB$pipestatus\fP would be 0 and 0.
.sp
It\(aqs possible for the first command to fail while the second succeeds. One common example is when the second program quits early.
.sp
For example, if you have a pipeline like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cat file1 file2 | head \-n 50
.EE
.UNINDENT
.UNINDENT
.sp
This will tell \fBcat\fP to print two files, \(dqfile1\(dq and \(dqfile2\(dq, one after the other, and the \fBhead\fP will then only print the first 50 lines. In this case you might often see this constellation:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> cat file1 file2 | head \-n 50
# 50 lines of output
> echo $pipestatus
141 0
.EE
.UNINDENT
.UNINDENT
.sp
Here, the \(dq141\(dq signifies that \fBcat\fP was killed by signal number 13 (128 + 13 == 141) \- a \fBSIGPIPE\fP\&. You can also use \fBfish_kill_signal\fP to see the signal number. This happens because it was still working, and then \fBhead\fP closed the pipe, so \fBcat\fP received a signal that it didn\(aqt ignore and so it died.
.sp
Whether \fBcat\fP here will see a SIGPIPE depends on how long the file is and how much it writes at once, so you might see a pipestatus of \(dq0 0\(dq, depending on the implementation. This is a general unix issue and not specific to fish. Some shells feature a \(dqpipefail\(dq feature that will call a pipeline failed if one of the processes in it failed, and this is a big problem with it.
.SS Locale Variables
.sp
The \(dqlocale\(dq of a program is its set of language and regional settings.
In UNIX, these are made up of several categories. The categories used by fish are:
.INDENT 0.0
.TP
.B LANG
This is the typical environment variable for specifying a locale.
A user may set this variable to express the language they speak, their region, and a character encoding.
The encoding part is ignored, fish always assumes UTF\-8. The actual values are specific to their platform, except for special values like \fBC\fP or \fBPOSIX\fP\&.
.sp
The value of \fBLANG\fP is used for each category unless the variable for that category was set or \fBLC_ALL\fP is set. So typically you only need to set LANG.
.sp
Example values are \fBen_US.UTF\-8\fP for the American English or \fBde_AT.UTF\-8\fP for Austrian German.
Your operating system might have a \fBlocale\fP command that you can call as \fBlocale \-a\fP to see a list of defined locales.
.UNINDENT
.INDENT 0.0
.TP
.B LANGUAGE
This is treated like \fBLC_MESSAGES\fP except that it can hold multiple values,
which allows to specify a priority list of languages for translation.
It\(aqs a PATH variable, like in GNU gettext \%\&.
.sp
Language identifiers without a region specified (e.g. \fBzh\fP) result in all available variants of this language being tried in arbitrary order.
In this example, we might first look for messages in the \fBzh_CN\fP catalog, followed by \fBzh_TW\fP, or the other way around.
This is different from GNU gettext, which uses a \(dqdefault\(dq variant of the language instead.
If you prefer a certain variant, specify it earlier in the list,
e.g. \fBzh_TW:zh\fP if your preferred language is \fBzh_TW\fP, and you prefer any other variants of \fBzh\fP over the English default.
If \fBzh_TW\fP is the only variant of \fBzh\fP you want,
specifying \fBzh_TW\fP in the \fBLANGUAGE\fP variable will result in messages which are not available in \fBzh_TW\fP being displayed in English.
.sp
See also builtin _ (underscore) \%<>\&.
.UNINDENT
.INDENT 0.0
.TP
.B LC_ALL
Overrides the \fBLANG\fP and all other \fBLC_*\fP variables.
Please use \fBLC_ALL\fP only as a temporary override.
.UNINDENT
.INDENT 0.0
.TP
.B LC_MESSAGES
Determines the language in which messages are displayed, see builtin _ (underscore) \%<>\&.
.UNINDENT
.INDENT 0.0
.TP
.B LC_NUMERIC
Sets the locale for formatting numbers \%<>\&.
.UNINDENT
.INDENT 0.0
.TP
.B LC_TIME
Determines how date and time are displayed.
Used in the history \%<#\:history-show-time> builtin.
.UNINDENT
.SS Builtin commands
.sp
fish includes a number of commands in the shell directly. We call these \(dqbuiltins\(dq. These include:
.INDENT 0.0
.IP \(bu 2
Builtins that manipulate the shell state \- cd \%<> changes directory, set \%<> sets variables
.IP \(bu 2
Builtins for dealing with data, like string \%<> for strings and math \%<> for numbers, count \%<> for counting lines or arguments, path \%<> for dealing with path
.IP \(bu 2
status \%<> for asking about the shell\(aqs status
.IP \(bu 2
printf \%<> and echo \%<> for creating output
.IP \(bu 2
test \%<> for checking conditions
.IP \(bu 2
argparse \%<> for parsing function arguments
.IP \(bu 2
source \%<> to read a script in the current shell (so changes to variables stay) and eval \%<> to execute a string as script
.IP \(bu 2
random \%<> to get random numbers or pick a random element from a list
.IP \(bu 2
read \%<> for reading from a pipe or the terminal
.UNINDENT
.sp
For a list of all builtins, use \fBbuiltin \-n\fP\&.
.sp
For a list of all builtins, functions and commands shipped with fish, see the list of commands \%<>\&. The documentation is also available by using the \fB\-\-help\fP switch.
.SS Command lookup
.sp
When fish is told to run something, it goes through multiple steps to find it.
.sp
If it contains a \fB/\fP, fish tries to execute the given file, from the current directory on.
.sp
If it doesn\(aqt contain a \fB/\fP, it could be a function, builtin, or external command, and so fish goes through the full lookup.
.sp
In order:
.INDENT 0.0
.IP 1. 3
It tries to resolve it as a function\&.
.INDENT 3.0
.IP \(bu 2
If the function is already known, it uses that
.IP \(bu 2
If there is a file of the name with a \(dq.fish\(dq suffix in \fBfish_function_path\fP, it loads that\&. (If there is more than one file only the first is used)
.IP \(bu 2
If the function is now defined it uses that
.UNINDENT
.IP 2. 3
It tries to resolve it as a builtin\&.
.IP 3. 3
It tries to find an executable file in \fBPATH\fP\&.
.INDENT 3.0
.IP \(bu 2
If it finds a file, it tells the kernel to run it.
.IP \(bu 2
If the kernel knows how to run the file (e.g. via a \fB#!\fP line \- \fB#!/bin/sh\fP or \fB#!/usr/bin/python\fP), it does it.
.IP \(bu 2
If the kernel reports that it couldn\(aqt run it because of a missing interpreter, and the file passes a rudimentary check, fish tells \fB/bin/sh\fP to run it.
.UNINDENT
.UNINDENT
.sp
If none of these work, fish runs the function fish_command_not_found \%<> and sets \fBstatus\fP to 127.
.sp
You can use type \%<> to see how fish resolved something:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> type \-\-short \-\-all echo
echo is a builtin
echo is /usr/bin/echo
.EE
.UNINDENT
.UNINDENT
.SS Querying for user input
.sp
Sometimes, you want to ask the user for input, for instance to confirm something. This can be done with the read \%<> builtin.
.sp
Let\(aqs make up an example. This function will glob the files in all the directories it gets as arguments, and if there are more than five \%<> it will ask the user if it is supposed to show them, but only if it is connected to a terminal:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function show_files
# This will glob on all arguments. Any non\-directories will be ignored.
set \-l files $argv/*
# If there are more than 5 files
if test (count $files) \-gt 5
# and both stdin (for reading input)
# and stdout (for writing the prompt)
# are terminals
and isatty stdin
and isatty stdout
# Keep asking until we get a valid response
while read \-\-nchars 1 \-l response \-\-prompt\-str=\(dqAre you sure? (y/n)\(dq
or return 1 # if the read was aborted with ctrl\-c/ctrl\-d
switch $response
case y Y
echo Okay
# We break out of the while and go on with the function
break
case n N
# We return from the function without printing
echo Not showing
return 1
case \(aq*\(aq
# We go through the while loop and ask again
echo Not valid input
continue
end
end
end
# And now we print the files
printf \(aq%s\en\(aq $files
end
.EE
.UNINDENT
.UNINDENT
.sp
If you run this as \fBshow_files /\fP, it will most likely ask you until you press Y/y or N/n. If you run this as \fBshow_files / | cat\fP, it will print the files without asking. If you run this as \fBshow_files .\fP, it might print something without asking because there are fewer than five files.
.SS Shell variable and function names
.sp
The names given to variables and functions (so\-called \(dqidentifiers\(dq) have to follow certain rules:
.INDENT 0.0
.IP \(bu 2
A variable name cannot be empty. It can contain only letters, digits, and underscores. It may begin and end with any of those characters.
.IP \(bu 2
A function name cannot be empty. It may not begin with a hyphen (\(dq\-\(dq) and may not contain a slash (\(dq/\(dq). All other characters, including a space, are valid. A function name also can\(aqt be the same as a reserved keyword or essential builtin like \fBif\fP or \fBset\fP\&.
.IP \(bu 2
A bind mode name (e.g., \fBbind \-m abc ...\fP) must be a valid variable name.
.UNINDENT
.sp
Other things have other restrictions. For instance what is allowed for file names depends on your system, but at the very least they cannot contain a \(dq/\(dq (because that is the path separator) or NULL byte (because that is how UNIX ends strings).
.SS Configuration files
.sp
When fish is started, it reads and runs its configuration files. Where these are depends on build configuration and environment variables.
.sp
The main file is \fB~/.config/fish/config.fish\fP (or more precisely \fB$XDG_CONFIG_HOME/fish/config.fish\fP).
.sp
Configuration files are run in the following order:
.INDENT 0.0
.IP \(bu 2
Configuration snippets (named \fB*.fish\fP) in the directories:
.INDENT 2.0
.IP \(bu 2
\fB$__fish_config_dir/conf.d\fP (by default, \fB~/.config/fish/conf.d/\fP)
.IP \(bu 2
\fB$__fish_sysconf_dir/conf.d\fP (by default, \fB/etc/fish/conf.d/\fP)
.IP \(bu 2
Directories for others to ship configuration snippets for their software:
.INDENT 2.0
.IP \(bu 2
the directories under \fB$__fish_user_data_dir\fP (usually \fB~/.local/share/fish\fP, controlled by the \fBXDG_DATA_HOME\fP environment variable)
.IP \(bu 2
a \fBfish/vendor_conf.d\fP directory in the directories listed in \fB$XDG_DATA_DIRS\fP (default \fB/usr/share/fish/vendor_conf.d\fP and \fB/usr/local/share/fish/vendor_conf.d\fP)
.UNINDENT
.sp
These directories are also accessible in \fB$__fish_vendor_confdirs\fP\&.
Note that changing that in a running fish won\(aqt do anything as by that point the directories have already been read.
.UNINDENT
.sp
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. \(dq01\(dq sorts before \(dq2\(dq).
.IP \(bu 2
System\-wide configuration files, where administrators can include initialization for all users on the system \- similar to \fB/etc/profile\fP for POSIX\-style shells \- in \fB$__fish_sysconf_dir\fP (usually \fB/etc/fish/config.fish\fP).
.IP \(bu 2
User configuration, usually in \fB~/.config/fish/config.fish\fP (controlled by the \fBXDG_CONFIG_HOME\fP environment variable, and accessible as \fB$__fish_config_dir\fP).
.UNINDENT
.sp
\fB~/.config/fish/config.fish\fP is sourced \fIafter\fP the snippets. This is so you can copy snippets and override some of their behavior.
.sp
These files are all executed on the startup of every shell. If you want to run a command only on starting an interactive shell, use the exit status of the command \fBstatus \-\-is\-interactive\fP to determine if the shell is interactive. If you want to run a command only when using a login shell, use \fBstatus \-\-is\-login\fP instead. This will speed up the starting of non\-interactive or non\-login shells.
.sp
If you are developing another program, you may want to add configuration for all users of fish on a system. This is discouraged; if not carefully written, they may have side\-effects or slow the startup of the shell. Additionally, users of other shells won\(aqt benefit from the fish\-specific configuration. However, if they are required, you can install them to the \(dqvendor\(dq configuration directory. As this path may vary from system to system, \fBpkg\-config\fP should be used to discover it: \fBpkg\-config \-\-variable confdir fish\fP\&.
.sp
For system integration, fish also ships a file called \fB__fish_build_paths.fish\fP\&. This can be customized during build, for instance because your system requires special paths to be used.
.SS Future feature flags
.sp
Feature flags are how fish stages changes that might break scripts. Breaking changes are introduced as opt\-in, in a few releases they become opt\-out, and eventually the old behavior is removed.
.sp
You can see the current list of features via \fBstatus features\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> status features
stderr\-nocaret on 3.0 ^ no longer redirects stderr
qmark\-noglob on 3.0 ? no longer globs
regex\-easyesc on 3.1 string replace \-r needs fewer \e\e\(aqs
ampersand\-nobg\-in\-token on 3.4 & only backgrounds if followed by a separating character
remove\-percent\-self off 4.0 %self is no longer expanded (use $fish_pid)
test\-require\-arg off 4.0 builtin test requires an argument
mark\-prompt on 4.0 write OSC 133 prompt markers to the terminal
ignore\-terminfo on 4.1 do not look up $TERM in terminfo database
query\-term on 4.1 query the TTY to enable extra functionality
omit\-term\-workarounds off 4.3 skip workarounds for incompatible terminals
.EE
.UNINDENT
.UNINDENT
.sp
Here is what they mean:
.INDENT 0.0
.IP \(bu 2
\fBstderr\-nocaret\fP was introduced in fish 3.0 and cannot be turned off since fish 3.5. It can still be tested for compatibility, but a \fBno\-stderr\-nocaret\fP value will be ignored. The flag made \fB^\fP an ordinary character instead of denoting an stderr redirection. Use \fB2>\fP instead.
.IP \(bu 2
\fBqmark\-noglob\fP was also introduced in fish 3.0 (and made the default in 4.0). It makes \fB?\fP an ordinary character instead of a single\-character glob. Use a \fB*\fP instead (which will match multiple characters) or find other ways to match files like \fBfind\fP\&.
.IP \(bu 2
\fBregex\-easyesc\fP was introduced in 3.1 (and made the default in 3.5). It makes it so the replacement expression in \fBstring replace \-r\fP does one fewer round of escaping. Before, to escape a backslash you would have to use \fBstring replace \-ra \(aq([ab])\(aq \(aq\e\e\e\e\e\e\e\e$1\(aq\fP\&. After, just \fB\(aq\e\e\e\e$1\(aq\fP is enough. Check your \fBstring replace\fP calls if you use this anywhere.
.IP \(bu 2
\fBampersand\-nobg\-in\-token\fP was introduced in fish 3.4 (and made the default in 3.5). It makes it so a \fB&\fP is no longer interpreted as the backgrounding operator in the middle of a token, so dealing with URLs becomes easier. Either put spaces or a semicolon after the \fB&\fP\&. This is recommended formatting anyway, and \fBfish_indent\fP will have done it for you already.
.IP \(bu 2
\fBremove\-percent\-self\fP turns off the special \fB%self\fP expansion. It was introduced in 4.0. To get fish\(aqs pid, you can use the \fBfish_pid\fP variable.
.IP \(bu 2
\fBtest\-require\-arg\fP removes builtin test \%<>\(aqs one\-argument form (\fBtest \(dqstring\(dq\fP\&. It was introduced in 4.0. To test if a string is non\-empty, use \fBtest \-n \(dqstring\(dq\fP\&. If disabled, any call to \fBtest\fP that would change sends a debug message \%<#\:debugging-fish> of category \(dqdeprecated\-test\(dq, so starting fish with \fBfish \-\-debug=deprecated\-test\fP can be used to find offending calls.
.IP \(bu 2
\fBmark\-prompt\fP makes fish report to the terminal the beginning and end of both shell prompts and command output.
.IP \(bu 2
\fBignore\-terminfo\fP was introduced in fish 4.1 and cannot be turned off since fish 4.5. It can still be tested for compatibility, but a \fBno\-ignore\-terminfo\fP value will be ignored. The flag disabled lookup of $TERM in the terminfo database.
.IP \(bu 2
\fBquery\-term\fP allows fish to query the terminal by writing escape sequences and reading the terminal\(aqs response.
This enables features such as scrolling \%<#\:term-compat-cursor-position-report>\&.
If you use an incompatible terminal, you can \-\- for the time being \-\- work around it by running (once) \fBset \-Ua fish_features no\-query\-term\fP\&.
.IP \(bu 2
\fBomit\-term\-workarounds\fP prevents fish from trying to work around incompatible terminals.
.UNINDENT
.sp
These changes are introduced off by default. They can be enabled on a per session basis:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish \-\-features qmark\-noglob,regex\-easyesc
.EE
.UNINDENT
.UNINDENT
.sp
or opted into globally for a user:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-U fish_features regex\-easyesc qmark\-noglob
.EE
.UNINDENT
.UNINDENT
.sp
Features will only be set on startup, so this variable will only take effect if it is universal or exported.
.sp
You can also use the version as a group, so \fB3.0\fP is equivalent to \(dqstderr\-nocaret\(dq and \(dqqmark\-noglob\(dq. Instead of a version, the special group \fBall\fP enables all features.
.sp
Prefixing a feature with \fBno\-\fP turns it off instead. E.g. to reenable the \fB?\fP single\-character glob:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-Ua fish_features no\-qmark\-noglob
.EE
.UNINDENT
.UNINDENT
.SS Event handlers
.sp
When defining a new function in fish, it is possible to make it into an event handler, i.e. a function that is automatically run when a specific event takes place. Events that can trigger a handler currently are:
.INDENT 0.0
.IP \(bu 2
When a signal is delivered
.IP \(bu 2
When a job exits
.IP \(bu 2
When the value of a variable is updated
.IP \(bu 2
When the prompt is about to be shown
.UNINDENT
.sp
Example:
.sp
To specify a signal handler for the WINCH signal, write:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function my_signal_handler \-\-on\-signal WINCH
echo Got WINCH signal!
end
.EE
.UNINDENT
.UNINDENT
.sp
fish already has the following named events for the \fB\-\-on\-event\fP switch:
.INDENT 0.0
.IP \(bu 2
\fBfish_prompt\fP is emitted whenever a new fish prompt is about to be displayed.
.IP \(bu 2
\fBfish_preexec\fP is emitted right before executing an interactive command. The commandline is passed as the first parameter. Not emitted if command is empty.
.IP \(bu 2
\fBfish_posterror\fP is emitted right after executing a command with syntax errors. The commandline is passed as the first parameter.
.IP \(bu 2
\fBfish_postexec\fP is emitted right after executing an interactive command. The commandline is passed as the first parameter. Not emitted if command is empty.
.IP \(bu 2
\fBfish_exit\fP is emitted right before fish exits.
.IP \(bu 2
\fBfish_cancel\fP is emitted when a commandline is cleared.
.IP \(bu 2
\fBfish_focus_in\fP is emitted when fish\(aqs terminal gains focus.
.IP \(bu 2
\fBfish_focus_out\fP is emitted when fish\(aqs terminal loses focus.
.UNINDENT
.sp
Events can be fired with the emit \%<> command, and do not have to be defined before. The names just need to match. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function handler \-\-on\-event imdone
echo generator is done $argv
end
function generator
sleep 1
# The \(dqimdone\(dq is the name of the event
# the rest is the arguments to pass to the handler
emit imdone with $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
If there are multiple handlers for an event, they will all be run, but the order might change between fish releases, so you should not rely on it.
.sp
Please note that event handlers only become active when a function is loaded, which means you need to otherwise source \%<> or execute a function instead of relying on autoloading\&. One approach is to put it into your configuration file\&.
.sp
For more information on how to define new event handlers, see the documentation for the function \%<> command.
.SS Debugging fish scripts
.sp
fish includes basic built\-in debugging facilities that allow you to stop execution of a script at an arbitrary point. When this happens you are presented with an interactive prompt where you can execute any fish command to inspect or change state (there are no debug commands as such). For example, you can check or change the value of any variables using printf \%<> and set \%<>\&. As another example, you can run status print\-stack\-trace \%<> to see how the current breakpoint was reached. To resume normal execution of the script, type exit \%<> or \fBctrl\fP\-\fBd\fP\&.
.sp
To start a debug session insert the builtin command \%<> \fBbreakpoint\fP at the point in a function or script where you wish to gain control, then run the function or script. Also, the default action of the \fBTRAP\fP signal is to call this builtin, meaning a running script can be actively debugged by sending it the \fBTRAP\fP signal (\fBkill \-s TRAP \fP). There is limited support for interactively setting or modifying breakpoints from this debug prompt: it is possible to insert new breakpoints in (or remove old ones from) other functions by using the \fBfunced\fP function to edit the definition of a function, but it is not possible to add or remove a breakpoint from the function/script currently loaded and being executed.
.sp
Another way to debug script issues is to set the \fBfish_trace\fP variable, e.g. \fBfish_trace=1 fish_prompt\fP to see which commands fish executes when running the fish_prompt \%<> function.
.SS Profiling fish scripts
.sp
If you specifically want to debug performance issues, \fBfish\fP can be run with the \fB\-\-profile /path/to/profile.log\fP option to save a profile to the specified path. This profile log includes a breakdown of how long each step in the execution took.
.sp
For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish \-\-profile /tmp/sleep.prof \-ic \(aqsleep 3s\(aq
> cat /tmp/sleep.prof
Time Sum Command
3003419 3003419 > sleep 3s
.EE
.UNINDENT
.UNINDENT
.sp
This will show the time for each command itself in the first column, the time for the command and every subcommand (like any commands inside of a function or command substitutions) in the second and the command itself in the third, separated with tabs.
.sp
The time is given in microseconds.
.sp
To see the slowest commands last, \fBsort \-nk2 /path/to/logfile\fP is useful.
.sp
For profiling fish\(aqs startup there is also \fB\-\-profile\-startup /path/to/logfile\fP\&.
.sp
See fish \%<> for more information.
.SS Commands
.sp
This is a list of all the commands fish ships with.
.sp
Broadly speaking, these fall into a few categories:
.SS Keywords
.sp
Core language keywords that make up the syntax, like
.INDENT 0.0
.IP \(bu 2
if \%<> and else \%<> for conditions.
.IP \(bu 2
for \%<> and while \%<> for loops.
.IP \(bu 2
break \%<> and continue \%<> to control loops.
.IP \(bu 2
function \%<> to define functions.
.IP \(bu 2
return \%<> to return a status from a function.
.IP \(bu 2
begin \%<> to begin a block and end \%<> to end any block (including ifs and loops).
.IP \(bu 2
and \%<>, or \%<> and not \%<> to combine commands logically.
.IP \(bu 2
switch \%<> and case \%<> to make multiple blocks depending on the value of a variable.
.IP \(bu 2
command \%<> or builtin \%<> to tell fish what sort of thing to execute
.IP \(bu 2
time \%<> to time execution
.IP \(bu 2
exec \%<> tells fish to replace itself with a command.
.IP \(bu 2
end \%<> to end a block
.UNINDENT
.SS Tools
.sp
Builtins to do a task, like
.INDENT 0.0
.IP \(bu 2
cd \%<> to change the current directory.
.IP \(bu 2
echo \%<> or printf \%<> to produce output.
.IP \(bu 2
set_color \%<> to colorize output.
.IP \(bu 2
set \%<> to set, query or erase variables.
.IP \(bu 2
read \%<> to read input.
.IP \(bu 2
string \%<> for string manipulation.
.IP \(bu 2
path \%<> for filtering paths and handling their components.
.IP \(bu 2
math \%<> does arithmetic.
.IP \(bu 2
argparse \%<> to make arguments easier to handle.
.IP \(bu 2
count \%<> to count arguments.
.IP \(bu 2
type \%<> to find out what sort of thing (command, builtin or function) fish would call, or if it exists at all.
.IP \(bu 2
test \%<> checks conditions like if a file exists or a string is empty.
.IP \(bu 2
contains \%<> to see if a list contains an entry.
.IP \(bu 2
eval \%<> and source \%<> to run fish code from a string or file.
.IP \(bu 2
status \%<> to get shell information, like whether it\(aqs interactive or a login shell, or which file it is currently running.
.IP \(bu 2
abbr \%<> manages Abbreviations \%<#\:abbreviations>\&.
.IP \(bu 2
bind \%<> to change bindings.
.IP \(bu 2
complete \%<> manages completions \%<#\:tab-completion>\&.
.IP \(bu 2
commandline \%<> to get or change the commandline contents.
.IP \(bu 2
fish_config \%<> to easily change fish\(aqs configuration, like the prompt or colorscheme.
.IP \(bu 2
random \%<> to generate random numbers or pick from a list.
.UNINDENT
.SS Known functions
.sp
Known functions are a customization point. You can change them to change how your fish behaves. This includes:
.INDENT 0.0
.IP \(bu 2
fish_prompt \%<> and fish_right_prompt \%<> and fish_mode_prompt \%<> to print your prompt.
.IP \(bu 2
fish_command_not_found \%<> to tell fish what to do when a command is not found.
.IP \(bu 2
fish_title \%<> to change the terminal\(aqs title.
.IP \(bu 2
fish_tab_title \%<> to change the terminal tab\(aqs title.
.IP \(bu 2
fish_greeting \%<> to show a greeting when fish starts.
.IP \(bu 2
fish_should_add_to_history \%<> to determine if a command should be added to history
.UNINDENT
.SS Helper functions
.sp
Some helper functions, often to give you information for use in your prompt:
.INDENT 0.0
.IP \(bu 2
fish_git_prompt \%<> and fish_hg_prompt \%<> to print information about the current git or mercurial repository.
.IP \(bu 2
fish_vcs_prompt \%<> to print information for either.
.IP \(bu 2
fish_svn_prompt \%<> to print information about the current svn repository.
.IP \(bu 2
fish_status_to_signal \%<> to give a signal name from a return status.
.IP \(bu 2
prompt_pwd \%<> to give the current directory in a nicely formatted and shortened way.
.IP \(bu 2
prompt_login \%<> to describe the current login, with user and hostname, and to explain if you are in a chroot or connected via ssh.
.IP \(bu 2
prompt_hostname \%<> to give the hostname, shortened for use in the prompt.
.IP \(bu 2
fish_is_root_user \%<> to check if the current user is an administrator user like root.
.IP \(bu 2
fish_add_path \%<> to easily add a path to $PATH.
.IP \(bu 2
alias \%<> to quickly define wrapper functions (\(dqaliases\(dq).
.IP \(bu 2
fish_delta \%<> to show what you have changed from the default configuration.
.IP \(bu 2
export \%<> as a compatibility function for other shells.
.UNINDENT
.SS Helper commands
.sp
fish also ships some things as external commands so they can be easily called from elsewhere.
.sp
This includes fish_indent \%<> to format fish code and fish_key_reader \%<> to show you what escape sequence a keypress produces.
.SS The full list
.sp
And here is the full list:
.SS _ \- call fish\(aqs translations
.SS Synopsis
.nf
\fB_\fP \fISTRING\fP
.fi
.sp
.SS Description
.sp
\fB_\fP translates its arguments into the current language, if possible.
.sp
This only works with messages which are translated as part of fish\(aqs own sources, so using it as part of your own fish scripts which are not upstreamed into the fish repo will not work unless the exact same message also exists upstream.
.sp
It requires fish to be built with gettext support. If that support is disabled or there is no translation it will echo the argument back.
.sp
The language depends on the current locale, set with \fBLANG\fP \%<#\:envvar-LANG>, \fBLC_MESSAGES\fP \%<#\:envvar-LC_MESSAGES>, \fBLC_ALL\fP \%<#\:envvar-LC_ALL>, and \fBLANGUAGE\fP \%<#\:envvar-LANGUAGE>\&.
These variables do not have to be exported for fish to use them, and fish\(aqs variable scopes are supported.
If other programs launched via fish should respect these locale variables they have to be exported to make them available outside of fish.
.sp
For \fBLANGUAGE\fP \%<#\:envvar-LANGUAGE> you can use a list, or use colons to separate multiple languages.
.sp
If the status language set \%<#\:status-language> command was used, its arguments specify the language precedence, and the environment variables are ignored.
.SS Options
.sp
\fB_\fP takes no options.
.SS Examples
.sp
Use German translations:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set LANG de_DE.UTF\-8
> _ file
Datei
.EE
.UNINDENT
.UNINDENT
.sp
Specify a precedence of languages (only works with \fBLANGUAGE\fP \%<#\:envvar-LANGUAGE>):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set LANGUAGE pt de
> _ file # This message has a Portuguese translation.
arquivo
> _ \(dqInvalid arguments\(dq # This message does not have a Portuguese translation, but a German one.
Ungültige Argumente
> _ untranslatable # No translation in Portuguese, nor in German.
untranslatable
.EE
.UNINDENT
.UNINDENT
.sp
Note that the specific examples may change if translations are added/modified.
.SS abbr \- manage fish abbreviations
.SS Synopsis
.nf
\fBabbr\fP \fB\-\-add\fP \fINAME\fP [\fB\-\-position\fP \fBcommand\fP | \fBanywhere\fP] [\fB\-r\fP | \fB\-\-regex\fP \fIPATTERN\fP] [\fB\-c\fP | \fB\-\-command\fP \fICOMMAND\fP]
[\fB\-\-set\-cursor\fP[\fB=\fP\fIMARKER\fP]] ([\fB\-f\fP | \fB\-\-function\fP \fIFUNCTION\fP] | \fIEXPANSION\fP)
\fBabbr\fP \fB\-\-erase\fP \fB[ \fP[\fB\-c\fP | \fB\-\-command\fP \fICOMMAND\fP]\&...\fB ]\fP \fINAME\fP \&...
\fBabbr\fP \fB\-\-rename\fP \fB[ \fP[\fB\-c\fP | \fB\-\-command\fP \fICOMMAND\fP]\&...\fB ]\fP \fIOLD_WORD\fP \fINEW_WORD\fP
\fBabbr\fP [\fB\-\-show\fP] [\fB\-\-color\fP \fIWHEN\fP]
\fBabbr\fP \fB\-\-list\fP
\fBabbr\fP \fB\-\-query\fP \fINAME\fP \&...
.fi
.sp
.SS Description
.sp
\fBabbr\fP manages abbreviations \- user\-defined words that are replaced with longer phrases when entered.
.sp
\fBNote:\fP
.INDENT 0.0
.INDENT 3.5
Only typed\-in commands use abbreviations. Abbreviations are not expanded in scripts.
.UNINDENT
.UNINDENT
.sp
For example, a frequently\-run command like \fBgit checkout\fP can be abbreviated to \fBgco\fP\&.
After entering \fBgco\fP and pressing \fBspace\fP or \fBenter\fP, the full text \fBgit checkout\fP will appear in the command line.
To avoid expanding something that looks like an abbreviation, the default \fBctrl\fP\-\fBspace\fP binding inserts a space without expanding.
.sp
An abbreviation may match a literal word, or it may match a pattern given by a regular expression. When an abbreviation matches a word, that word is replaced by new text, called its \fIexpansion\fP\&. This expansion may be a fixed new phrase, or it can be dynamically created via a fish function. This expansion occurs after pressing space or enter.
.sp
Combining these features, it is possible to create custom syntaxes, where a regular expression recognizes matching tokens, and the expansion function interprets them. See the Examples section.
.sp
Changed in version 3.6.0: Previous versions of this allowed saving abbreviations in universal variables.
That\(aqs no longer possible. Existing variables will still be imported and \fBabbr \-\-erase\fP will also erase the variables.
We recommend adding abbreviations to config.fish \%<#\:configuration> by just adding the \fBabbr \-\-add\fP command.
When you run \fBabbr\fP, you will see output like this
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> abbr
abbr \-a \-\- foo bar # imported from a universal variable, see \(gahelp abbr\(ga
.EE
.UNINDENT
.UNINDENT
.sp
In that case you should take the part before the \fB#\fP comment and save it in config.fish \%<#\:configuration>,
then you can run \fBabbr \-\-erase\fP to remove the universal variable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> abbr >> ~/.config/fish/config.fish
> abbr \-\-erase (abbr \-\-list)
.EE
.UNINDENT
.UNINDENT
.sp
Alternatively you can keep them in a separate configuration file \%<#\:configuration> by doing something like the following:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> abbr > ~/.config/fish/conf.d/myabbrs.fish
.EE
.UNINDENT
.UNINDENT
.sp
This will save all your abbreviations in \(dqmyabbrs.fish\(dq, overwriting the whole file so it doesn\(aqt leave any duplicates,
or restore abbreviations you had erased.
Of course any functions will have to be saved separately, see funcsave \%<>\&.
.SS \(dqadd\(dq subcommand
.nf
\fBabbr\fP [\fB\-a\fP | \fB\-\-add\fP] \fINAME\fP [\fB\-\-position\fP \fBcommand\fP | \fBanywhere\fP] [\fB\-r\fP | \fB\-\-regex\fP \fIPATTERN\fP]
[\fB\-c\fP | \fB\-\-command\fP \fICOMMAND\fP] [\fB\-\-set\-cursor\fP[\fB=\fP\fIMARKER\fP]] ([\fB\-f\fP | \fB\-\-function\fP \fIFUNCTION\fP] | \fIEXPANSION\fP)
.fi
.sp
.sp
\fBabbr \-\-add\fP creates a new abbreviation. With no other options, the string \fBNAME\fP is replaced by \fBEXPANSION\fP\&.
.sp
With \fB\-\-position command\fP, the abbreviation will only expand when it is positioned as a command, not as an argument to another command. With \fB\-\-position anywhere\fP the abbreviation may expand anywhere in the command line. The default is \fBcommand\fP\&.
.sp
With \fB\-\-command COMMAND\fP, the abbreviation will only expand when it is used as an argument to the given COMMAND. Multiple \fB\-\-command\fP can be used together, and the abbreviation will expand for each. An empty \fBCOMMAND\fP means it will expand only when there is no command. \fB\-\-command\fP implies \fB\-\-position anywhere\fP and disallows \fB\-\-position command\fP\&. Even with different \fBCOMMANDS\fP, the \fBNAME\fP of the abbreviation needs to be unique. Consider using \fB\-\-regex\fP if you want to expand the same word differently for multiple commands.
.sp
With \fB\-\-regex\fP, the abbreviation matches using the regular expression given by \fBPATTERN\fP, instead of the literal \fBNAME\fP\&. The pattern is interpreted using PCRE2 syntax and must match the entire token. If multiple abbreviations match the same token, the last abbreviation added is used.
.sp
With \fB\-\-set\-cursor=MARKER\fP, the cursor is moved to the first occurrence of \fBMARKER\fP in the expansion. The \fBMARKER\fP value is erased. The \fBMARKER\fP may be omitted (i.e. simply \fB\-\-set\-cursor\fP), in which case it defaults to \fB%\fP\&.
.sp
With \fB\-f FUNCTION\fP or \fB\-\-function FUNCTION\fP, \fBFUNCTION\fP is treated as the name of a fish function instead of a literal replacement. When the abbreviation matches, the function will be called with the matching token as an argument. If the function\(aqs exit status is 0 (success), the token will be replaced by the function\(aqs output; otherwise the token will be left unchanged. No \fBEXPANSION\fP may be given separately.
.sp
The description set by \fB\-\-description=DESCRIPTION\fP will be added to the completion description in the completion pager.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-\-add gco git checkout
.EE
.UNINDENT
.UNINDENT
.sp
Add a new abbreviation where \fBgco\fP will be replaced with \fBgit checkout\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-a \-\-position anywhere \-\- \-C \-\-color
.EE
.UNINDENT
.UNINDENT
.sp
Add a new abbreviation where \fB\-C\fP will be replaced with \fB\-\-color\fP\&. The \fB\-\-\fP allows \fB\-C\fP to be treated as the name of the abbreviation, instead of an option.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-a L \-\-position anywhere \-\-set\-cursor \(dq% | less\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Add a new abbreviation where \fBL\fP will be replaced with \fB| less\fP, placing the cursor before the pipe.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function last_history_item
echo $history[1]
end
abbr \-a !! \-\-position anywhere \-\-function last_history_item
.EE
.UNINDENT
.UNINDENT
.sp
This first creates a function \fBlast_history_item\fP which outputs the last entered command. It then adds an abbreviation which replaces \fB!!\fP with the result of calling this function. Taken together, this is similar to the \fB!!\fP history expansion feature of bash.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function vim_edit
echo vim $argv
end
abbr \-a vim_edit_texts \-\-position command \-\-regex \(dq.+\e.txt\(dq \-\-function vim_edit
.EE
.UNINDENT
.UNINDENT
.sp
This first creates a function \fBvim_edit\fP which prepends \fBvim\fP before its argument. It then adds an abbreviation which matches commands ending in \fB\&.txt\fP, and replaces the command with the result of calling this function. This allows text files to be \(dqexecuted\(dq as a command to open them in vim, similar to the \(dqsuffix alias\(dq feature in zsh.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr 4DIRS \-\-set\-cursor=! \(dq$(string join \en \-\- \(aqfor dir in */\(aq \(aqcd $dir\(aq \(aq!\(aq \(aqcd ..\(aq \(aqend\(aq)\(dq
.EE
.UNINDENT
.UNINDENT
.sp
This creates an abbreviation \(dq4DIRS\(dq which expands to a multi\-line loop \(dqtemplate.\(dq The template enters each directory and then leaves it. The cursor is positioned ready to enter the command to run in each directory, at the location of the \fB!\fP, which is itself erased.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-\-command git co checkout
.EE
.UNINDENT
.UNINDENT
.sp
Turns \(dqco\(dq as an argument to \(dqgit\(dq into \(dqcheckout\(dq. Multiple commands are possible, \fB\-\-command={git,hg}\fP would expand \(dqco\(dq to \(dqcheckout\(dq for both git and hg.
.SS Other subcommands
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-\-rename [ [\-c | \-\-command COMMAND]... ] OLD_NAME NEW_NAME
.EE
.UNINDENT
.UNINDENT
.sp
Renames an abbreviation, from \fIOLD_NAME\fP to \fINEW_NAME\fP\&.
For command\-specific abbreviations, the \fB\-\-command\fP options must be provided to disambiguate which abbreviation to rename.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr [\-s | \-\-show]
.EE
.UNINDENT
.UNINDENT
.sp
Show all abbreviations in a manner suitable for import and export
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr [\-l | \-\-list]
.EE
.UNINDENT
.UNINDENT
.sp
Prints the names of all abbreviation
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr [\-e | \-\-erase] [ [\-c | \-\-command COMMAND]... ] NAME ...
.EE
.UNINDENT
.UNINDENT
.sp
Erases the abbreviation with the given name.
For command\-specific abbreviations, the \fB\-\-command\fP options must be provided to disambiguate which abbreviation to rename.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-q or \-\-query [NAME...]
.EE
.UNINDENT
.UNINDENT
.sp
Return 0 (true) if one of the \fINAME\fP is an abbreviation.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
abbr \-h or \-\-help
.EE
.UNINDENT
.UNINDENT
.sp
Displays help for the \fIabbr\fP command.
.SS alias \- create a function
.SS Synopsis
.nf
\fBalias\fP
\fBalias\fP [\fB\-\-save\fP] \fINAME\fP \fIDEFINITION\fP
\fBalias\fP [\fB\-\-save\fP] \fINAME\fP\fB=\fP\fIDEFINITION\fP
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBalias\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man alias\fP\&.
.sp
\fBalias\fP is a simple wrapper for the \fBfunction\fP builtin, which creates a function wrapping a command. It has similar syntax to POSIX shell \fBalias\fP\&. For other uses, it is recommended to define a function \%<>\&.
.sp
If you want to ease your interactive use, to save typing, consider using an abbreviation \%<> instead.
.sp
\fBfish\fP marks functions that have been created by \fBalias\fP by including the command used to create them in the function description. You can list \fBalias\fP\-created functions by running \fBalias\fP without arguments. They must be erased using \fBfunctions \-e\fP\&.
.INDENT 0.0
.IP \(bu 2
\fBNAME\fP is the name of the alias
.IP \(bu 2
\fBDEFINITION\fP is the actual command to execute. \fBalias\fP automatically appends \fB$argv\fP, so that all parameters used with the alias are passed to the actual command.
.UNINDENT
.sp
You cannot create an alias to a function with the same name. Note that spaces need to be escaped in the call to \fBalias\fP just like at the command line, \fIeven inside quoted parts\fP\&.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.TP
\fB\-s\fP or \fB\-\-save\fP
Saves the function created by the alias into your fish configuration directory using funcsave \%<>\&.
.UNINDENT
.SS Example
.sp
The following code will create \fBrmi\fP, which runs \fBrm\fP with additional arguments on every invocation.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
alias rmi=\(dqrm \-i\(dq
# This is equivalent to entering the following function:
function rmi \-\-wraps rm \-\-description \(aqalias rmi=rm \-i\(aq
rm \-i $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
\fBalias\fP sometimes requires escaping, as you can see here:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# This needs to have the spaces escaped or \(dqChrome.app...\(dq
# will be seen as an argument to \(dq/Applications/Google\(dq:
alias chrome=\(aq/Applications/Google\e Chrome.app/Contents/MacOS/Google\e Chrome\(aq
.EE
.UNINDENT
.UNINDENT
.SS See more
.INDENT 0.0
.IP 1. 3
The function \%<> command this builds on.
.IP 2. 3
Functions \%<#\:syntax-function>\&.
.IP 3. 3
Defining aliases \%<#\:syntax-aliases>\&.
.UNINDENT
.SS and \- conditionally execute a command
.SS Synopsis
.nf
\fIPREVIOUS\fP\fB;\fP \fBand\fP \fICOMMAND\fP
.fi
.sp
.SS Description
.sp
\fBand\fP is used to execute a command if the previous command was successful (returned a status of 0).
.sp
\fBand\fP statements may be used as part of the condition in an while \%<> or if \%<> block.
.sp
\fBand\fP does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status \%<#\:variables-status> variable.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code runs the \fBmake\fP command to build a program. If the build succeeds, \fBmake\fP\(aqs exit status is 0, and the program is installed. If either step fails, the exit status is 1, and \fBmake clean\fP is run, which removes the files created by the build process.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
make; and make install; or make clean
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
or \%<> command
.IP \(bu 2
not \%<> command
.UNINDENT
.SS argparse \- parse options passed to a fish script or function
.SS Synopsis
.nf
\fBargparse\fP [\fIOPTIONS\fP] \fIOPTION_SPEC\fP \&... \fB\-\-\fP [\fIARG\fP \&...]
.fi
.sp
.SS Description
.sp
This command makes it easy for fish scripts and functions to handle arguments. You pass arguments that define the known options, followed by a literal \fB\-\-\fP, then the arguments to be parsed (which might also include a literal \fB\-\-\fP). \fBargparse\fP then sets variables to indicate the passed options with their values, sets \fB$argv_opts\fP to the options and their values, and sets \fB$argv\fP to the remaining arguments. See the usage section below.
.sp
Each option specification (\fBOPTION_SPEC\fP) is written in the domain specific language described below. All OPTION_SPECs must appear after any argparse flags and before the \fB\-\-\fP that separates them from the arguments to be parsed.
.sp
Each option that is seen in the ARG list will result in variables named \fB_flag_X\fP, where \fBX\fP is the short flag letter and the long flag name (if they are defined). For example a \fB\-\-help\fP option could cause argparse to define one variable called \fB_flag_h\fP and another called \fB_flag_help\fP\&.
.sp
The variables will be set with local scope (i.e., as if the script had done \fBset \-l _flag_X\fP). If the flag is a boolean (that is, it is passed or not, it doesn\(aqt have a value) the values are the short and long flags seen. If the option is not a boolean the values will be zero or more values corresponding to the values collected when the ARG list is processed. If the flag was not seen the flag variable will not be set.
.SS Options
.sp
The following \fBargparse\fP options are available. They must appear before all \fIOPTION_SPEC\fPs:
.INDENT 0.0
.TP
\fB\-n\fP or \fB\-\-name\fP \fINAME\fP
Use \fINAME\fP in error messages. By default the current function name will be used, or \fBargparse\fP if run outside of a function.
.TP
\fB\-x\fP or \fB\-\-exclusive\fP \fIOPTIONS\fP
A comma separated list of options that are mutually exclusive. You can use this more than once to define multiple sets of mutually exclusive options.
You give either the short or long version of each option, and you still need to otherwise define the options.
.TP
\fB\-N\fP or \fB\-\-min\-args\fP \fINUMBER\fP
The minimum number of acceptable non\-option arguments. The default is zero.
.TP
\fB\-X\fP or \fB\-\-max\-args\fP \fINUMBER\fP
The maximum number of acceptable non\-option arguments. The default is infinity.
.TP
\fB\-u\fP or \fB\-\-move\-unknown\fP
Allow unknown options, and move them from \fB$argv\fP to \fB$argv_opts\fP\&. By default, Unknown options are treated as if they take optional arguments (i.e. have option spec \fB=?\fP).
.sp
The above means that if a group of short options contains an unknown short option \fIfollowed\fP by a known short option, the known short option is
treated as an argument to the unknown one (e.g. \fB\-\-move\-unknown h \-\- \-oh\fP will treat \fBh\fP as the argument to \fB\-o\fP, and so \fB_flag_h\fP will \fInot\fP be set).
In contrast, if the known option comes first (and does not take any arguments), the known option will be recognised (e.g. \fBargparse \-\-move\-unknown h \-\- \-ho\fP \fIwill\fP set \fB$_flag_h\fP to \fB\-h\fP)
.TP
\fB\-i\fP or \fB\-\-ignore\-unknown\fP
Deprecated. This is like \fB\-\-move\-unknown\fP, except that unknown options and their arguments are kept in \fB$argv\fP and not moved to \fB$argv_opts\fP\&. Unlike \fB\-\-move\-unknown\fP, this option makes it impossible to distinguish between an unknown option and non\-option argument that starts with a \fB\-\fP (since any \fB\-\-\fP separator in \fB$argv\fP will be removed).
.TP
\fB\-S\fP or \fB\-\-strict\-longopts\fP
This makes the parsing of long options more strict. In particular, \fIwithout\fP this flag, if \fBlong\fP is a known long option flag, \fB\-\-long\fP and \fB\-\-long=\fP can be abbreviated as:
.INDENT 7.0
.IP \(bu 2
\fB\-long\fP and \fB\-long=\fP, but \fIonly\fP if there is no short flag \fBl\fP\&.
.IP \(bu 2
\fB\-\-lo\fP and \fB\-\-lo=\fP, but \fIonly\fP if there is no other long flag that starts with \fBlo\fP\&. Similarly with any other non\-empty prefix of \fBlong\fP\&.
.IP \(bu 2
\fB\-lo\fP and \fB\-lo=\fP (i.e. combining the above two).
.UNINDENT
.sp
With the \fB\-\-strict\-longopts\fP flag, the above three are parse errors: one must use the syntax \fB\-\-long\fP or \fB\-\-long=\fP to use a long option called \fBlong\fP\&.
.sp
This flag has no effect on the parsing of unknown options (which are parsed as if this flag is on).
.sp
This option may be on all the time in the future, so do not rely on the behaviour without it.
.TP
\fB\-\-unknown\-arguments\fP \fIKIND\fP
This option implies \fB\-\-move\-unknown\fP, unless \fB\-\-ignore\-unknown\fP is also given.
This will modify the parsing behaviour of unknown options depending on the value of \fIKIND\fP:
.INDENT 7.0
.INDENT 3.5
.INDENT 0.0
.IP \(bu 2
\fBoptional\fP (the default), allows each unknown option to take an optional argument (i.e. as if it had \fB=?\fP or \fB=*\fP in its option specification). For example, \fBargparse \-\-ignore\-unknown \-\-unknown\-arguments=optional ab \-\- \-u \-a \-ub\fP will set \fB_flag_a\fP but \fInot\fP \fB_flag_b\fP, as the \fBb\fP is treated as an argument to the second use of \fB\-u\fP\&.
.IP \(bu 2
\fBrequired\fP requires each unknown option to take an argument (i.e. as if it had \fB=\fP or \fB=+\fP in its option specification). If the above example was changed to use \fB\-\-unknown\-arguments=required\fP, \fIneither\fP \fB_flag_a\fP nor \fB_flag_b\fP would be set: the \fB\-a\fP will be treated as an argument to the first use of \fB\-u\fP, and the \fBb\fP as an argument to the second.
.IP \(bu 2
\fBnone\fP forbids each unknown option from taking an argument (i.e. as if it had no \fB=\fP in its option specification). If the above example was changed to use \fB\-\-unknown\-arguments=none\fP, \fIboth\fP \fB_flag_a\fP and \fB_flag_b\fP would be set, as neither use of \fB\-u\fP will be passed as taking an argument.
.UNINDENT
.sp
Note that the above assumes that unknown long flags use the \fB\-\-\fP \(dqGNU\-style\(dq (e.g. if \fIKIND\fP is \fBnone\fP, and there is no \fBbar\fP long option, \fB\-bar\fP is interpreted as three short flags, \fBb\fP, \fBa\fP, and \fBr\fP; but if \fBbar\fP is known, \fB\-bar\fP is treated the same as \fB\-\-bar\fP).
.sp
When using \fB\-\-unknown\-arguments=required\fP, you will get an error if the provided arguments end in an unknown option, since it has no argument. Similarly, with \fB\-\-unknown\-arguments=none\fP, you will get an error if you use the \fB\-\-flag=value\fP syntax and \fBflag\fP is an unknown option.
.UNINDENT
.UNINDENT
.TP
\fB\-s\fP or \fB\-\-stop\-nonopt\fP
Causes scanning the arguments to stop as soon as the first non\-option argument is seen. Among other things, this is useful to implement subcommands that have their own options.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Usage
.sp
To use this command, pass the option specifications (\fBOPTION_SPEC\fP), a mandatory \fB\-\-\fP, and then the arguments to be parsed.
.sp
A simple example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
argparse \(aqh/help\(aq \(aqn/name=\(aq \-\- $argv
or return
.EE
.UNINDENT
.UNINDENT
.sp
If \fB$argv\fP is empty then there is nothing to parse and \fBargparse\fP returns zero to indicate success. If \fB$argv\fP is not empty then it is checked for flags \fB\-h\fP, \fB\-\-help\fP, \fB\-n\fP and \fB\-\-name\fP\&. If they are found they are removed from the arguments and local variables called \fB_flag_OPTION\fP are set so the script can determine which options were seen. If \fB$argv\fP doesn\(aqt have any errors, like an unknown option or a missing mandatory value for an option, then \fBargparse\fP exits with a status of zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one.
.sp
The \fBor return\fP means that the function returns \fBargparse\fP\(aqs status if it failed, so if it goes on \fBargparse\fP succeeded.
.sp
To use the flags argparse has extracted:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Checking for _flag_h and _flag_help is equivalent
# We check if it has been given at least once
if set \-ql _flag_h
echo \(dqUsage: my_function [\-h | \-\-help] [\-n | \-\-name=NAME]\(dq >&2
return 1
end
set \-l myname somedefault
set \-ql _flag_name[1]
and set myname $_flag_name[\-1] # here we use the *last* \-\-name=
.EE
.UNINDENT
.UNINDENT
.sp
Any characters in the flag name that are not valid in a variable name (like \fB\-\fP dashes) will be replaced with underscores.
.sp
The \fB\-\-\fP argument is required. You do not have to include any option specifications or arguments after the \fB\-\-\fP but you must include the \fB\-\-\fP\&. For example, this is acceptable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l argv foo
argparse \(aqh/help\(aq \(aqn/name\(aq \-\- $argv
argparse \-\-min\-args=1 \-\- $argv
.EE
.UNINDENT
.UNINDENT
.sp
But this is not:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l argv
argparse \(aqh/help\(aq \(aqn/name\(aq $argv
.EE
.UNINDENT
.UNINDENT
.sp
The first \fB\-\-\fP seen is what allows the \fBargparse\fP command to reliably separate the option specifications and options to \fBargparse\fP itself (like \fB\-\-move\-unknown\fP) from the command arguments, so it is required.
.SS Option Specifications
.sp
Each option specification consists of:
.INDENT 0.0
.IP \(bu 2
An optional alphanumeric short flag character.
.IP \(bu 2
An optional long flag name preceded by a \fB/\fP\&. If neither a short flag nor long flag are present, an error is reported.
.INDENT 2.0
.INDENT 3.5
.INDENT 0.0
.IP \(bu 2
If there is no short flag, and the long flag name is more than one character, the \fB/\fP can be omitted.
.IP \(bu 2
For backwards compatibility, if there is a short and a long flag, a \fB\-\fP can be used in place of the \fB/\fP, if the short flag is not to be usable by users (in which case it will also not be exposed as a flag variable).
.UNINDENT
.UNINDENT
.UNINDENT
.IP \(bu 2
Nothing if the flag is a boolean that takes no argument or is an integer flag, or
.INDENT 2.0
.INDENT 3.5
.INDENT 0.0
.IP \(bu 2
\fB=\fP if it requires a value and only the last instance of the flag is saved, or
.IP \(bu 2
\fB=?\fP if it takes an optional value and only the last instance of the flag is saved, or
.IP \(bu 2
\fB=+\fP if it requires a value and each instance of the flag is saved, or
.IP \(bu 2
\fB=*\fP if it takes an optional value \fIand\fP each instance of the flag is saved, storing the empty string when the flag was not given a value.
.UNINDENT
.UNINDENT
.UNINDENT
.IP \(bu 2
Optionally a \fB&\fP, indicating that the option and any attached values are not to be saved in \fB$argv\fP or \fB$argv_opts\fP\&. This does not affect the the \fB_flag_\fP variables.
.IP \(bu 2
Nothing if the flag is a boolean that takes no argument, or
.INDENT 2.0
.INDENT 3.5
.INDENT 0.0
.IP \(bu 2
\fB!\fP followed by fish script to validate the value. Typically this will be a function to run. If the exit status is zero the value for the flag is valid. If non\-zero the value is invalid. Any error messages should be written to stdout (not stderr). See the section on Flag Value Validation for more information.
.UNINDENT
.UNINDENT
.UNINDENT
.UNINDENT
.sp
See the fish_opt \%<> command for a friendlier but more verbose way to create option specifications.
.sp
If a flag is not seen when parsing the arguments then the corresponding _flag_X var(s) will not be set.
.SS Integer flag
.sp
Sometimes commands take numbers directly as options, like \fBfoo \-55\fP\&. To allow this one option spec can have the \fB#\fP modifier so that any integer will be understood as this flag, and the last number will be given as its value (as if \fB=\fP was used).
.sp
The \fB#\fP must follow the short flag letter (if any), and other modifiers like \fB=\fP are not allowed, except for \fB\-\fP (for backwards compatibility):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
m#maximum
.EE
.UNINDENT
.UNINDENT
.sp
This does not read numbers given as \fB+NNN\fP, only those that look like flags \- \fB\-NNN\fP\&.
.SS Note: Optional arguments
.sp
An option defined with \fB=?\fP or \fB=*\fP can take optional arguments. Optional arguments have to be \fIdirectly attached\fP to the option they belong to.
.sp
That means the argument will only be used for the option if you use it like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cmd \-\-flag=value
# or
cmd \-fvalue
.EE
.UNINDENT
.UNINDENT
.sp
but not if used like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cmd \-\-flag value
# \(dqvalue\(dq here will be used as a positional argument
# and \(dq\-\-flag\(dq won\(aqt have an argument.
.EE
.UNINDENT
.UNINDENT
.sp
If this weren\(aqt the case, using an option without an optional argument would be difficult if you also wanted to use positional arguments.
.sp
For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
grep \-\-color auto
# Here \(dqauto\(dq will be used as the search string,
# \(dqcolor\(dq will not have an argument and will fall back to the default,
# which also *happens to be* auto.
grep \-\-color always
# Here grep will still only use color \(dqauto\(dqmatically
# and search for the string \(dqalways\(dq.
.EE
.UNINDENT
.UNINDENT
.sp
This isn\(aqt specific to argparse but common to all things using \fBgetopt(3)\fP (if they have optional arguments at all). That \fBgrep\fP example is how GNU grep actually behaves.
.SS Flag Value Validation
.sp
Sometimes you need to validate the option values. For example, that it is a valid integer within a specific range, or an ip address, or something entirely different. You can always do this after \fBargparse\fP returns but you can also request that \fBargparse\fP perform the validation by executing arbitrary fish script. To do so append an \fB!\fP (exclamation\-mark) then the fish script to be run. When that code is executed three vars will be defined:
.INDENT 0.0
.IP \(bu 2
\fB_argparse_cmd\fP will be set to the value of the value of the \fBargparse \-\-name\fP value.
.IP \(bu 2
\fB_flag_name\fP will be set to the short or long flag that being processed.
.IP \(bu 2
\fB_flag_value\fP will be set to the value associated with the flag being processed.
.UNINDENT
.sp
These variables are passed to the function as local exported variables.
.sp
The script should write any error messages to stdout, not stderr. It should return a status of zero if the flag value is valid otherwise a non\-zero status to indicate it is invalid.
.sp
fish ships with a \fB_validate_int\fP function that accepts a \fB\-\-min\fP and \fB\-\-max\fP flag. Let\(aqs say your command accepts a \fB\-m\fP or \fB\-\-max\fP flag and the minimum allowable value is zero and the maximum is 5. You would define the option like this: \fBm/max=!_validate_int \-\-min 0 \-\-max 5\fP\&. The default if you call \fB_validate_int\fP without those flags is to check that the value is a valid integer with no limits on the min or max value allowed.
.sp
Here are some examples of flag validations:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# validate that a path is a directory
argparse \(aqp/path=!test \-d \(dq$_flag_value\(dq\(aq \-\- \-\-path $__fish_config_dir
# validate that a function does not exist
argparse \(aqf/func=!not functions \-q \(dq$_flag_value\(dq\(aq \-\- \-f alias
# validate that a string matches a regex
argparse \(aqc/color=!string match \-rq \e\(aq^#?[0\-9a\-fA\-F]{6}$\e\(aq \(dq$_flag_value\(dq\(aq \-\- \-c \(aqc0ffee\(aq
# validate with a validator function
argparse \(aqn/num=!_validate_int \-\-min 0 \-\-max 99\(aq \-\- \-\-num 42
.EE
.UNINDENT
.UNINDENT
.SS Example OPTION_SPECs
.sp
Some \fIOPTION_SPEC\fP examples:
.INDENT 0.0
.IP \(bu 2
\fBh/help\fP means that both \fB\-h\fP and \fB\-\-help\fP are valid. The flag is a boolean and can be used more than once. If either flag is used then \fB_flag_h\fP and \fB_flag_help\fP will be set to however either flag was seen, as many times as it was seen. So it could be set to \fB\-h\fP, \fB\-h\fP and \fB\-\-help\fP, and \fBcount $_flag_h\fP would yield \(dq3\(dq.
.IP \(bu 2
\fBhelp\fP means that only \fB\-\-help\fP is valid. The flag is a boolean and can be used more than once. If it is used then \fB_flag_help\fP will be set as above. Also \fBh\-help\fP (with an arbitrary short letter) for backwards compatibility.
.IP \(bu 2
\fBhelp&\fP is similar (it will \fIremove\fP \fB\-\-help\fP from \fB$argv\fP), the difference is that \fB\-\-help\(ga\fP will \fInot\fP placed in \fB$argv_opts\fP\&.
.IP \(bu 2
\fBlongonly=\fP is a flag \fB\-\-longonly\fP that requires an option, there is no short flag or even short flag variable.
.IP \(bu 2
\fBn/name=\fP means that both \fB\-n\fP and \fB\-\-name\fP are valid. It requires a value and can be used at most once. If the flag is seen then \fB_flag_n\fP and \fB_flag_name\fP will be set with the single mandatory value associated with the flag.
.IP \(bu 2
\fBn/name=?\fP means that both \fB\-n\fP and \fB\-\-name\fP are valid. It accepts an optional value and can be used at most once. If the flag is seen then \fB_flag_n\fP and \fB_flag_name\fP will be set with the value associated with the flag if one was provided else it will be set with no values.
.IP \(bu 2
\fBn/name=*\fP is similar, but the flag can be used more than once. If the flag is seen then \fB_flag_n\fP and \fB_flag_name\fP will be set with the values associated with each occurrence. Each value will be the value given to the option, or the empty string if no value was given.
.IP \(bu 2
\fBname=+\fP means that only \fB\-\-name\fP is valid. It requires a value and can be used more than once. If the flag is seen then \fB_flag_name\fP will be set with the values associated with each occurrence.
.IP \(bu 2
\fBx\fP means that only \fB\-x\fP is valid. It is a boolean that can be used more than once. If it is seen then \fB_flag_x\fP will be set as above.
.IP \(bu 2
\fB/x\fP is similar, but only \fB\-\-x\fP is valid (instead of \fB\-x\fP).
.IP \(bu 2
\fBx=\fP, \fBx=?\fP, and \fBx=+\fP are similar to the n/name examples above but there is no long flag alternative to the short flag \fB\-x\fP\&.
.IP \(bu 2
\fB#max\fP (or \fB#\-max\fP) means that flags matching the regex \(dq^\-\-?\ed+$\(dq are valid. When seen they are assigned to the variable \fB_flag_max\fP\&. This allows any valid positive or negative integer to be specified by prefixing it with a single \(dq\-\(dq. Many commands support this idiom. For example \fBhead \-3 /a/file\fP to emit only the first three lines of /a/file.
.IP \(bu 2
\fBn#max\fP means that flags matching the regex \(dq^\-\-?\ed+$\(dq are valid. When seen they are assigned to the variables \fB_flag_n\fP and \fB_flag_max\fP\&. This allows any valid positive or negative integer to be specified by prefixing it with a single \(dq\-\(dq. Many commands support this idiom. For example \fBhead \-3 /a/file\fP to emit only the first three lines of /a/file. You can also specify the value using either flag: \fB\-n NNN\fP or \fB\-\-max NNN\fP in this example.
.IP \(bu 2
\fB#longonly\fP causes the last integer option to be stored in \fB_flag_longonly\fP\&.
.UNINDENT
.sp
After parsing the arguments the \fBargv\fP variable is set with local scope to any values not already consumed during flag processing. If there are no unbound values the variable is set but \fBcount $argv\fP will be zero. Similarly, the \fBargv_opts\fP variable is set with local scope to the arguments that \fIwere\fP consumed during flag processing. This allows forwarding \fB$argv_opts\fP to another command, together with additional arguments.
.sp
If an error occurs during argparse processing it will exit with a non\-zero status and print error messages to stderr.
.SS Examples
.sp
A simple use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
argparse h/help \-\- $argv
or return
if set \-q _flag_help
# TODO: Print help here
return 0
end
.EE
.UNINDENT
.UNINDENT
.sp
This supports one option \- \fB\-h\fP / \fB\-\-help\fP\&. Any other option is an error. If it is given it prints help and exits.
.sp
How fish_add_path \- add to the path \%<> parses its args:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
argparse \-x g,U \-x P,U \-x a,p g/global U/universal P/path p/prepend a/append h/help m/move v/verbose n/dry\-run \-\- $argv
.EE
.UNINDENT
.UNINDENT
.sp
There are a variety of boolean flags, all with long and short versions. A few of these cannot be used together, and that is what the \fB\-x\fP flag is used for.
\fB\-x g,U\fP means that \fB\-\-global\fP and \fB\-\-universal\fP or their short equivalents conflict, and if they are used together you get an error.
In this case you only need to give the short or long flag, not the full option specification.
.sp
After this it figures out which variable it should operate on according to the \fB\-\-path\fP flag:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l var fish_user_paths
set \-q _flag_path
and set var PATH
# ...
# Check for \-\-dry\-run.
# The \(dq\-\(dq has been replaced with a \(dq_\(dq because
# it is not valid in a variable name
not set \-ql _flag_dry_run
and set $var $result
.EE
.UNINDENT
.UNINDENT
.sp
An example of using \fB$argv_opts\fP to forward known options to another command, whilst adding new options:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function my\-head
# The following option is the only existing one to head that takes arguments
# (we will forward it verbatim).
set \-l opt_spec n/lines=
# \-\-qwords is a new option, but \-\-bytes is an existing one which we will modify below
set \-a opt_spec \(dqqwords=&\(dq \(dqc/bytes=&\(dq
argparse \-\-strict\-longopts \-\-move\-unknown \-\-unknown\-arguments=none $opt_spec \-\- $argv || return
if set \-q _flag_qwords
# \-\-qwords allows specifying the size in multiples of 8 bytes
set \-a argv_opts \-\-bytes=(math \-\- $_flag_qwords \e* 8 || return)
else if set \-q _flag_bytes
# Allows using a \(aqq\(aq suffix, e.g. \-\-bytes=4q to mean 4*8 bytes.
if string match \-qr \(aqq$\(aq \-\- $_flag_bytes
set \-a argv_opts \-\-bytes=(math \-\- (string replace \-r \(aqq$\(aq \(aq*8\(aq \-\- $_flag_bytes) || return)
else
# Keep the users setting
set \-a argv_opts \-\-bytes=$_flag_bytes
end
end
if test (count $argv) \-eq 0
# Default to heading /dev/kmsg (whereas head defaults to stdin)
set \-l argv /dev/kmsg
end
# Call the real head with our modified options and arguments.
head $argv_opts \-\- $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
The argparse call above saves all the options we do \fInot\fP want to process in \fB$argv_opts\fP\&. (The \fB\-\-qwords\fP and \fB\-\-bytes\fP options are \fInot\fP saved there as their option spec\(aqs end in a \fB~\fP). The code then processes the \fB\-\-qwords\fP and \fB\-\-bytess\fP options using the the \fB$_flag_OPTION\fP variables, and puts the transformed options in \fB$argv_opts\fP (which already contains all the original options, \fIother\fP than \fB\-\-qwords\fP and \fB\-\-bytes\fP).
.sp
Note that because the \fBargparse\fP call above uses \fB\-\-move\-unknown\fP and \fB\-\-unknown\-arguments=none\fP, we only need to tell it the arguments to \fBhead\fP that take a value. This allows the wrapper script to accurately work out the \fInon\fP\-option arguments (i.e. \fB$argv\fP, the filenames that \fBhead\fP is to operate on). Using \fB\-\-unknown\-arguments=optional\fP and explicitly listing all the known options to \fBhead\fP however would have the advantage that if \fBhead\fP were to add new options, they could still be used with the wrapper script using the \(dqstuck\(dq form for arguments (e.g. \fB\-o\fP, or \fB\-\-opt=\fP).
.sp
Note that the \fB\-\-strict\-longopts\fP is required to be able to correctly pass short options, e.g. without it \fBmy\-head \-q \-\-bytes 10q\fP, will actually parse the \fB\-q\fP as shorthand for \fB\-\-qwords\fP\&.
.SS begin \- start a new block of code
.SS Synopsis
.nf
\fBbegin\fP\fB;\fP [\fICOMMANDS\fP \&...]\fB;\fP \fBend\fP
\fB{ \fP[\fICOMMANDS\fP \&...]\fB }\fP
.fi
.sp
.SS Description
.sp
\fBbegin\fP is used to create a new block of code.
.sp
A block allows the introduction of a new variable scope \%<#\:variables-scope>, redirection of the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like \fBand\fP\&.
.sp
The block is unconditionally executed. \fBbegin; ...; end\fP is equivalent to \fBif true; ...; end\fP\&.
.sp
\fBbegin\fP does not change the current exit status itself. After the block has completed, \fB$status\fP will be set to the status returned by the most recent command.
.sp
Some other shells only support the \fB{ [COMMANDS ...] ; }\fP notation.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
begin
set \-l PIRATE Yarrr
...
end
echo $PIRATE
# This will not output anything, since the PIRATE variable
# went out of scope at the end of the block
.EE
.UNINDENT
.UNINDENT
.sp
In the following code, all output is redirected to the file out.html.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
begin
echo $xml_header
echo $html_header
if test \-e $file
...
end
...
end > out.html
.EE
.UNINDENT
.UNINDENT
.SS bg \- send jobs to background
.SS Synopsis
.nf
\fBbg\fP [\fIPID\fP \&...]
.fi
.sp
.SS Description
.sp
\fBbg\fP sends jobs \%<#\:syntax-job-control> to the background, resuming them if they are stopped.
.sp
A background job is executed simultaneously with fish, and does not have access to the keyboard. If no job is specified, the last job to be used is put in the background. If \fBPID\fP is specified, the jobs containing the specified process IDs are put in the background.
.sp
A PID of the format \fB%n\fP, where n is an integer, will be interpreted as the PID of job number n. Job numbers can be seen in the output of jobs \%<>\&.
.sp
When at least one of the arguments isn\(aqt a valid job specifier, \fBbg\fP will print an error without backgrounding anything.
.sp
When all arguments are valid job specifiers, \fBbg\fP will background all matching jobs that exist.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The typical use is to run something, stop it with ctrl\-z, and then continue it in the background with bg:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> find / \-name \(dq*.js\(dq >/tmp/jsfiles 2>/dev/null # oh no, this takes too long, let\(aqs press Ctrl\-z!
fish: Job 1, \(aqfind / \-name \(dq*.js\(dq >/tmp/jsfil…\(aq has stopped
> bg
Send job 1 \(aqfind / \-name \(dq*.js\(dq >/tmp/jsfiles 2>/dev/null\(aq to background
> # I can continue using this shell!
> # Eventually:
fish: Job 1, \(aqfind / \-name \(dq*.js\(dq >/tmp/jsfil…\(aq has ended
.EE
.UNINDENT
.UNINDENT
.sp
\fBbg 123 456 789\fP will background the jobs that contain processes 123, 456 and 789.
.sp
If only 123 and 789 exist, it will still background them and print an error about 456.
.sp
\fBbg 123 banana\fP or \fBbg banana 123\fP will complain that \(dqbanana\(dq is not a valid process ID.
.sp
\fBbg %2\fP will background job 2.
.SS bind \- handle fish key bindings
.SS Synopsis
.nf
\fBbind\fP [(\fB\-M\fP | \fB\-\-mode\fP) \fIMODE\fP] [(\fB\-m\fP | \fB\-\-sets\-mode\fP) \fINEW_MODE\fP] [\fB\-\-preset\fP | \fB\-\-user\fP] [\fB\-s\fP | \fB\-\-silent\fP] \fIKEYS\fP \fICOMMAND\fP \&...
\fBbind\fP [(\fB\-M\fP | \fB\-\-mode\fP) \fIMODE\fP] [\fB\-\-preset\fP] [\fB\-\-user\fP] [\fB\-\-color\fP \fIWHEN\fP] [\fIKEYS\fP]
\fBbind\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-\-preset\fP] [\fB\-\-user\fP] [\fB\-\-color\fP \fIWHEN\fP]
\fBbind\fP (\fB\-f\fP | \fB\-\-function\-names\fP)
\fBbind\fP (\fB\-K\fP | \fB\-\-key\-names\fP)
\fBbind\fP (\fB\-L\fP | \fB\-\-list\-modes\fP)
\fBbind\fP (\fB\-e\fP | \fB\-\-erase\fP) [(\fB\-M\fP | \fB\-\-mode\fP) \fIMODE\fP] [\fB\-\-preset\fP] [\fB\-\-user\fP] [\fB\-a\fP | \fB\-\-all\fP] | \fIKEYS\fP \&...
.fi
.sp
.SS Description
.sp
\fBbind\fP manages key bindings.
.sp
If both \fBKEYS\fP and \fBCOMMAND\fP are given, \fBbind\fP adds (or replaces) a binding in \fBMODE\fP\&.
If only \fBKEYS\fP is given, \fBbind\fP lists any existing bindings for those keys in \fBMODE\fP or in all modes.
If no \fBKEYS\fP argument is provided, \fBbind\fP lists all bindings in \fBMODE\fP or in all modes.
.sp
\fBKEYS\fP is a comma\-separated list of key names.
Modifier keys can be specified by prefixing a key name with a combination of \fBctrl\-\fP, \fBalt\-\fP, \fBshift\-\fP and \fBsuper\-\fP (i.e. the \(dqwindows\(dq or \(dqcommand\(dq key).
For example, pressing \fBw\fP while holding the Alt modifier is written as \fBalt\-w\fP\&.
Key names are case\-sensitive; for example \fBalt\-W\fP is the same as \fBalt\-shift\-w\fP\&.
\fBctrl\-x,ctrl\-e\fP would mean pressing \fBctrl\fP\-\fBx\fP followed by \fBctrl\fP\-\fBe\fP\&.
.sp
Some keys have names, usually because they don\(aqt have an obvious printable character representation.
They are:
.INDENT 0.0
.IP \(bu 2
the arrow keys \fBup\fP, \fBdown\fP, \fBleft\fP and \fBright\fP,
.IP \(bu 2
\fBbackspace\fP,
.IP \(bu 2
\fBcomma\fP (\fB,\fP),
.IP \(bu 2
\fBdelete\fP,
.IP \(bu 2
\fBend\fP,
.IP \(bu 2
\fBenter\fP,
.IP \(bu 2
\fBescape\fP,
.IP \(bu 2
\fBf1\fP through \fBf12\fP\&.
.IP \(bu 2
\fBhome\fP,
.IP \(bu 2
\fBinsert\fP,
.IP \(bu 2
\fBmenu\fP,
.IP \(bu 2
\fBminus\fP (\fB\-\fP),
.IP \(bu 2
\fBpageup\fP,
.IP \(bu 2
\fBpagedown\fP,
.IP \(bu 2
\fBprintscreen\fP,
.IP \(bu 2
\fBspace\fP and
.IP \(bu 2
\fBtab\fP,
.UNINDENT
.sp
These names are case\-sensitive.
.sp
An empty value (\fB\(aq\(aq\fP) for \fBKEYS\fP designates the generic binding that will be used if nothing else matches. For most bind modes, it makes sense to bind this to the \fBself\-insert\fP function (i.e. \fBbind \(aq\(aq self\-insert\fP). This will insert any keystrokes that have no bindings otherwise. Non\-printable characters are ignored by the editor, so this will not result in control sequences being inserted.
.sp
To find the name of a key combination you can use fish_key_reader \%<>\&.
.sp
\fBCOMMAND\fP can be any fish command, but it can also be one of a set of special input functions. These include functions for moving the cursor, operating on the kill\-ring, performing tab completion, etc. Use \fBbind \-\-function\-names\fP or see below for a list of these input functions.
.sp
\fBNote:\fP
.INDENT 0.0
.INDENT 3.5
If a script changes the commandline, it should finish by calling the \fBrepaint\fP special input function.
.UNINDENT
.UNINDENT
.sp
Key bindings may use \(dqmodes\(dq, which mimics vi\(aqs modal input behavior. The default mode is \(dqdefault\(dq (in vi\-mode, that\(aqs vi\(aqs \(dqnormal\(dq mode). Every key binding applies to a single mode; you can specify which one with \fB\-M MODE\fP\&. If the key binding should change the mode, you can specify the new mode with \fB\-m NEW_MODE\fP\&. The mode can be viewed and changed via the \fB$fish_bind_mode\fP variable. If you want to change the mode from inside a fish function, use \fBset fish_bind_mode MODE\fP\&.
.sp
To save custom key bindings, put the \fBbind\fP statements into config.fish \%<#\:configuration>\&. Alternatively, fish also automatically executes a function called \fBfish_user_key_bindings\fP if it exists.
.SS Options
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-f\fP or \fB\-\-function\-names\fP
Display a list of available input functions
.TP
\fB\-K\fP or \fB\-\-key\-names\fP
Display a list of available named keys such as \fBbackspace\fP\&.
.TP
\fB\-L\fP or \fB\-\-list\-modes\fP
Display a list of defined bind modes
.TP
\fB\-M MODE\fP or \fB\-\-mode\fP \fIMODE\fP
Specify a bind mode that the bind is used in. Defaults to \(dqdefault\(dq.
If you use vi bindings \%<#\:vi-mode>, that\(aqs the \fIcommand\fP mode,
what vi calls \(dqnormal\(dq mode.
.TP
\fB\-m NEW_MODE\fP or \fB\-\-sets\-mode\fP \fINEW_MODE\fP
Change the current mode to \fINEW_MODE\fP after this binding is executed
.TP
\fB\-e\fP or \fB\-\-erase\fP
Erase the binding with the given sequence and mode instead of defining a new one.
Multiple sequences can be specified with this flag.
Specifying \fB\-a\fP or \fB\-\-all\fP with \fB\-M\fP or \fB\-\-mode\fP erases all binds in the given mode regardless of sequence.
Specifying \fB\-a\fP or \fB\-\-all\fP without \fB\-M\fP or \fB\-\-mode\fP erases all binds in all modes regardless of sequence.
.TP
\fB\-a\fP or \fB\-\-all\fP
See \fB\-\-erase\fP
.TP
\fB\-\-preset\fP and \fB\-\-user\fP
Specify if bind should operate on user or preset bindings.
User bindings take precedence over preset bindings when fish looks up mappings.
By default, all \fBbind\fP invocations work on the \(dquser\(dq level except for listing, which will show both levels.
All invocations except for inserting new bindings can operate on both levels at the same time (if both \fB\-\-preset\fP and \fB\-\-user\fP are given).
\fB\-\-preset\fP should only be used in full binding sets (like when working on \fBfish_vi_key_bindings\fP).
.TP
\fB\-s\fP or \fB\-\-silent\fP
Silences error message for unbound sequences.
.TP
\fB\-\-color\fP \fIWHEN\fP
Controls when to use syntax highlighting colors when listing bindings.
\fIWHEN\fP can be \fBauto\fP (the default, colorize if the output is a terminal \%<>), \fBalways\fP, or \fBnever\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Special input functions
.sp
The following special input functions are available:
.INDENT 0.0
.TP
.B \fBand\fP
only execute the next function if the previous succeeded (note: only some functions report success)
.TP
.B \fBaccept\-autosuggestion\fP
accept the current autosuggestion. Returns false when there was nothing to accept.
.TP
.B \fBbackward\-char\fP
move one character to the left.
If the completion pager is active, select the previous completion instead.
.TP
.B \fBbackward\-char\-passive\fP
move one character to the left, but do not trigger any non\-movement\-related operations. If the cursor is at the start of
the commandline, does nothing. Does not change the selected item in the completion pager UI when shown.
.TP
.B \fBbackward\-token\fP
move one argument to the left
.TP
.B \fBbackward\-delete\-char\fP
deletes one character of input to the left of the cursor
.TP
.B \fBbackward\-kill\-token\fP
move the argument to the left of the cursor to the killring
.TP
.B \fBbackward\-kill\-line\fP
move everything from the beginning of the line to the cursor to the killring
.UNINDENT
.INDENT 0.0
.TP
.B \fBbackward\-kill\-path\-component\fP
move one path component to the left of the cursor to the killring. A path component is everything likely to belong to a path component, i.e. not any of the following: \fI/={,}\(aq\(dq:@ |;<>&\fP, plus newlines and tabs.
.TP
.B \fBbackward\-kill\-word\fP
move the word to the left of the cursor to the killring, until the start of the current word (like vim\(aqs \fBdb\fP)
.TP
.B \fBbackward\-kill\-bigword\fP
move the whitespace\-delimited word to the left of the cursor to the killring, until the start of the current word (like vim\(aqs \fBdB\fP)
.TP
.B \fBbackward\-path\-component\fP
move one path component to the left
.TP
.B \fBbackward\-word\fP
move one word to the left, stopping at the start of the previous word (like vim\(aqs \fBb\fP, or Emacs\(aq \fBM\-b\fP but differs slightly in word division rules)
.TP
.B \fBbackward\-bigword\fP
move one whitespace\-delimited word to the left, stopping at the start of the previous word (like vim\(aqs \fBB\fP)
.TP
.B \fBbackward\-word\-end\fP
move to the end of the previous word (like vim\(aqs \fBge\fP)
.TP
.B \fBbackward\-bigword\-end\fP
move to the end of the previous whitespace\-delimited word (like vim\(aqs \fBgE\fP)
.TP
.B \fBbeginning\-of\-buffer\fP
moves to the beginning of the buffer, i.e. the start of the first line
.TP
.B \fBbeginning\-of\-history\fP
move to the beginning of the history
.TP
.B \fBbeginning\-of\-line\fP
move to the beginning of the line
.TP
.B \fBbegin\-selection\fP
start selecting text
.TP
.B \fBcancel\fP
close the pager if it is open, or undo the most recent completion if one was just inserted
.TP
.B \fBcancel\-commandline\fP
cancel the current commandline and replace it with a new empty one, leaving the old one in place with a marker to show that it was cancelled
.TP
.B \fBcapitalize\-word\fP
make the current word begin with a capital letter
.TP
.B \fBclear\-commandline\fP
empty the entire commandline
.TP
.B \fBclear\-screen\fP
clears the screen and redraws the prompt.
.UNINDENT
.INDENT 0.0
.TP
.B \fBscrollback\-push\fP
pushes earlier output to the terminal scrollback, positioning the prompt at the top.
This requires the terminal to implement the ECMA\-48 SCROLL UP \%<#\:term-compat-indn> command and cursor position reporting \%<#\:term-compat-cursor-position-report>\&.
.TP
.B \fBcomplete\fP
guess the remainder of the current token
.TP
.B \fBcomplete\-and\-search\fP
invoke the searchable pager on completion options (for convenience, this also moves backwards in the completion pager)
.TP
.B \fBdelete\-char\fP
delete one character to the right of the cursor
.TP
.B \fBdelete\-or\-exit\fP
delete one character to the right of the cursor, or exit the shell if the commandline is empty
.TP
.B \fBdown\-line\fP
move down one line
.TP
.B \fBdowncase\-word\fP
make the current word lowercase
.TP
.B \fBend\-of\-buffer\fP
moves to the end of the buffer, i.e. the end of the last line;
or if already at the end of the commandline, accept the current autosuggestion.
.TP
.B \fBend\-of\-history\fP
move to the end of the history
.TP
.B \fBend\-of\-line\fP
move to the end of the line
.TP
.B \fBend\-selection\fP
end selecting text
.TP
.B \fBexpand\-abbr\fP
expands any abbreviation currently under the cursor
.TP
.B \fBexecute\fP
run the current commandline
.TP
.B \fBexit\fP
exit the shell
.TP
.B \fBforward\-token\fP
move one argument to the right
.TP
.B \fBforward\-char\fP
move one character to the right; or if at the end of the commandline, accept the current autosuggestion.
If the completion pager is active, select the next completion instead.
.TP
.B \fBforward\-char\-passive\fP
move one character to the right, but do not trigger any non\-movement\-related operations. If the cursor is at the end of the
commandline, does not accept the current autosuggestion (if any). Does not change the selected item in the completion pager,
if shown.
.TP
.B \fBforward\-path\-component\fP
move one path component to the right; or if at the end of the commandline, accept a path component from the current autosuggestion.
.TP
.B \fBforward\-single\-char\fP
move one character to the right; or if at the end of the commandline, accept a single char from the current autosuggestion.
.UNINDENT
.INDENT 0.0
.TP
.B \fBforward\-word\fP
move one word to the right, stopping after the end of the current word; or if at the end of the commandline, accept one word
from the current autosuggestion.
.TP
.B \fBforward\-word\-vi\fP
like forward\-word, but stops at the start of the next word (like vim\(aqs \fBw\fP)
.TP
.B \fBforward\-word\-end\fP
like forward\-word, but stops at the end of the next word (like vim\(aqs \fBe\fP)
.UNINDENT
.INDENT 0.0
.TP
.B \fBforward\-bigword\fP
move one whitespace\-delimited word to the right, stopping after the end of the current word; or if at the end of the commandline, accept one word from the current autosuggestion.
.TP
.B \fBforward\-bigword\-vi\fP
like forward\-bigword, but stops at the start of the next word (like vim\(aqs \fBW\fP)
.TP
.B \fBforward\-bigword\-end\fP
like forward\-bigword, but stops at the end of the next word (like vim\(aqs \fBE\fP)
.TP
.B \fBhistory\-pager\fP
invoke the searchable pager on history (incremental search); or if the history pager is already active, search further backwards in time.
.TP
.B \fBhistory\-delete\fP
permanently delete the current history item, either from the history pager or from an active up\-arrow history search
.TP
.B \fBhistory\-search\-backward\fP
search the history for the previous match
.TP
.B \fBhistory\-search\-forward\fP
search the history for the next match
.TP
.B \fBhistory\-prefix\-search\-backward\fP
search the history for the previous prefix match
.TP
.B \fBhistory\-prefix\-search\-forward\fP
search the history for the next prefix match
.TP
.B \fBhistory\-token\-search\-backward\fP
search the history for the previous matching argument
.TP
.B \fBhistory\-token\-search\-forward\fP
search the history for the next matching argument
.TP
.B \fBhistory\-last\-token\-search\-backward\fP
search the history for the previous matching last argument
.TP
.B \fBhistory\-last\-token\-search\-forward\fP
search the history for the next matching last argument
.TP
.B \fBforward\-jump\fP and \fBbackward\-jump\fP
read another character and jump to its next occurrence after/before the cursor
.TP
.B \fBforward\-jump\-till\fP and \fBbackward\-jump\-till\fP
jump to right \fIbefore\fP the next occurrence
.TP
.B \fBrepeat\-jump\fP and \fBrepeat\-jump\-reverse\fP
redo the last jump in the same/opposite direction
.TP
.B \fBjump\-to\-matching\-bracket\fP
jump to matching bracket if the character under the cursor is bracket;
otherwise, jump to the next occurrence of \fIany right\fP bracket after the cursor.
The following brackets are considered: \fB([{}])\fP
.TP
.B \fBjump\-till\-matching\-bracket\fP
the same as \fBjump\-to\-matching\-bracket\fP but offset cursor to the right for left bracket, and offset cursor to the left for right bracket.
The offset is applied for both the position we jump from and position we jump to.
In other words, the cursor will continuously jump inside the brackets but won\(aqt reach them by 1 character.
The input function is useful to emulate \fBib\fP vi text object.
The following brackets are considered: \fB([{}])\fP
.TP
.B \fBkill\-token\fP
move the next argument to the killring
.TP
.B \fBkill\-line\fP
move everything from the cursor to the end of the line to the killring
.TP
.B \fBkill\-path\-component\fP
move one path component to the killring.
.TP
.B \fBkill\-selection\fP
move the selected text to the killring
.TP
.B \fBkill\-whole\-line\fP
move the line (including the following newline) to the killring. If the line is the last line, its preceding newline is also removed
.TP
.B \fBkill\-inner\-line\fP
move the line (without the following newline) to the killring
.TP
.B \fBkill\-word\fP
move the next word to the killring, stopping after the end of the killed word
.TP
.B \fBkill\-word\-vi\fP
move the next word to the killring, stopping at the start of the next word (like vim\(aqs \fBdw\fP)
.TP
.B \fBkill\-bigword\fP
move the next whitespace\-delimited word to the killring, stopping after the end of the current word
.TP
.B \fBkill\-bigword\-vi\fP
move the next whitespace\-delimited word to the killring, stopping at the start of the next word (like vim\(aqs \fBdW\fP)
.TP
.B \fBkill\-inner\-word\fP
delete the word under the cursor (like vim\(aqs \fBdiw\fP)
.TP
.B \fBkill\-inner\-bigword\fP
delete the whitespace\-delimited word under the cursor (like vim\(aqs \fBdiW\fP)
.TP
.B \fBkill\-a\-word\fP
delete the word under the cursor plus surrounding whitespace (like vim\(aqs \fBdaw\fP)
.TP
.B \fBkill\-a\-bigword\fP
delete the whitespace\-delimited word under the cursor plus surrounding whitespace (like vim\(aqs \fBdaW\fP)
.TP
.B \fBnextd\-or\-forward\-word\fP
if the commandline is empty, then move forward in the directory history, otherwise move one word to the right;
or if at the end of the commandline, accept one word from the current autosuggestion.
.TP
.B \fBor\fP
only execute the next function if the previous did not succeed (note: only some functions report failure)
.TP
.B \fBpager\-toggle\-search\fP
toggles the search field if the completions pager is visible; or if used after \fBhistory\-pager\fP, search forwards in time.
.TP
.B \fBprevd\-or\-backward\-word\fP
if the commandline is empty, then move backward in the directory history, otherwise move one word to the left
.TP
.B \fBrepaint\fP
reexecutes the prompt functions and redraws the prompt (also \fBforce\-repaint\fP for backwards\-compatibility)
.TP
.B \fBrepaint\-mode\fP
reexecutes the fish_mode_prompt \%<> and redraws the prompt. This is useful for vi mode. If no \fBfish_mode_prompt\fP exists or it prints nothing, it acts like a normal repaint.
.TP
.B \fBself\-insert\fP
inserts the matching sequence into the command line
.TP
.B \fBself\-insert\-notfirst\fP
inserts the matching sequence into the command line, unless the cursor is at the beginning
.TP
.B \fBget\-key\fP
sets \fBfish_key\fP to the key that was pressed to trigger this binding. Example use:
.INDENT 7.0
.INDENT 3.5
.sp
.EX
for i in (seq 0 9)
bind $i get\-key \(aqcommandline \-i \(dq#$fish_key\(dq\(aq \(aqset \-eg fish_key\(aq
end
.EE
.UNINDENT
.UNINDENT
.TP
.B \fBsuppress\-autosuggestion\fP
remove the current autosuggestion. Returns true if there was a suggestion to remove.
.TP
.B \fBswap\-selection\-start\-stop\fP
go to the other end of the highlighted text without changing the selection
.TP
.B \fBtranspose\-chars\fP
transpose two characters to the left of the cursor
.TP
.B \fBtranspose\-words\fP
transpose two words to the left of the cursor
.TP
.B \fBtogglecase\-char\fP
toggle the capitalisation (case) of the character under the cursor
.TP
.B \fBtogglecase\-selection\fP
toggle the capitalisation (case) of the selection
.TP
.B \fBinsert\-line\-under\fP
add a new line under the current line
.TP
.B \fBinsert\-line\-over\fP
add a new line over the current line
.TP
.B \fBup\-line\fP
move up one line
.TP
.B \fBundo\fP and \fBredo\fP
revert or redo the most recent edits on the command line
.TP
.B \fBupcase\-word\fP
make the current word uppercase
.TP
.B \fByank\fP
insert the latest entry of the killring into the buffer
.TP
.B \fByank\-pop\fP
rotate to the previous entry of the killring
.UNINDENT
.SS Additional functions
.sp
The following functions are included as normal functions, but are particularly useful for input editing:
.INDENT 0.0
.TP
.B \fBup\-or\-search\fP and \fBdown\-or\-search\fP
move the cursor or search the history depending on the cursor position and current mode
.TP
.B \fBedit_command_buffer\fP
open the visual editor (controlled by the \fBVISUAL\fP or \fBEDITOR\fP environment variables) with the current command\-line contents
.TP
.B \fBfish_clipboard_copy\fP
copy the current selection to the system clipboard
.TP
.B \fBfish_clipboard_paste\fP
paste the current selection from the system clipboard before the cursor
.TP
.B \fBfish_commandline_append\fP
append the argument to the command\-line. If the command\-line already ends with the argument, this removes the suffix instead. Starts with the last command from history if the command\-line is empty.
.TP
.B \fBfish_commandline_prepend\fP
prepend the argument to the command\-line. If the command\-line already starts with the argument, this removes the prefix instead. Starts with the last command from history if the command\-line is empty.
.UNINDENT
.SS Examples
.sp
Exit the shell when \fBctrl\fP\-\fBd\fP is pressed:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind ctrl\-d \(aqexit\(aq
.EE
.UNINDENT
.UNINDENT
.sp
Perform a history search when \fBpageup\fP is pressed:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind pageup history\-search\-backward
.EE
.UNINDENT
.UNINDENT
.sp
Turn on vi key bindings \%<#\:vi-mode> and rebind \fBctrl\fP\-\fBc\fP to clear the input line:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_key_bindings fish_vi_key_bindings
bind \-M insert ctrl\-c kill\-whole\-line repaint
.EE
.UNINDENT
.UNINDENT
.sp
Launch \fBgit diff\fP and repaint the commandline afterwards when \fBctrl\fP\-\fBg\fP is pressed:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind ctrl\-g \(aqgit diff\(aq repaint
.EE
.UNINDENT
.UNINDENT
.sp
Swap \fBtab\fP and \fBshift\fP\-\fBtab\fP, making tab focus the search field.
But if the search field is already active, keep the behavior (\fBtab\fP cycles forward, \fBshift\fP\-\fBtab\fP backward).:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind tab \(aq
if commandline \-\-search\-field >/dev/null
commandline \-f complete
else
commandline \-f complete\-and\-search
end
\(aq
bind shift\-tab \(aq
if commandline \-\-search\-field >/dev/null
commandline \-f complete\-and\-search
else
commandline \-f complete
end
\(aq
.EE
.UNINDENT
.UNINDENT
.SS Terminal Limitations
.sp
Unix terminals, like the ones fish operates in, are at heart 70s technology. They have some limitations that applications running inside them can\(aqt workaround.
.sp
For instance, historically the control key modifies a character by setting the top three bits to 0. This means:
.INDENT 0.0
.IP \(bu 2
Many characters + control are indistinguishable from other keys: \fBctrl\fP\-\fBi\fP \fIis\fP \fBtab\fP, \fBctrl\fP\-\fBj\fP \fIis\fP newline (\fB\en\fP).
.IP \(bu 2
Control and shift don\(aqt work simultaneously \- \fBctrl\fP\-\fBX\fP is the same as \fBctrl\fP\-\fBx\fP\&.
.UNINDENT
.sp
Other keys don\(aqt have a direct encoding, and are sent as escape sequences. For example \fBright\fP (\fB→\fP) usually sends \fB\ee\e[C\fP\&.
.sp
Some modern terminals support newer encodings for keys, that allow distinguishing more characters and modifiers, and fish enables as many of these as it can, automatically.
.sp
When in doubt, run fish_key_reader \- explore what characters keyboard keys send \%<>\&. If that tells you that pressing \fBctrl\fP\-\fBi\fP sends tab, your terminal does not support these better encodings, and so fish is limited to what it sends.
.SS Key timeout
.sp
When you\(aqve bound a sequence of multiple characters, there is always the possibility that fish has only seen a part of it, and then it needs to disambiguate between the full sequence and part of it.
.sp
For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
bind j,k \(aqcommandline \-i foo\(aq
# or \(gabind jk\(ga
.EE
.UNINDENT
.UNINDENT
.sp
will bind the sequence \fBjk\fP to insert \(dqfoo\(dq into the commandline. When you\(aqve only pressed \(dqj\(dq, fish doesn\(aqt know if it should insert the \(dqj\(dq (because of the default self\-insert), or wait for the \(dqk\(dq.
.sp
You can enable a timeout for this, by setting the \fBfish_sequence_key_delay_ms\fP \%<#\:envvar-fish_sequence_key_delay_ms> variable to the timeout in milliseconds. If the timeout elapses, fish will no longer wait for the sequence to be completed, and do what it can with the characters it already has.
.sp
The escape key is a special case, because it can be used standalone as a real key or as part of a longer escape sequence, like function or arrow keys. Holding alt and something else also typically sends escape, for example holding alt+a will send an escape character and then an \(dqa\(dq. So the escape character has its own timeout configured with \fBfish_escape_delay_ms\fP \%<#\:envvar-fish_escape_delay_ms>\&.
.sp
See also Key sequences \%<#\:interactive-key-sequences>\&.
.SS block \- temporarily block delivery of events
.SS Synopsis
.nf
\fBblock\fP [(\fB\-\-local\fP | \fB\-\-global\fP)]
\fBblock\fP \fB\-\-erase\fP
.fi
.sp
.SS Description
.sp
\fBblock\fP delays delivery of all events triggered by \fBfish\fP or the emit \%<>, thus delaying the execution of any function registered \fB\-\-on\-event\fP, \fB\-\-on\-process\-exit\fP, \fB\-\-on\-job\-exit\fP, \fB\-\-on\-variable\fP and \fB\-\-on\-signal\fP until after the block is removed.
.sp
Event blocks should not be confused with code blocks, which are created with \fBbegin\fP, \fBif\fP, \fBwhile\fP or \fBfor\fP
.sp
Without options, \fBblock\fP sets up a block that is released automatically at the end of the current function scope.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-l\fP or \fB\-\-local\fP
Release the block automatically at the end of the current innermost code block scope.
.TP
\fB\-g\fP or \fB\-\-global\fP
Never automatically release the lock.
.TP
\fB\-e\fP or \fB\-\-erase\fP
Release global block.
.TP
\fB\-h\fP or \fB\-\-help\fP
Display help about using this command.
.UNINDENT
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Create a function that listens for events
function \-\-on\-event foo foo; echo \(aqfoo fired\(aq; end
# Block the delivery of events
block \-g
emit foo
# No output will be produced
block \-e
# \(aqfoo fired\(aq will now be printed
.EE
.UNINDENT
.UNINDENT
.SS Notes
.sp
Events are only received from the current fish process as there is no way to send events from one fish process to another.
.SS break \- stop the current inner loop
.SS Synopsis
.nf
\fILOOP_CONSTRUCT\fP
[\fICOMMANDS\fP \&...]
\fBbreak\fP
[\fICOMMANDS\fP \&...]
\fBend\fP
.fi
.sp
.SS Description
.sp
\fBbreak\fP halts a currently running loop (\fILOOP_CONSTRUCT\fP), such as a for \%<> or while \%<> loop. It is usually added inside of a conditional block such as an if \%<> block.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code searches all .c files for \(dqsmurf\(dq, and halts at the first occurrence.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in *.c
if grep smurf $i
echo Smurfs are present in $i
break
end
end
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the continue \%<> command, to skip the remainder of the current iteration of the current inner loop
.UNINDENT
.SS breakpoint \- launch debug mode
.SS Synopsis
.nf
\fBbreakpoint\fP
.fi
.sp
.SS Description
.sp
\fBbreakpoint\fP is used to halt a running script and launch an interactive debugging prompt.
.sp
For more details, see Debugging fish scripts \%<#\:debugging> in the \fBfish\fP manual.
.sp
There are no parameters for \fBbreakpoint\fP\&.
.SS builtin \- run a builtin command
.SS Synopsis
.nf
\fBbuiltin\fP [\fIOPTIONS\fP] \fIBUILTINNAME\fP
\fBbuiltin\fP \fB\-\-query\fP \fIBUILTINNAME\fP \&...
\fBbuiltin\fP \fB\-\-names\fP
.fi
.sp
.SS Description
.sp
\fBbuiltin\fP forces the shell to use a builtin command named \fIBUILTIN\fP, rather than a function or external program.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-n\fP or \fB\-\-names\fP
Lists the names of all defined builtins.
.TP
\fB\-q\fP or \fB\-\-query\fP \fIBUILTIN\fP
Tests if any of the specified builtins exist. If any exist, it returns 0, 1 otherwise.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
builtin jobs
# executes the jobs builtin, even if a function named jobs exists
.EE
.UNINDENT
.UNINDENT
.SS case \- conditionally execute a block of commands
.SS Synopsis
.nf
\fBswitch\fP \fIVALUE\fP
[\fBcase\fP [\fIGLOB\fP \&...]
[\fICOMMAND\fP \&...]]
\fBend\fP
.fi
.sp
.SS Description
.sp
\fBswitch\fP executes one of several blocks of commands, depending on whether a specified value matches one of several values. \fBcase\fP is used together with the \fBswitch\fP statement in order to determine which block should be executed.
.sp
Each \fBcase\fP command is given one or more parameters. The first \fBcase\fP command with a parameter that matches the string specified in the switch command will be evaluated. \fBcase\fP parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
.sp
Note that fish does not fall through on case statements. Only the first matching case is executed.
.sp
Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter.
.SS Example
.sp
Say $animal contains the name of an animal. Then this code would classify it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
# Note that the next case has a wildcard which is quoted
case \(aq*\(aq
echo I have no idea what a $animal is
end
.EE
.UNINDENT
.UNINDENT
.sp
If the above code was run with \fB$animal\fP set to \fBwhale\fP, the output
would be \fBmammal\fP\&.
.sp
If \fB$animal\fP was set to \(dqbanana\(dq, it would print \(dqI have no idea what a banana is\(dq.
.SS cd \- change directory
.SS Synopsis
.nf
\fBcd\fP [( \fB\-L\fP | \fB\-\-no\-dereference\fP ) | ( \fB\-P\fP | \fB\-\-dereference\fP )] [\fIDIRECTORY\fP]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBcd\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man cd\fP\&.
.sp
\fBcd\fP changes the current working directory.
.sp
The \fBPWD\fP \%<#\:envvar-PWD> environment variable is updated with the new working directory, and the previous directory
is added to the directory history \%<#\:directory-history>\&.
.sp
If \fIDIRECTORY\fP is given, it will become the new directory. If no parameter is given, the \fBHOME\fP \%<#\:envvar-HOME> environment variable will be used.
.sp
If \fIDIRECTORY\fP is a relative path, all the paths in the \fBCDPATH\fP \%<#\:envvar-CDPATH> will be tried as prefixes for it, in addition to \fBPWD\fP \%<#\:envvar-PWD>\&.
It is recommended to keep \fB\&.\fP as the first element of \fBCDPATH\fP \%<#\:envvar-CDPATH>, or \fBPWD\fP \%<#\:envvar-PWD> will be tried last.
.sp
The new directory name is partially resolved to remove redundant segments (\fB\&.\fP or \fB\&..\fP).
.sp
\fBcd\fP defaults to treating symbolic links as real directories, and not resolving them to their underlying
targets. The \fB$PWD\fP special variable \%<#\:variables-special> variable will contain the path that was
supplied. This default behaviour can be enforced with the \fB\-L\fP or \fB\-\-no\-dereference\fP option.
.sp
The \fB\-P\fP or \fB\-\-dereference\fP option resolves all symbolic links first. This was the default in fish versions before 3.0.0.
.sp
fish will also try to change directory if given a command that looks like a directory (starting with \fB\&.\fP, \fB/\fP or \fB~\fP, or ending with \fB/\fP), without explicitly requiring \fBcd\fP\&.
.sp
fish also ships a wrapper function around the builtin \fBcd\fP that understands \fBcd \-\fP as changing to the previous directory.
See also prevd \%<>\&.
This wrapper function maintains a history of the 25 most recently visited directories in the \fB$dirprev\fP and \fB$dirnext\fP global variables.
If you make those universal variables your \fBcd\fP history is shared among all fish instances.
.sp
As a special case, \fBcd .\fP is equivalent to \fBcd $PWD\fP, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated.
.sp
The \fB\-\-help\fP or \fB\-h\fP option displays help about using this command, and does not change the directory.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cd
# changes the working directory to your home directory.
cd /usr/src/fish\-shell
# changes the working directory to /usr/src/fish\-shell
cd \-P /tmp/link
# resolves /tmp/link to its target before recording the directory
.EE
.UNINDENT
.UNINDENT
.SS See Also
.sp
Navigate directories using the directory history \%<#\:directory-history> or the directory stack \%<#\:directory-stack>
.SS cdh \- change to a recently visited directory
.SS Synopsis
.nf
\fBcdh\fP [\fIDIRECTORY\fP]
.fi
.sp
.SS Description
.sp
\fBcdh\fP with no arguments presents a list of recently visited directories \%<#\:directory-history>\&.
You can then select one of the entries by letter or number.
You can also press \fBtab\fP to use the completion pager to select an item from the list.
If you give it a single argument it is equivalent to \fBcd DIRECTORY\fP\&.
.sp
Note that the \fBcd\fP command limits directory history to the 25 most recently visited directories.
The history is stored in the \fBdirprev\fP and \fBdirnext\fP variables, which this command manipulates.
If you make those universal variables, your \fBcd\fP history is shared among all fish instances.
.SS See Also
.INDENT 0.0
.IP \(bu 2
the dirh \%<> command to print the directory history
.IP \(bu 2
the prevd \%<> command to move backward
.IP \(bu 2
the nextd \%<> command to move forward
.UNINDENT
.SS command \- run a program
.SS Synopsis
.nf
\fBcommand\fP [\fIOPTIONS\fP] [\fICOMMANDNAME\fP [\fIARG\fP \&...]]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBcommand\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man command\fP\&.
.sp
\fBcommand\fP forces the shell to execute the program \fICOMMANDNAME\fP and ignore any functions or builtins with the same name.
.sp
In \fBcommand foo\fP, \fBcommand\fP is a keyword.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-all\fP
Prints all \fICOMMAND\fP found in \fBPATH\fP \%<#\:envvar-PATH>, in the order found.
.TP
\fB\-q\fP or \fB\-\-query\fP
Return 0 if any of the given commands could be found, 127 otherwise.
Don\(aqt print anything.
For compatibility, this is also \fB\-\-quiet\fP (deprecated).
.TP
\fB\-s\fP or \fB\-\-search\fP (or \fB\-v\fP)
Prints the external command that would be executed, or prints nothing if no file with the specified name could be found in \fBPATH\fP \%<#\:envvar-PATH>\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Examples
.nf
\fBcommand ls\fP executes the \fBls\fP program, even if an \fBls\fP function also exists.
\fBcommand \-s ls\fP prints the path to the \fBls\fP program.
\fBcommand \-q git; and command git log\fP runs \fBgit log\fP only if \fBgit\fP exists.
\fBcommand \-sq git\fP and \fBcommand \-q git\fP and \fBcommand \-vq git\fP return true (0) if a git command could be found and don\(aqt print anything.
.fi
.sp
.SS commandline \- set or get the current command line buffer
.SS Synopsis
.nf
\fBcommandline\fP [\fIOPTIONS\fP] [\fICMD\fP]
.fi
.sp
.SS Description
.sp
\fBcommandline\fP can be used to set or get the current contents of the command line buffer.
.sp
With no parameters, \fBcommandline\fP returns the current value of the command line.
.sp
With \fBCMD\fP specified, the command line buffer is erased and replaced with the contents of \fBCMD\fP\&.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-C\fP or \fB\-\-cursor\fP
Set or get the current cursor position, not the contents of the buffer.
If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.
If one of the options \fB\-j\fP, \fB\-p\fP or \fB\-t\fP is given, the position is relative to the respective substring instead of the entire command line buffer.
.TP
\fB\-B\fP or \fB\-\-selection\-start\fP
Get current position of the selection start in the buffer.
.TP
\fB\-E\fP or \fB\-\-selection\-end\fP
Get current position of the selection end in the buffer.
.TP
\fB\-f\fP or \fB\-\-function\fP
Causes any additional arguments to be interpreted as input functions, and puts them into the queue, so that they will be read before any additional actual key presses are.
This option cannot be combined with any other option.
See bind \%<> for a list of input functions.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
The following options change the way \fBcommandline\fP updates the command line buffer:
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-append\fP
Do not remove the current commandline, append the specified string at the end of it.
.TP
\fB\-i\fP, \fB\-\-insert\fP or \fB\-\-insert\-smart\fP
Do not remove the current commandline, insert the specified string at the current cursor position.
The \fB\-\-insert\-smart\fP option turns on a Do\-What\-I\-Mean (DWIM) mode: it strips any \fB$\fP prefix from the first command on each line.
.TP
\fB\-r\fP or \fB\-\-replace\fP
Remove the current commandline and replace it with the specified string (default)
.UNINDENT
.sp
The following options change what part of the commandline is printed or updated:
.INDENT 0.0
.TP
\fB\-b\fP or \fB\-\-current\-buffer\fP
Select the entire commandline, not including any displayed autosuggestion (default).
.TP
\fB\-j\fP or \fB\-\-current\-job\fP
Select the current job \- a \fBjob\fP here is one pipeline.
Stops at logical operators or terminators (\fB;\fP, \fB&\fP, and newlines).
.TP
\fB\-p\fP or \fB\-\-current\-process\fP
Select the current process \- a \fBprocess\fP here is one command.
Stops at logical operators, terminators, and pipes.
.TP
\fB\-s\fP or \fB\-\-current\-selection\fP
Selects the current selection
.TP
\fB\-t\fP or \fB\-\-current\-token\fP
Selects the current token
.TP
\fB\-\-search\-field\fP
Use the pager search field instead of the command line. Returns false if the search field is not shown.
.TP
\fB\-\-input=INPUT\fP
Operate on this string instead of the commandline. Useful for using options like \fB\-\-tokens\-expanded\fP\&.
.UNINDENT
.sp
The following options change the way \fBcommandline\fP prints the current commandline buffer:
.INDENT 0.0
.TP
\fB\-c\fP or \fB\-\-cut\-at\-cursor\fP
Only print selection up until the current cursor position.
If combined with \fB\-\-tokens\-expanded\fP, this will print up until the last completed token \- excluding the token the cursor is in.
This is typically what you would want for instance in completions.
To get both, use both \fBcommandline \-\-cut\-at\-cursor \-\-tokens\-expanded; commandline \-\-cut\-at\-cursor \-\-current\-token\fP,
or \fBcommandline \-cx; commandline \-ct\fP for short.
.TP
\fB\-x\fP or \fB\-\-tokens\-expanded\fP
Perform argument expansion on the selection and print one argument per line.
Command substitutions are not expanded but forwarded as\-is.
.TP
\fB\-o\fP, \fBtokenize\fP, \fB\-\-tokens\-raw\fP
Deprecated; do not use.
.UNINDENT
.sp
If \fBcommandline\fP is called during a call to complete a given string using \fBcomplete \-C STRING\fP, \fBcommandline\fP will consider the specified string to be the current contents of the command line.
.sp
The following options output metadata about the commandline state:
.INDENT 0.0
.TP
\fB\-L\fP or \fB\-\-line\fP
If no argument is given, print the line that the cursor is on, with the topmost line starting at 1.
Otherwise, set the cursor to the given line.
.TP
\fB\-\-column\fP
If no argument is given, print the 1\-based offset from the start of the line to the cursor position in Unicode code points.
Otherwise, set the cursor to the given code point offset.
.TP
\fB\-S\fP or \fB\-\-search\-mode\fP
Evaluates to true if the commandline is performing a history search.
.TP
\fB\-P\fP or \fB\-\-paging\-mode\fP
Evaluates to true if the commandline is showing pager contents, such as tab completions.
.TP
\fB\-\-paging\-full\-mode\fP
Evaluates to true if the commandline is showing pager contents, such as tab completions and all lines are shown (no \(dq more rows\(dq message).
.TP
\fB\-\-is\-valid\fP
Returns true when the commandline is syntactically valid and complete.
If it is, it would be executed when the \fBexecute\fP bind function is called.
If the commandline is incomplete, return 2, if erroneous, return 1.
.TP
\fB\-\-showing\-suggestion\fP
Evaluates to true (i.e. returns 0) when the shell is currently showing an automatic history completion/suggestion, available to be consumed via one of the \fIforward\-\fP bindings.
For example, can be used to determine if moving the cursor to the right when already at the end of the line would have no effect or if it would cause a completion to be accepted (note that \fIforward\-char\-passive\fP does this automatically).
.UNINDENT
.SS Example
.sp
\fBcommandline \-j $history[3]\fP replaces the job under the cursor with the third item from the command line history.
.sp
If the commandline contains
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ echo $flounder >&2 | less; and echo $catfish
.EE
.UNINDENT
.UNINDENT
.sp
(with the cursor on the \(dqo\(dq of \(dqflounder\(dq)
.sp
The \fBecho $flounder >&\fP is the first process, \fBless\fP the second and \fBand echo $catfish\fP the third.
.sp
\fBecho $flounder >&2 | less\fP is the first job, \fBand echo $catfish\fP the second.
.sp
\fB$flounder\fP is the current token.
.sp
The most common use for something like completions is
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l tokens (commandline \-xpc)
.EE
.UNINDENT
.UNINDENT
.sp
which gives the current \fIprocess\fP (what is being completed), tokenized into separate entries, up to but excluding the currently being completed token
.sp
If you are then also interested in the in\-progress token, add
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l current (commandline \-ct)
.EE
.UNINDENT
.UNINDENT
.sp
Note that this makes it easy to render fish\(aqs infix matching moot \- if possible it\(aqs best if the completions just print all possibilities and leave the matching to the current token up to fish\(aqs logic.
.sp
More examples:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ commandline \-t
$flounder
>_ commandline \-ct
$fl
>_ commandline \-b # or just commandline
echo $flounder >&2 | less; and echo $catfish
>_ commandline \-p
echo $flounder >&2
>_ commandline \-j
echo $flounder >&2 | less
.EE
.UNINDENT
.UNINDENT
.SS complete \- edit command\-specific tab\-completions
.SS Synopsis
.nf
\fBcomplete\fP ((\fB\-c\fP | \fB\-\-command\fP) | (\fB\-p\fP | \fB\-\-path\fP)) \fICOMMAND\fP [\fIOPTIONS\fP] [\fB\-\-color\fP \fIWHEN\fP]
\fBcomplete\fP (\fB\-C\fP | \fB\-\-do\-complete\fP) [\fB\-\-escape\fP] \fISTRING\fP
.fi
.sp
.SS Description
.sp
\fBcomplete\fP defines, removes or lists completions for a command.
.sp
For an introduction to writing your own completions, see Writing your own completions \%<> in
the fish manual.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-c\fP or \fB\-\-command\fP \fICOMMAND\fP
Specifies that \fICOMMAND\fP is the name of the command. If there is no \fB\-c\fP or \fB\-p\fP, one non\-option argument will be used as the command.
.TP
\fB\-p\fP or \fB\-\-path\fP \fICOMMAND\fP
Specifies that \fICOMMAND\fP is the absolute path of the command (optionally containing wildcards).
.TP
\fB\-e\fP or \fB\-\-erase\fP
Deletes the specified completion.
.TP
\fB\-s\fP or \fB\-\-short\-option\fP \fISHORT_OPTION\fP
Adds a short option to the completions list.
.TP
\fB\-l\fP or \fB\-\-long\-option\fP \fILONG_OPTION\fP
Adds a GNU\-style long option to the completions list.
.TP
\fB\-o\fP or \fB\-\-old\-option\fP \fIOPTION\fP
Adds an old\-style short or long option (see below for details).
.TP
\fB\-a\fP or \fB\-\-arguments\fP \fIARGUMENTS\fP
Adds the specified option arguments to the completions list.
.TP
\fB\-k\fP or \fB\-\-keep\-order\fP
Keeps the order of \fIARGUMENTS\fP instead of sorting alphabetically. Multiple \fBcomplete\fP calls with \fB\-k\fP result in arguments of the later ones displayed first.
.TP
\fB\-f\fP or \fB\-\-no\-files\fP
This completion may not be followed by a filename.
.TP
\fB\-F\fP or \fB\-\-force\-files\fP
This completion may be followed by a filename, even if another applicable \fBcomplete\fP specified \fB\-\-no\-files\fP\&.
.TP
\fB\-r\fP or \fB\-\-require\-parameter\fP
This completion must have an option argument, i.e. may not be followed by another option.
This means that the next argument is the argument to the option.
If this is \fInot\fP given, the option argument must be attached like \fB\-xFoo\fP or \fB\-\-color=auto\fP\&.
.TP
\fB\-x\fP or \fB\-\-exclusive\fP
Short for \fB\-r\fP and \fB\-f\fP\&.
.TP
\fB\-d\fP or \fB\-\-description\fP \fIDESCRIPTION\fP
Add a description for this completion, to be shown in the completion pager.
.TP
\fB\-w\fP or \fB\-\-wraps\fP \fIWRAPPED_COMMAND\fP
Causes the specified command to inherit completions from \fIWRAPPED_COMMAND\fP\&.
This is used for \(dqthis command completes like that other command\(dq kinds of relationships.
See below for details.
.TP
\fB\-n\fP or \fB\-\-condition\fP \fICONDITION\fP
This completion should only be used if the \fICONDITION\fP (a shell command) returns 0. This makes it possible to specify completions that should only be used in some cases. If multiple conditions are specified, fish will try them in the order they are specified until one fails or all succeeded.
.TP
\fB\-C\fP or \fB\-\-do\-complete\fP \fISTRING\fP
Makes \fBcomplete\fP try to find all possible completions for the specified string. If there is no \fISTRING\fP, the current commandline is used instead.
.TP
\fB\-\-escape\fP
When used with \fB\-C\fP, escape special characters in completions.
.TP
\fB\-\-color\fP \fIWHEN\fP
Controls when to use syntax highlighting colors when printing completions.
\fIWHEN\fP can be \fBauto\fP (the default, colorize if the output is a terminal \%<>), \fBalways\fP, or \fBnever\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
Command\-specific tab\-completions in \fBfish\fP are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as \fB\-h\fP, \fB\-help\fP or \fB\-\-help\fP\&. Arguments are parameters that do not begin with a hyphen. fish recognizes three styles of options, the same styles as the GNU getopt library. These styles are:
.INDENT 0.0
.IP \(bu 2
Short options, like \fB\-a\fP\&. Short options are a single character long, are preceded by a single hyphen and can be grouped together (like \fB\-la\fP, which is equivalent to \fB\-l \-a\fP). Option arguments may be specified by appending the option with the value (\fB\-w32\fP), or, if \fB\-\-require\-parameter\fP is given, in the following parameter (\fB\-w 32\fP).
.IP \(bu 2
Old\-style options, long like \fB\-Wall\fP or \fB\-name\fP or even short like \fB\-a\fP\&. Old\-style options can be more than one character long, are preceded by a single hyphen and may not be grouped together. Option arguments are specified by default following a space (\fB\-foo null\fP) or after \fB=\fP (\fB\-foo=null\fP).
.IP \(bu 2
GNU\-style long options, like \fB\-\-colors\fP\&. GNU\-style long options can be more than one character long, are preceded by two hyphens, and can\(aqt be grouped together. Option arguments may be specified after a \fB=\fP (\fB\-\-quoting\-style=shell\fP), or, if \fB\-\-require\-parameter\fP is given, in the following parameter (\fB\-\-quoting\-style shell\fP).
.UNINDENT
.sp
Multiple commands and paths can be given in one call to define the same completions for multiple commands.
.sp
Multiple command switches and wrapped commands can also be given to define multiple completions in one call.
.sp
Invoking \fBcomplete\fP multiple times for the same command adds the new definitions on top of any existing completions defined for the command.
.sp
When \fB\-a\fP or \fB\-\-arguments\fP is specified in conjunction with long, short, or old\-style options, the specified arguments are only completed as arguments for any of the specified options. If \fB\-a\fP or \fB\-\-arguments\fP is specified without any long, short, or old\-style options, the specified arguments are used when completing non\-option arguments to the command (except when completing an option argument that was specified with \fB\-r\fP or \fB\-\-require\-parameter\fP).
.sp
Command substitutions found in \fBARGUMENTS\fP should return a newline\-separated list of arguments, and each argument may optionally have a tab character followed by the argument description. Description given this way override a description given with \fB\-d\fP or \fB\-\-description\fP\&.
.sp
Descriptions given with \fB\-\-description\fP are also used to group options given with \fB\-s\fP, \fB\-o\fP or \fB\-l\fP\&. Options with the same (non\-empty) description will be listed as one candidate, and one of them will be picked. If the description is empty or no description was given this is skipped.
.sp
The \fB\-w\fP or \fB\-\-wraps\fP options causes the specified command to inherit completions from another command, \(dqwrapping\(dq the other command. The wrapping command can also have additional completions. A command can wrap multiple commands, and wrapping is transitive: if A wraps B, and B wraps C, then A automatically inherits all of C\(aqs completions. Wrapping can be removed using the \fB\-e\fP or \fB\-\-erase\fP options. Wrapping only works for completions specified with \fB\-c\fP or \fB\-\-command\fP and are ignored when specifying completions with \fB\-p\fP or \fB\-\-path\fP\&.
.sp
When erasing completions, it is possible to either erase all completions for a specific command by specifying \fBcomplete \-c COMMAND \-e\fP, or by specifying a specific completion option to delete.
.sp
When \fBcomplete\fP is called without anything that would define or erase completions (options, arguments, wrapping, ...), it shows matching completions instead. So \fBcomplete\fP without any arguments shows all loaded completions, \fBcomplete \-c foo\fP shows all loaded completions for \fBfoo\fP\&. Since completions are autoloaded \%<#\:syntax-function-autoloading>, you will have to trigger them first.
.SS Cygwin / MSYS2 / Windows
.sp
On Windows, binary executables have a \fB\&.exe\fP extension, but this extension is not required when calling an application (and if the name is not ambiguous, i.e. there isn\(aqt also a script called \fBmyprog\fP in the same directory as \fBmyprog.exe\fP).
.sp
To unify completions between Windows and other OSes, on Cygwin/MSYS2/Windows, \fICOMMAND\fP does not require the \fB\&.exe\fP extension.
Completions for \fBmyprog\fP will also be used for \fBmyprog.exe\fP if there are no ambiguities, i.e. if there are no completions for \fBmyprog.exe\fP specifically.
However, completions for \fBmyprog.exe\fP will only be used when also using the \fB\&.exe\fP extension on the command line.
.sp
In other words:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog.exe ... #1
.EE
.UNINDENT
.UNINDENT
.sp
will only work for \fBmyprog.exe\fP
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog ... #2
.EE
.UNINDENT
.UNINDENT
.sp
can work for both \fBmyprog\fP and \fBmyprog.exe\fP\&. But if both completions exist, #2 will only be used for \fBmyprog\fP while \fBmyprog.exe\fP will use #1.
.SS Examples
.sp
The short\-style option \fB\-o\fP for the \fBgcc\fP command needs a file argument:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c gcc \-s o \-r
.EE
.UNINDENT
.UNINDENT
.sp
The short\-style option \fB\-d\fP for the \fBgrep\fP command requires one of \fBread\fP, \fBskip\fP or \fBrecurse\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c grep \-s d \-x \-a \(dqread skip recurse\(dq
.EE
.UNINDENT
.UNINDENT
.sp
The \fBsu\fP command takes any username as an argument. Usernames are given as the first colon\-separated field in the file /etc/passwd. This can be specified as:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-x \-c su \-d \(dqUsername\(dq \-a \(dq(cat /etc/passwd | cut \-d : \-f 1)\(dq
.EE
.UNINDENT
.UNINDENT
.sp
The \fBrpm\fP command has several different modes. If the \fB\-e\fP or \fB\-\-erase\fP flag has been specified, \fBrpm\fP should delete one or more packages, in which case several switches related to deleting packages are valid, like the \fBnodeps\fP switch.
.sp
This can be written as:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c rpm \-n \(dq__fish_contains_opt \-s e erase\(dq \-l nodeps \-d \(dqDon\(aqt check dependencies\(dq
.EE
.UNINDENT
.UNINDENT
.sp
where \fB__fish_contains_opt\fP is a function that checks the command line buffer for the presence of a specified set of options.
.sp
To implement an alias, use the \fB\-w\fP or \fB\-\-wraps\fP option:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c hub \-w git
.EE
.UNINDENT
.UNINDENT
.sp
Now hub inherits all of the completions from git. Note this can also be specified in a function declaration (\fBfunction thing \-w otherthing\fP).
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c git
.EE
.UNINDENT
.UNINDENT
.sp
Shows all completions for \fBgit\fP\&.
.sp
Any command \fBfoo\fP that doesn\(aqt support grouping multiple short options in one string (not supporting \fB\-xf\fP as short for \fB\-x \-f\fP) or a short option and its value in one string (not supporting \fB\-d9\fP instead of \fB\-d 9\fP) should be specified as a single\-character old\-style option instead of as a short\-style option; for example, \fBcomplete \-c foo \-o s; complete \-c foo \-o v\fP would never suggest \fBfoo \-ov\fP but rather \fBfoo \-o \-v\fP\&.
.SS contains \- test if a word is present in a list
.SS Synopsis
.nf
\fBcontains\fP [\fIOPTIONS\fP] [\fB\-\-\fP] \fIKEY\fP [\fIVALUES\fP \&...]
.fi
.sp
.SS Description
.sp
\fBcontains\fP tests whether the set \fIVALUES\fP contains the string \fIKEY\fP\&.
If so, \fBcontains\fP exits with code 0; if not, it exits with code 1.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-i\fP or \fB\-\-index\fP
Print the index (number of the element in the set) of the first matching element.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
Options must be passed before \fIKEY\fP\&.
All arguments after \fIKEY\fP will be considered a value, regardless if they start with a \fB\-\fP or not, including \fB\-\-\fP\&.
If \fIKEY\fP itself starts with a \fB\-\fP, use a \fB\-\-\fP argument to separate it from the options.
.sp
See the examples below.
.SS Example
.sp
If \fIanimals\fP is a list of animals, the following will test if \fIanimals\fP contains \(dqcat\(dq:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if contains cat $animals
echo Your animal list is evil!
end
.EE
.UNINDENT
.UNINDENT
.sp
This code will add some directories to \fBPATH\fP \%<#\:envvar-PATH> if they aren\(aqt yet included:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in ~/bin /usr/local/bin
if not contains $i $PATH
set PATH $PATH $i
end
end
.EE
.UNINDENT
.UNINDENT
.sp
While this will check if function \fBhasargs\fP is being ran with the \fB\-q\fP option:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function hasargs
if contains \-\- \-q $argv
echo \(aq$argv contains a \-q option\(aq
end
end
.EE
.UNINDENT
.UNINDENT
.sp
The \fB\-\-\fP here stops \fBcontains\fP from treating \fB\-q\fP to an option to itself.
Instead it treats it as a normal string to check.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
contains \-i foo \-q \-\- foo
.EE
.UNINDENT
.UNINDENT
.sp
This returns 3, since all arguments after the key are considered a value.
.SS continue \- skip the remainder of the current iteration of the current inner loop
.SS Synopsis
.nf
\fILOOP_CONSTRUCT\fP\fB;\fP [\fICOMMANDS\fP \&...\fB;\fP] \fBcontinue\fP\fB;\fP [\fICOMMANDS\fP \&...\fB;\fP] \fBend\fP
.fi
.sp
.SS Description
.sp
\fBcontinue\fP skips the remainder of the current iteration of the current inner loop, such as a for \%<> loop or a while \%<> loop. It is usually added inside of a conditional block such as an if \%<> statement or a switch \%<> statement.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code removes all tmp files that do not contain the word smurf.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in *.tmp
if grep smurf $i
continue
end
# This \(dqrm\(dq is skipped over if \(dqcontinue\(dq is executed.
rm $i
# As is this \(dqecho\(dq
echo $i
end
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the break \%<> command, to stop the current inner loop
.UNINDENT
.SS count \- count the number of elements of a list
.SS Synopsis
.nf
\fBcount\fP \fISTRING1\fP \fISTRING2\fP \&...
\fICOMMAND\fP | \fBcount\fP
\fBcount\fP [\&...] \fB<\fP \fIFILE\fP
.fi
.sp
.SS Description
.sp
\fBcount\fP prints the number of arguments that were passed to it, plus the number of newlines passed to it via stdin. This is usually used to find out how many elements an environment variable list contains, or how many lines there are in a text file.
.sp
\fBcount\fP does not accept any options, not even \fB\-h\fP or \fB\-\-help\fP\&.
.sp
\fBcount\fP exits with a non\-zero exit status if no arguments were passed to it, and with zero if at least one argument was passed.
.sp
Note that, like \fBwc \-l\fP, reading from stdin counts newlines, so \fBecho \-n foo | count\fP will print 0.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
count $PATH
# Returns the number of directories in the users PATH variable.
count *.txt
# Returns the number of files in the current working directory
# ending with the suffix \(aq.txt\(aq.
git ls\-files \-\-others \-\-exclude\-standard | count
# Returns the number of untracked files in a git repository
printf \(aq%s\en\(aq foo bar | count baz
# Returns 3 (2 lines from stdin plus 1 argument)
count < /etc/hosts
# Counts the number of entries in the hosts file
.EE
.UNINDENT
.UNINDENT
.SS dirh \- print directory history
.SS Synopsis
.nf
\fBdirh\fP
.fi
.sp
.SS Description
.sp
\fBdirh\fP prints the current directory history \%<#\:directory-history>\&. The current position in the history is highlighted using the color defined in the \fBfish_color_history_current\fP environment variable.
.sp
\fBdirh\fP does not accept any parameters.
.sp
Note that the cd \%<> command limits directory history to the 25 most recently visited directories. The history is stored in the \fB$dirprev\fP and \fB$dirnext\fP variables.
.SS See Also
.INDENT 0.0
.IP \(bu 2
the cdh \%<> command to display a prompt to quickly navigate the history
.IP \(bu 2
the prevd \%<> command to move backward
.IP \(bu 2
the nextd \%<> command to move forward
.UNINDENT
.SS dirs \- print directory stack
.SS Synopsis
.nf
\fBdirs\fP [\fB\-c\fP]
.fi
.sp
.SS Description
.sp
\fBdirs\fP prints the current directory stack \%<#\:directory-stack>, as created by pushd \%<> and modified by popd \%<>\&.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-c\fP:
Clear the directory stack instead of printing it.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
\fBdirs\fP does not accept any arguments.
.SS See Also
.INDENT 0.0
.IP \(bu 2
the cdh \%<> command, which provides a more intuitive way to navigate to recently visited directories.
.UNINDENT
.SS disown \- remove a process from the list of jobs
.SS Synopsis
.nf
\fBdisown\fP [\fIPID\fP \&...]
.fi
.sp
.SS Description
.sp
\fBdisown\fP removes the specified job \%<#\:syntax-job-control> from the list of jobs. The job itself continues to exist, but fish does not keep track of it any longer.
This will make fish lose all knowledge of the job, so functions defined with \fB\-\-on\-process\-exit\fP or \fB\-\-on\-job\-exit\fP will no longer fire.
.sp
Jobs in the list of jobs are sent a hang\-up signal when fish terminates, which usually causes the job to terminate; \fBdisown\fP allows these processes to continue regardless.
.sp
If no process is specified, the most recently\-used job is removed (like bg \%<> and fg \%<>). If one or more PIDs are specified, jobs with the specified process IDs are removed from the job list. Invalid jobs are ignored and a warning is printed.
.sp
If a job is stopped, it is sent a signal to continue running, and a warning is printed. It is not possible to use the bg \%<> builtin to continue a job once it has been disowned.
.sp
\fBdisown\fP returns 0 if all specified jobs were disowned successfully, and 1 if any problems were encountered.
.sp
The \fB\-\-help\fP or \fB\-h\fP option displays help about using this command.
.SS Example
.sp
\fBfirefox &; disown\fP will start the Firefox web browser in the background and remove it from the job list, meaning it will not be closed when the fish process is closed.
.sp
\fBdisown (jobs \-p)\fP removes all jobs \%<> from the job list without terminating them.
.SS echo \- display a line of text
.SS Synopsis
.nf
\fBecho\fP [\fIOPTIONS\fP] [\fISTRING\fP]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBecho\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man echo\fP\&.
.sp
\fBecho\fP displays \fISTRING\fP of text.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-n\fP
Do not output a newline.
.TP
\fB\-s\fP
Do not separate arguments with spaces.
.TP
\fB\-E\fP
Disable interpretation of backslash escapes (default).
.TP
\fB\-e\fP
Enable interpretation of backslash escapes.
.UNINDENT
.sp
Unlike other shells, this echo accepts \fB\-\-\fP to signal the end of the options.
.SS Escape Sequences
.sp
If \fB\-e\fP is used, the following sequences are recognized:
.INDENT 0.0
.IP \(bu 2
\fB\e\fP backslash
.IP \(bu 2
\fB\ea\fP alert (BEL)
.IP \(bu 2
\fB\eb\fP backspace
.IP \(bu 2
\fB\ec\fP produce no further output
.IP \(bu 2
\fB\ee\fP escape
.IP \(bu 2
\fB\ef\fP form feed
.IP \(bu 2
\fB\en\fP new line
.IP \(bu 2
\fB\er\fP carriage return
.IP \(bu 2
\fB\et\fP horizontal tab
.IP \(bu 2
\fB\ev\fP vertical tab
.IP \(bu 2
\fB\e0NNN\fP byte with octal value NNN (1 to 3 digits)
.IP \(bu 2
\fB\exHH\fP byte with hexadecimal value HH (1 to 2 digits)
.UNINDENT
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo \(aqHello World\(aq
Hello World
> echo \-e \(aqTop\enBottom\(aq
Top
Bottom
> echo \-\- \-n
\-n
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the printf \%<> command, for more control over output formatting
.UNINDENT
.SS else \- execute command if a condition is not met
.SS Synopsis
.nf
\fBif\fP \fICONDITION\fP\fB;\fP \fICOMMANDS_TRUE\fP \&...\fB;\fP [\fBelse\fP\fB;\fP \fICOMMANDS_FALSE\fP \&...\fB;\fP] \fBend\fP
.fi
.sp
.SS Description
.sp
if \%<> will execute the command \fICONDITION*\fP\&.
If the condition\(aqs exit status is 0, the commands \fICOMMANDS_TRUE\fP will execute.
If it is not 0 and \fBelse\fP is given, \fICOMMANDS_FALSE\fP will be executed.
.SS Example
.sp
The following code tests whether a file \fIfoo.txt\fP exists as a regular file.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-f foo.txt
echo foo.txt exists
else
echo foo.txt does not exist
end
.EE
.UNINDENT
.UNINDENT
.SS emit \- emit a generic event
.SS Synopsis
.nf
\fBemit\fP \fIEVENT_NAME\fP [\fIARGUMENTS\fP \&...]
.fi
.sp
.SS Description
.sp
\fBemit\fP emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers \%<#\:event>\&. The arguments are passed to the event handlers as function arguments.
.sp
The \fB\-\-help\fP or \fB\-h\fP option displays help about using this command.
.SS Example
.sp
The following code first defines an event handler for the generic event named \(aqtest_event\(aq, and then emits an event of that type.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function event_test \-\-on\-event test_event
echo event test: $argv
end
emit test_event something
.EE
.UNINDENT
.UNINDENT
.SS Notes
.sp
Note that events are only sent to the current fish process as there is no way to send events from one fish process to another.
.SS end \- end a block of commands
.SS Synopsis
.nf
\fBbegin\fP
[\fICOMMANDS\fP \&...]
\fBend\fP
.fi
.sp
.nf
\fBfunction\fP \fINAME\fP [\fIOPTIONS\fP]\fB;\fP \fICOMMANDS\fP \&...\fB;\fP \fBend\fP
\fBif\fP \fICONDITION\fP\fB;\fP \fICOMMANDS_TRUE\fP \&...\fB;\fP [\fBelse\fP\fB;\fP \fICOMMANDS_FALSE\fP \&...\fB;\fP] \fBend\fP
\fBswitch\fP \fIVALUE\fP\fB;\fP [\fBcase\fP [\fIWILDCARD\fP \&...]\fB;\fP [\fICOMMANDS\fP \&...]\fB;\fP \&...] \fBend\fP
\fBwhile\fP \fICONDITION\fP\fB;\fP \fICOMMANDS\fP \&...\fB;\fP \fBend\fP
\fBfor\fP \fIVARNAME\fP \fBin\fP [\fIVALUES\fP \&...]\fB;\fP \fICOMMANDS\fP \&...\fB;\fP \fBend\fP
.fi
.sp
.SS Description
.sp
The \fBend\fP keyword ends a block of commands started by one of the following commands:
.INDENT 0.0
.IP \(bu 2
begin \%<> to start a block of commands
.IP \(bu 2
function \%<> to define a function
.IP \(bu 2
if \%<>, switch \%<> to conditionally execute commands
.IP \(bu 2
while \%<>, for \%<> to perform commands multiple times
.UNINDENT
.sp
The \fBend\fP keyword does not change the current exit status.
Instead, the status after it will be the status returned by the most recent command.
.SS eval \- evaluate the specified commands
.SS Synopsis
.nf
\fBeval\fP [\fICOMMANDS\fP \&...]
.fi
.sp
.SS Description
.sp
\fBeval\fP evaluates the specified parameters as a command.
If more than one parameter is specified, all parameters will be joined using a space character as a separator.
.sp
If the command does not need access to stdin, consider using source \%<> instead.
.sp
If no piping or other compound shell constructs are required, variable\-expansion\-as\-command, as in \fBset cmd ls \-la; $cmd\fP, is also an option.
.SS Example
.sp
The following code will call the ls command and truncate each filename to the first 12 characters.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set cmd ls \e| cut \-c 1\-12
eval $cmd
.EE
.UNINDENT
.UNINDENT
.SS exec \- execute command in current process
.SS Synopsis
.nf
\fBexec\fP \fICOMMAND\fP
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBexec\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man exec\fP\&.
.sp
\fBexec\fP replaces the currently running shell with a new command. On successful completion, \fBexec\fP never returns. \fBexec\fP cannot be used inside a pipeline.
.sp
The \fB\-\-help\fP or \fB\-h\fP option displays help about using this command.
.SS Example
.sp
\fBexec emacs\fP starts up the emacs text editor, and exits \fBfish\fP\&. When emacs exits, the session will terminate.
.SS exit \- exit the shell
.SS Synopsis
.nf
\fBexit\fP [\fICODE\fP]
.fi
.sp
.SS Description
.sp
\fBexit\fP is a special builtin that causes the shell to exit. Either 255 or the \fICODE\fP supplied is used, whichever is lesser.
Otherwise, the exit status will be that of the last command executed.
.sp
If exit is called while sourcing a file (using the source \%<> builtin) the rest of the file will be skipped, but the shell itself will not exit.
.sp
The \fB\-\-help\fP or \fB\-h\fP option displays help about using this command.
.SS export \- compatibility function for exporting variables
.SS Synopsis
.nf
\fBexport\fP
\fBexport\fP \fINAME\fP\fB=\fP\fIVALUE\fP
.fi
.sp
.SS Description
.sp
\fBexport\fP is a function included for compatibility with POSIX shells. In general, the set \%<>
builtin should be used instead.
.sp
When called without arguments, \fBexport\fP prints a list of currently\-exported variables, like \fBset
\-x\fP\&.
.sp
When called with a \fBNAME=VALUE\fP pair, the variable \fBNAME\fP is set to \fBVALUE\fP in the global
scope, and exported as an environment variable to other commands.
.sp
There are no options available.
.SS Example
.sp
The following commands have an identical effect.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-gx PAGER bat
export PAGER=bat
.EE
.UNINDENT
.UNINDENT
.sp
Note: If you want to add to e.g. \fB$PATH\fP, you need to be careful to combine the list \%<#\:cartesian-product>\&. Quote it, like so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
export PATH=\(dq$PATH:/opt/bin\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Or just use \fBset\fP, which avoids this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-gx PATH $PATH /opt/bin
.EE
.UNINDENT
.UNINDENT
.SS See more
.INDENT 0.0
.IP 1. 3
The set \%<> command.
.UNINDENT
.SS false \- return an unsuccessful result
.SS Synopsis
.nf
\fBfalse\fP
.fi
.sp
.SS Description
.sp
\fBfalse\fP sets the exit status to 1.
.SS See Also
.INDENT 0.0
.IP \(bu 2
true \%<> command
.IP \(bu 2
$status \%<#\:variables-status> variable
.UNINDENT
.SS fg \- bring job to foreground
.SS Synopsis
.nf
\fBfg\fP [\fIPID\fP]
.fi
.sp
.SS Description
.sp
The \fBfg\fP builtin brings the specified job \%<#\:syntax-job-control> to the foreground, resuming it if it is stopped.
While a foreground job is executed, fish is suspended.
If no job is specified, the last job to be used is put in the foreground.
If \fBPID\fP is specified, the job containing a process with the specified process ID is put in the foreground.
.sp
For compatibility with other shells, job expansion syntax is supported for \fBfg\fP\&. A \fIPID\fP of the format \fB%1\fP will foreground job 1.
Job numbers can be seen in the output of jobs \%<>\&.
.sp
The \fB\-\-help\fP or \fB\-h\fP option displays help about using this command.
.SS Example
.sp
\fBfg\fP will put the last job in the foreground.
.sp
\fBfg %3\fP will put job 3 into the foreground.
.SS fish \- the friendly interactive shell
.SS Synopsis
.nf
\fBfish\fP [\fIOPTIONS\fP] [\fIFILE\fP [\fIARG\fP \&...]]
\fBfish\fP [\fIOPTIONS\fP] [\fB\-c\fP \fICOMMAND\fP [\fIARG\fP \&...]]
.fi
.sp
.SS Description
.sp
\fBfish\fP is a command\-line shell written mainly with interactive use in mind.
This page briefly describes the options for invoking \fBfish\fP\&.
The full manual \%<#\:intro> is available in HTML by using the \fBhelp\fP command from inside fish, and in the \fIfish\-doc(1)\fP man page.
The tutorial \%<> is available as HTML via \fBhelp tutorial\fP or in \fIman fish\-tutorial\fP\&.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-c\fP or \fB\-\-command=COMMAND\fP
Evaluate the specified commands instead of reading from the commandline.
Any additional positional arguments are used as \fB$argv\fP\&.
.TP
\fB\-C\fP or \fB\-\-init\-command=COMMANDS\fP
Evaluate specified commands after reading the configuration but before executing command specified by \fB\-c\fP or reading interactive input.
.TP
\fB\-d\fP or \fB\-\-debug=DEBUG_CATEGORIES\fP
Enables debug output and specify a pattern for matching debug categories.
See Debugging below for details.
.TP
\fB\-o\fP or \fB\-\-debug\-output=DEBUG_FILE\fP
Specifies a file path to receive the debug output, including categories and \fBfish_trace\fP \%<#\:envvar-fish_trace>\&.
The default is standard error.
.TP
\fB\-i\fP or \fB\-\-interactive\fP
The shell is interactive.
.TP
\fB\-l\fP or \fB\-\-login\fP
Act as if invoked as a login shell.
.TP
\fB\-N\fP or \fB\-\-no\-config\fP
Do not read configuration files.
.TP
\fB\-n\fP or \fB\-\-no\-execute\fP
Do not execute any commands, only perform syntax checking.
.TP
\fB\-p\fP or \fB\-\-profile=PROFILE_FILE\fP
when \fBfish\fP exits, output timing information on all executed commands to the specified file.
This excludes time spent starting up and reading the configuration.
.TP
\fB\-\-profile\-startup=PROFILE_FILE\fP
Will write timing for \fBfish\fP startup to specified file.
.TP
\fB\-P\fP or \fB\-\-private\fP
Enables private mode \%<#\:private-mode>: \fBfish\fP will not access old or store new history.
.TP
\fB\-\-print\-rusage\-self\fP
When \fBfish\fP exits, output stats from getrusage.
.TP
\fB\-\-print\-debug\-categories\fP
Print all debug categories, and then exit.
.TP
\fB\-v\fP or \fB\-\-version\fP
Print version and exit.
.TP
\fB\-f\fP or \fB\-\-features=FEATURES\fP
Enables one or more comma\-separated feature flags \%<#\:featureflags>\&.
.UNINDENT
.sp
The \fBfish\fP exit status is generally the exit status of the last foreground command \%<#\:variables-status>\&.
.SS Debugging
.sp
While fish provides extensive support for debugging fish scripts \%<#\:debugging>, it is also possible to debug and instrument its internals.
Debugging can be enabled by passing the \fB\-\-debug\fP option.
For example, the following command turns on debugging for background IO thread events, in addition to the default categories, i.e. \fIdebug\fP, \fIerror\fP, \fIwarning\fP, and \fIwarning\-path\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish \-\-debug=iothread
.EE
.UNINDENT
.UNINDENT
.sp
Available categories are listed by \fBfish \-\-print\-debug\-categories\fP\&. The \fB\-\-debug\fP option accepts a comma\-separated list of categories, and supports glob syntax.
The following command turns on debugging for \fIcomplete\fP, \fIhistory\fP, \fIhistory\-file\fP, and \fIprofile\-history\fP, as well as the default categories:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish \-\-debug=\(aqcomplete,*history*\(aq
.EE
.UNINDENT
.UNINDENT
.sp
Debug messages output to stderr by default. Note that if \fBfish_trace\fP \%<#\:envvar-fish_trace> is set, execution tracing also outputs to stderr by default. You can output to a file using the \fB\-\-debug\-output\fP option:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish \-\-debug=\(aqcomplete,*history*\(aq \-\-debug\-output=/tmp/fish.log \-\-init\-command=\(aqset fish_trace on\(aq
.EE
.UNINDENT
.UNINDENT
.sp
These options can also be changed via the \fBFISH_DEBUG\fP \%<#\:envvar-FISH_DEBUG> and \fBFISH_DEBUG_OUTPUT\fP \%<#\:envvar-FISH_DEBUG_OUTPUT> variables.
The categories enabled via \fB\-\-debug\fP are \fIadded\fP to the ones enabled by $FISH_DEBUG, so they can be disabled by prefixing them with \fB\-\fP (\fBreader\-*,\-ast*\fP enables reader debugging and disables ast debugging).
.sp
The file given in \fB\-\-debug\-output\fP takes precedence over the file in \fBFISH_DEBUG_OUTPUT\fP \%<#\:envvar-FISH_DEBUG_OUTPUT>\&.
.SS Examples
.sp
To just start fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish
.EE
.UNINDENT
.UNINDENT
.sp
To run a file with fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish /path/to/script.fish
.EE
.UNINDENT
.UNINDENT
.sp
To run some commands with fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish \-c \(aqecho Hi there!\(aq
.EE
.UNINDENT
.UNINDENT
.sp
You can also pass arguments to those commands:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish \-c \(aqprintf %s\en $argv\(aq \(dqfirst line\(dq \(dqsecond line\(dq
first line
second line
.EE
.UNINDENT
.UNINDENT
.sp
To run a script, except read this other file first:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish \-\-init\-cmd \(dqsource otherfile\(dq script.fish
.EE
.UNINDENT
.UNINDENT
.sp
To profile \%<#\:profiling> fish\(aqs startup and find what takes the most time in your configuration:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish \-\-profile\-startup /tmp/start.prof \-ic exit
sort \-nk2 /tmp/start.prof
.EE
.UNINDENT
.UNINDENT
.SS fish_add_path \- add to the path
.SS Synopsis
.nf
\fBfish_add_path\fP \fBpath\fP \&...
\fBfish_add_path\fP [(\fB\-g\fP | \fB\-\-global\fP) | (\fB\-U\fP | \fB\-\-universal\fP) | (\fB\-P\fP | \fB\-\-path\fP)] [(\fB\-m\fP | \fB\-\-move\fP)] [(\fB\-a\fP | \fB\-\-append\fP) | (\fB\-p\fP | \fB\-\-prepend\fP)] [(\fB\-v\fP | \fB\-\-verbose\fP) | (\fB\-n\fP | \fB\-\-dry\-run\fP)] \fIPATHS\fP \&...
.fi
.sp
.SS Description
.sp
\fBfish_add_path\fP is a simple way to add more directories to fish\(aqs \fBPATH\fP \%<#\:envvar-PATH>\&. It does this by adding the directories either to \fBfish_user_paths\fP \%<#\:envvar-fish_user_paths> or directly to \fBPATH\fP \%<#\:envvar-PATH> (if the \fB\-\-path\fP switch is given).
.sp
It is (by default) safe to use \fBfish_add_path\fP in config.fish, or it can be used once, interactively, and the paths will stay in future because of universal variables \%<#\:variables-universal>\&. This is a \(dqdo what I mean\(dq style command \- it tries to do the right thing by default, and follow your lead on what you have already set up (e.g. by using a global \fBfish_user_paths\fP \%<#\:envvar-fish_user_paths> if you have that already). If you need more control, consider modifying the variable yourself.
.sp
Directories are normalized with realpath \%<>\&. Trailing slashes are ignored and relative paths are made absolute (but symlinks are not resolved). If a directory is already included, it is not added again and stays in the same place unless the \fB\-\-move\fP switch is given.
.sp
Directories are added in the order they are given, and they are prepended to the path unless \fB\-\-append\fP is given. If $fish_user_paths is used, that means they are last in $fish_user_paths, which is itself prepended to \fBPATH\fP \%<#\:envvar-PATH>, so they still stay ahead of the system paths. If the \fB\-\-path\fP option is used, the paths are appended/prepended to \fBPATH\fP \%<#\:envvar-PATH> directly, so this doesn\(aqt happen.
.sp
With \fB\-\-path\fP, because \fBPATH\fP \%<#\:envvar-PATH> must be a global variable instead of a universal one, the changes won\(aqt persist, so those calls need to be stored in config.fish \%<#\:configuration>\&. This also applies to \fBfish_user_paths\fP \%<#\:envvar-fish_user_paths> if you make it global (for instance by passing \fB\-\-global\fP).
.sp
If no directory is new, the variable (\fBfish_user_paths\fP \%<#\:envvar-fish_user_paths> or \fBPATH\fP \%<#\:envvar-PATH>) is not set again or otherwise modified, so variable handlers are not triggered.
.sp
If an argument is not an existing directory, \fBfish_add_path\fP ignores it.
.SS Options
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-append\fP
Add directories to the \fIend\fP of the variable.
.TP
\fB\-p\fP or \fB\-\-prepend\fP
Add directories to the \fIfront\fP of the variable (this is the default).
.TP
\fB\-g\fP or \fB\-\-global\fP
Use a global \fBfish_user_paths\fP \%<#\:envvar-fish_user_paths>\&.
.TP
\fB\-U\fP or \fB\-\-universal\fP
Use a universal \fBfish_user_paths\fP \%<#\:envvar-fish_user_paths> \- this is the default if it doesn\(aqt already exist.
.TP
\fB\-P\fP or \fB\-\-path\fP
Manipulate \fBPATH\fP \%<#\:envvar-PATH> directly.
.TP
\fB\-m\fP or \fB\-\-move\fP
Move already\-included directories to the place they would be added \- by default they would be left in place and not added again.
.TP
\fB\-v\fP or \fB\-\-verbose\fP
Print the set \%<> command used, and some more warnings, like when a path is skipped because it doesn\(aqt exist or is not a directory.
Verbose mode is automatically enabled when fish_add_path is used interactively and the output goes to the terminal.
.TP
\fB\-n\fP or \fB\-\-dry\-run\fP
Print the \fBset\fP command that would be used without executing it.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
If \fB\-\-move\fP is used, it may of course lead to the path swapping order, so you should be careful doing that in config.fish.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# I just installed mycoolthing and need to add it to the path to use it.
# It is at /opt/mycoolthing/bin/mycoolthing,
# so let\(aqs add the directory: /opt/mycoolthing/bin.
> fish_add_path /opt/mycoolthing/bin
# I want my ~/.local/bin to be checked first,
# even if it was already added.
> fish_add_path \-m ~/.local/bin
# I prefer using a global fish_user_paths
# This isn\(aqt saved automatically, I need to add this to config.fish
# if I want it to stay.
> fish_add_path \-g ~/.local/bin ~/.otherbin /usr/local/sbin
# I want to append to the entire $PATH because this directory contains fallbacks
# This needs \-\-path/\-P because otherwise it appends to $fish_user_paths,
# which is added to the front of $PATH.
> fish_add_path \-\-append \-\-path /opt/fallback/bin
# I want to add the bin/ directory of my current $PWD (say /home/nemo/)
# \-v/\-\-verbose shows what fish_add_path did.
> fish_add_path \-v bin/
set fish_user_paths /home/nemo/bin /usr/bin /home/nemo/.local/bin
# I have installed ruby via homebrew
> fish_add_path /usr/local/opt/ruby/bin
.EE
.UNINDENT
.UNINDENT
.SS fish_breakpoint_prompt \- define the prompt when stopped at a breakpoint
.SS Synopsis
.nf
\fBfish_breakpoint_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_breakpoint_prompt
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
\fBfish_breakpoint_prompt\fP is the prompt function when asking for input in response to a breakpoint \%<> command.
.sp
The exit status of commands within \fBfish_breakpoint_prompt\fP will not modify the value of $status \%<#\:variables-status> outside of the \fBfish_breakpoint_prompt\fP function.
.sp
\fBfish\fP ships with a default version of this function that displays the function name and line number of the current execution context.
.SS Example
.sp
A simple prompt that is a simplified version of the default debugging prompt:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_breakpoint_prompt \-d \(dqWrite out the debug prompt\(dq
set \-l function (status current\-function)
set \-l line (status current\-line\-number)
set \-l prompt \(dq$function:$line >\(dq
echo \-ns (set_color $fish_color_status) \(dqBP $prompt\(dq (set_color \-\-reset) \(aq \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS fish_clipboard_copy \- copy text to the system\(aqs clipboard
.SS Synopsis
.nf
\fBfish_clipboard_copy\fP
\fBfoo\fP | \fBfish_clipboard_copy\fP
.fi
.sp
.SS Description
.sp
The \fBfish_clipboard_copy\fP function copies text to the system clipboard.
.sp
If stdin is not a terminal (see isatty \%<>), it will read all input from there and copy it. If it is, it will use the current commandline, or the current selection if there is one.
.sp
It is bound to \fBctrl\fP\-\fBx\fP by default.
.sp
\fBfish_clipboard_copy\fP works by calling a system\-specific backend. If it doesn\(aqt appear to work you may need to install yours.
.sp
Currently supported are:
.INDENT 0.0
.IP \(bu 2
\fBpbcopy\fP
.IP \(bu 2
\fBwl\-copy\fP using wayland
.IP \(bu 2
\fBxsel\fP and \fBxclip\fP for X11
.IP \(bu 2
\fBclip.exe\fP on Windows.
.IP \(bu 2
The OSC 52 clipboard sequence \%<#\:term-compat-osc-52>, which your terminal might support
.UNINDENT
.SS See also
.INDENT 0.0
.IP \(bu 2
fish_clipboard_paste \- get text from the system\(aqs clipboard \%<> which does the inverse.
.UNINDENT
.SS fish_clipboard_paste \- get text from the system\(aqs clipboard
.SS Synopsis
.nf
\fBfish_clipboard_paste\fP
\fBfish_clipboard_paste\fP | \fBfoo\fP
.fi
.sp
.SS Description
.sp
The \fBfish_clipboard_paste\fP function copies text from the system clipboard.
.sp
If its stdout is not a terminal (see isatty \%<>), it will output everything there, as\-is, without any additional newlines. If it is, it will put the text in the commandline instead.
.sp
If it outputs to the commandline, it will automatically escape the output if the cursor is currently inside single\-quotes so it is suitable for single\-quotes (meaning it escapes \fB\(aq\fP and \fB\e\e\fP).
.sp
It is bound to \fBctrl\fP\-\fBv\fP by default.
.sp
\fBfish_clipboard_paste\fP works by calling a system\-specific backend. If it doesn\(aqt appear to work you may need to install yours.
.sp
Currently supported are:
.INDENT 0.0
.IP \(bu 2
\fBpbpaste\fP
.IP \(bu 2
\fBwl\-paste\fP using wayland
.IP \(bu 2
\fBxsel\fP and \fBxclip\fP for X11
.IP \(bu 2
\fBpowershell.exe\fP on Windows (this backend has encoding limitations and uses windows line endings that \fBfish_clipboard_paste\fP undoes)
.UNINDENT
.SS See also
.INDENT 0.0
.IP \(bu 2
fish_clipboard_copy \- copy text to the system\(aqs clipboard \%<> which does the inverse.
.UNINDENT
.SS fish_command_not_found \- what to do when a command wasn\(aqt found
.SS Synopsis
.nf
\fBfunction\fP \fBfish_command_not_found\fP
\&...
\fBend\fP
.fi
.sp
.SS Description
.sp
When fish tries to execute a command and can\(aqt find it, it invokes this function.
.sp
It can print a message to tell you about it, and it often also checks for a missing package that would include the command.
.sp
fish ships multiple handlers for various operating systems and chooses from them when this function is loaded,
or you can define your own.
.sp
It receives the full commandline as one argument per token, so $argv[1] contains the missing command.
.sp
When you leave \fBfish_command_not_found\fP undefined (e.g. by adding an empty function file) or explicitly call \fB__fish_default_command_not_found_handler\fP, fish will just print a simple error.
.SS Example
.sp
A simple handler:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_command_not_found
echo Did not find command $argv[1]
end
> flounder
Did not find command flounder
.EE
.UNINDENT
.UNINDENT
.sp
Or the handler for OpenSUSE\(aqs command\-not\-found:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_command_not_found
/usr/bin/command\-not\-found $argv[1]
end
.EE
.UNINDENT
.UNINDENT
.sp
Or the simple default handler:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_command_not_found
__fish_default_command_not_found_handler $argv
end
.EE
.UNINDENT
.UNINDENT
.SS fish_config \- start the web\-based configuration interface
.SS Synopsis
.nf
\fBfish_config\fP [\fBbrowse\fP]
\fBfish_config\fP \fBprompt\fP (\fBchoose\fP | \fBlist\fP | \fBsave\fP | \fBshow\fP)
\fBfish_config\fP \fBtheme\fP
\fBfish_config\fP \fBtheme\fP \fBchoose\fP \fITHEME\fP \fB[ \fP\fB\-\-color\-theme\fP\fB=\fP(\fBdark\fP | \fBlight\fP)\fB ]\fP
\fBfish_config\fP \fBtheme\fP \fBdemo\fP
\fBfish_config\fP \fBtheme\fP \fBdump\fP
\fBfish_config\fP \fBtheme\fP \fBlist\fP
\fBfish_config\fP \fBtheme\fP \fBshow\fP [\fITHEME\fP\&...]
.fi
.sp
.SS Description
.sp
\fBfish_config\fP is used to configure fish.
.sp
Without arguments or with the \fBbrowse\fP command it starts the web\-based configuration interface. The web interface allows you to view your functions, variables and history, and to make changes to your prompt and color configuration. It starts a local web server and opens a browser window. When you are finished, close the browser window and press the Enter key to terminate the configuration session.
.sp
If the \fBBROWSER\fP environment variable is set, it will be used as the name of the web browser to open instead of the system default.
.sp
With the \fBprompt\fP command \fBfish_config\fP can be used to view and choose a prompt from fish\(aqs sample prompts inside the terminal directly.
.sp
Available subcommands for the \fBprompt\fP command:
.INDENT 0.0
.IP \(bu 2
\fBchoose\fP loads a sample prompt in the current session.
.IP \(bu 2
\fBlist\fP lists the names of the available sample prompts.
.IP \(bu 2
\fBsave\fP saves the current prompt to a file (via funcsave \%<>).
.IP \(bu 2
\fBshow\fP shows what the given sample prompts (or all) would look like.
.UNINDENT
.sp
With the \fBtheme\fP command \fBfish_config\fP can be used to view and choose a theme (meaning a color scheme) inside the terminal.
.sp
Available subcommands for the \fBtheme\fP command:
.INDENT 0.0
.IP \(bu 2
\fBchoose\fP loads a theme in the current session.
If the theme has light and dark variants (see below), the one matching \fBfish_terminal_color_theme\fP \%<#\:envvar-fish_terminal_color_theme> will be applied (also whenever that variable changes).
To override \fBfish_terminal_color_theme\fP \%<#\:envvar-fish_terminal_color_theme>, pass the \fB\-\-color\-theme\fP argument.
.IP \(bu 2
\fBdemo\fP displays some sample text in the current theme.
.IP \(bu 2
\fBdump\fP prints the current theme in a loadable format.
.IP \(bu 2
\fBlist\fP lists the names of the available themes.
.IP \(bu 2
\fBshow\fP shows what the given themes (or all) would look like.
.IP \(bu 2
\fI(not recommended)\fP \fBsave\fP saves the given theme to universal variables \%<#\:variables-universal>\&.
A theme set this way will not update as \fBfish_terminal_color_theme\fP \%<#\:envvar-fish_terminal_color_theme> changes.
.UNINDENT
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Theme Files
.sp
\fBfish_config theme\fP and the theme selector in the web config tool load their themes from theme files. These are stored in the fish configuration directory, typically \fB~/.config/fish/themes\fP, with a .theme ending.
.sp
You can add your own theme by adding a file in that directory.
.sp
To get started quickly:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_config theme dump > ~/.config/fish/themes/my.theme
.EE
.UNINDENT
.UNINDENT
.sp
which will save your current theme in .theme format.
.sp
The format looks like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# name: \(aqMy Theme\(aq
[light]
# preferred_background: ffffff
fish_color_normal 000000
fish_color_autosuggestion 7f7f7f
fish_color_command 0000ee
[dark]
# preferred_background: 000000
fish_color_normal ffffff
fish_color_autosuggestion 7f7f7f
fish_color_command 5c5cff
[unknown]
fish_color_normal \-\-reset
fish_color_autosuggestion brblack
fish_color_cancel \-r
fish_color_command \-\-reset
.EE
.UNINDENT
.UNINDENT
.sp
The comments provide name and background color to the web config tool.
.sp
Themes can have three variants,
one for light mode,
one for dark mode,
and one for terminals that don\(aqt report colors \%<#\:term-compat-query-background-color> (where \fBfish_terminal_color_theme\fP \%<#\:envvar-fish_terminal_color_theme> is set to \fBunknown\fP).
.sp
The other lines are just like \fBset variable value\fP, except that no expansions are allowed. Quotes are, but aren\(aqt necessary.
.sp
Other than that, .theme files can contain any variable with a name that matches the regular expression \fB\(aq^fish_(?:pager_)?color_.*$\(aq\fP \- starts with \fBfish_\fP, an optional \fBpager_\fP, then \fBcolor_\fP and then anything.
.SS Example
.sp
\fBfish_config\fP or \fBfish_config browse\fP opens a new web browser window and allows you to configure certain fish settings.
.sp
\fBfish_config prompt show\fP demos the available sample prompts.
.sp
\fBfish_config prompt choose disco\fP makes the disco prompt the prompt for the current session. This can also be used in config.fish \%<#\:configuration> to set the prompt.
.sp
\fBfish_config prompt save\fP saves the current prompt to an autoloaded \%<#\:syntax-function-autoloading> file.
.sp
\fBfish_config prompt save default\fP chooses the default prompt and saves it.
.SS fish_darcs_prompt \- output Darcs information for use in a prompt
.SS Synopsis
.nf
\fBfish_darcs_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
printf \(aq%s\(aq $PWD (fish_darcs_prompt) \(aq $ \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_darcs_prompt\fP function displays information about the current Darcs repository, if any.
.sp
Darcs \% must be installed.
.sp
The prompt always shows the VCS name (configurable via \fB$fish_prompt_darcs_name\fP, default \fBdarcs\fP) as there are no branches/channels; it can be unset to remove it entirely. If the repository has unrecorded changes, status counts are shown for each change type:
.INDENT 0.0
.IP \(bu 2
\fB$fish_color_darcs_normal\fP, default \fBgreen\fP (the prompt label color)
.IP \(bu 2
\fB$fish_color_darcs_rebasing\fP, default \fByellow\fP (used when a rebase is in progress)
.UNINDENT
.sp
To match Darcs’s logo green:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set fish_color_darcs_normal 72ff01
.EE
.UNINDENT
.UNINDENT
.sp
The Darcs status symbols:
.INDENT 0.0
.IP \(bu 2
\fB$fish_prompt_darcs_status_added\fP, default \fB+\fP
.IP \(bu 2
\fB$fish_prompt_darcs_status_modified\fP, default \fB*\fP
.IP \(bu 2
\fB$fish_prompt_darcs_status_removed\fP, default \fB\-\fP
.IP \(bu 2
\fB$fish_prompt_darcs_status_moved\fP, default \fB→\fP
.IP \(bu 2
\fB$fish_prompt_darcs_status_untracked\fP, default \fB…\fP
.IP \(bu 2
\fB$fish_prompt_darcs_status_conflict\fP, default \fB!\fP
.UNINDENT
.sp
Colors for these symbols can be set with the corresponding variables (\fB$fish_color_darcs_added\fP & so on), which are unset by default so the terminal’s foreground color is used.
.sp
\fB$fish_prompt_darcs_status_order\fP can be used to change the order the status symbols appear in. It defaults to \fBadded removed modified moved conflict untracked\fP\&.
.sp
See also fish_vcs_prompt \%<>, which will call all supported version control prompt functions, including Git, Mercurial, & Darcs.
.SS Example
.sp
A simple prompt that displays darcs info:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
...
printf \(aq%s %s$\(aq $PWD (fish_darcs_prompt)
end
.EE
.UNINDENT
.UNINDENT
.SS fish_default_key_bindings \- set emacs key bindings for fish
.SS Synopsis
.nf
\fBfish_default_key_bindings\fP
.fi
.sp
.SS Description
.sp
\fBfish_default_key_bindings\fP sets the emacs key bindings for \fBfish\fP shell.
.sp
Some of the Emacs key bindings are defined here \%<#\:emacs-mode>\&.
.sp
There are no parameters for \fBfish_default_key_bindings\fP\&.
.SS Examples
.sp
To start using emacs key bindings:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_default_key_bindings
.EE
.UNINDENT
.UNINDENT
.SS fish_delta \- compare functions and completions to the default
.SS Synopsis
.nf
\fBfish_delta\fP \fBname\fP \&...
\fBfish_delta\fP [\fB\-f\fP | \fB\-\-no\-functions\fP] [\fB\-c\fP | \fB\-\-no\-completions\fP] [\fB\-C\fP | \fB\-\-no\-config\fP] [\fB\-d\fP | \fB\-\-no\-diff\fP] [\fB\-n\fP | \fB\-\-new\fP] [\fB\-V\fP | \fB\-\-vendor\fP\fB=\fP]
\fBfish_delta\fP [\fB\-h\fP | \fB\-\-help\fP]
.fi
.sp
.SS Description
.sp
The \fBfish_delta\fP function tells you, at a glance, which of your functions and completions differ from the set that fish ships.
.sp
It does this by going through the relevant variables (\fBfish_function_path\fP \%<#\:envvar-fish_function_path> for functions and \fBfish_complete_path\fP \%<#\:envvar-fish_complete_path> for completions) and comparing the files against fish\(aqs default directories.
.sp
If any names are given, it will only compare files by those names (plus a \(dq.fish\(dq extension).
.sp
By default, it will also use \fBdiff\fP to display the difference between the files. If \fBdiff\fP is unavailable, it will skip it, but in that case it also cannot figure out if the files really differ.
.sp
The exit status is 1 if there was a difference and 2 for other errors, otherwise 0.
.SS Options
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-f\fP or \fB\-\-no\-functions\fP
Skips checking functions
.TP
\fB\-c\fP or \fB\-\-no\-completions\fP
Skips checking completions
.TP
\fB\-C\fP or \fB\-\-no\-config\fP
Skips checking configuration files like config.fish or snippets in the conf.d directories.
.TP
\fB\-d\fP or \fB\-\-no\-diff\fP
Removes the diff display (this happens automatically if \fBdiff\fP can\(aqt be found)
.TP
\fB\-n\fP or \fB\-\-new\fP
Also prints new files (i.e. those that can\(aqt be found in fish\(aqs default directories).
.TP
\fB\-Vvalue\fP or \fB\-\-vendor=value\fP
Determines how the vendor directories are counted. Valid values are:
.INDENT 7.0
.IP \(bu 2
\(dqdefault\(dq \- counts vendor files as belonging to the defaults. Any changes in other directories will be counted as changes over them. This is the default.
.IP \(bu 2
\(dquser\(dq \- counts vendor files as belonging to the user files. Any changes in them will be counted as new or changed files.
.IP \(bu 2
\(dqignore\(dq \- ignores vendor directories. Files of the same name will be counted as \(dqnew\(dq if no file of the same name in fish\(aqs default directories exists.
.UNINDENT
.TP
\fB\-h\fP or \fB\-\-help\fP
Prints \fBfish_delta\fP\(aqs help (this).
.UNINDENT
.SS Example
.sp
Running just:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_delta
.EE
.UNINDENT
.UNINDENT
.sp
will give you a list of all your changed functions and completions, including diffs (if you have the \fBdiff\fP command).
.sp
It might look like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish_delta
New: /home/alfa/.config/fish/functions/battery.fish
Changed: /home/alfa/.config/fish/test/completions/cargo.fish
\-\-\- /home/alfa/.config/fish/test/completions/cargo.fish 2022\-09\-02 12:57:55.579229959 +0200
+++ /usr/share/fish/completions/cargo.fish 2022\-09\-25 17:51:53.000000000 +0200
# the output of \(gadiff\(ga follows
.EE
.UNINDENT
.UNINDENT
.sp
The options are there to select which parts of the output you want. With \fB\-\-no\-completions\fP you can compare just functions, and with \fB\-\-no\-diff\fP you can turn off the \fBdiff\fP display.
.sp
To only compare your \fBfish_git_prompt\fP, you might use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_delta \-\-no\-completions fish_git_prompt
.EE
.UNINDENT
.UNINDENT
.sp
which will only compare files called \(dqfish_git_prompt.fish\(dq.
.SS fish_git_prompt \- output git information for use in a prompt
.SS Synopsis
.nf
\fBfish_git_prompt\fP [\fIFORMAT\fP]
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
printf \(aq%s\(aq $PWD (fish_git_prompt) \(aq $ \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_git_prompt\fP function displays information about the current git repository, if any.
.sp
Git \% must be installed.
.sp
It is possible to modify the output format by passing an argument. The default value is \fB\(dq (%s)\(dq\fP\&.
.sp
There are numerous customization options, which can be controlled with git options or fish variables. git options, where available, take precedence over the fish variable with the same function. git options can be set on a per\-repository or global basis. git options can be set with the \fBgit config\fP command, while fish variables can be set as usual with the set \%<> command.
.sp
Boolean options (those which enable or disable something) understand \(dq1\(dq, \(dqyes\(dq or \(dqtrue\(dq to mean true and every other value to mean false.
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_show_informative_status\fP or the git option \fBbash.showInformativeStatus\fP can be set to 1, true or yes to enable the \(dqinformative\(dq display, which will show a large amount of information \- the number of dirty files, unpushed/unpulled commits, and more.
In large repositories, this can take a lot of time, so you may wish to disable it in these repositories with \fBgit config \-\-local bash.showInformativeStatus false\fP\&. It also changes the characters the prompt uses to less plain ones (\fB✚\fP instead of \fB*\fP for the dirty state for example) , and if you are only interested in that, set \fB$__fish_git_prompt_use_informative_chars\fP instead.
.sp
Because counting untracked files requires a lot of time, the number of untracked files is only shown if enabled via \fB$__fish_git_prompt_showuntrackedfiles\fP or the git option \fBbash.showUntrackedFiles\fP\&.
.IP \(bu 2
\fB$__fish_git_prompt_showdirtystate\fP or the git option \fBbash.showDirtyState\fP can be set to 1, true or yes to show if the repository is \(dqdirty\(dq, i.e. has uncommitted changes.
.IP \(bu 2
\fB$__fish_git_prompt_showuntrackedfiles\fP or the git option \fBbash.showUntrackedFiles\fP can be set to 1, true or yes to show if the repository has untracked files (that aren\(aqt ignored).
.IP \(bu 2
\fB$__fish_git_prompt_showupstream\fP can be set to a list of values to determine how changes between HEAD and upstream are shown:
.INDENT 2.0
.INDENT 3.5
.INDENT 0.0
.TP
.B \fBauto\fP
summarize the difference between HEAD and its upstream
.TP
.B \fBverbose\fP
show number of commits ahead/behind (+/\-) upstream
.TP
.B \fBname\fP
if verbose, then also show the upstream abbrev name
.TP
.B \fBinformative\fP
similar to verbose, but shows nothing when equal \- this is the default if informative status is enabled.
.TP
.B \fBgit\fP
always compare HEAD to @{upstream}
.TP
.B \fBsvn\fP
always compare HEAD to your SVN upstream
.TP
.B \fBnone\fP
disables (useful with informative status)
.UNINDENT
.UNINDENT
.UNINDENT
.IP \(bu 2
\fB$__fish_git_prompt_showstashstate\fP can be set to 1, true or yes to display the state of the stash.
.IP \(bu 2
\fB$__fish_git_prompt_shorten_branch_len\fP can be set to the number of characters that the branch name will be shortened to.
.IP \(bu 2
\fB$__fish_git_prompt_describe_style\fP can be set to one of the following styles to describe the current HEAD:
.INDENT 2.0
.INDENT 3.5
.INDENT 0.0
.TP
.B \fBcontains\fP
relative to newer annotated tag, such as \fB(v1.6.3.2~35)\fP
.TP
.B \fBbranch\fP
relative to newer tag or branch, such as \fB(master~4)\fP
.TP
.B \fBdescribe\fP
relative to older annotated tag, such as \fB(v1.6.3.1\-13\-gdd42c2f)\fP
.TP
.B \fBdefault\fP
an exactly matching tag (\fB(develop)\fP)
.UNINDENT
.sp
If none of these apply, the commit SHA shortened to 8 characters is used.
.UNINDENT
.UNINDENT
.IP \(bu 2
\fB$__fish_git_prompt_showcolorhints\fP can be set to 1, true or yes to enable coloring for the branch name and status symbols.
.UNINDENT
.sp
A number of variables set characters and color used as indicators. Many of these have a different default if used with informative status enabled, or \fB$__fish_git_prompt_use_informative_chars\fP set. The usual default is given first, then the informative default (if it is different). If no default for the colors is given, they default to \fB$__fish_git_prompt_color\fP\&.
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_char_stateseparator\fP (\(aq \(aq, \fB|\fP) \- the character to be used between the state characters
.IP \(bu 2
\fB$__fish_git_prompt_color\fP (no default)
.IP \(bu 2
\fB$__fish_git_prompt_color_prefix\fP \- the color of the \fB(\fP prefix
.IP \(bu 2
\fB$__fish_git_prompt_color_suffix\fP \- the color of the \fB)\fP suffix
.IP \(bu 2
\fB$__fish_git_prompt_color_bare\fP \- the color to use for a bare repository \- one without a working tree
.IP \(bu 2
\fB$__fish_git_prompt_color_merging\fP \- the color when a merge/rebase/revert/bisect or cherry\-pick is in progress
.IP \(bu 2
\fB$__fish_git_prompt_char_cleanstate\fP (✔ in informative mode) \- the character to be used when nothing else applies
.IP \(bu 2
\fB$__fish_git_prompt_color_cleanstate\fP (no default)
.UNINDENT
.sp
Variables used with \fBshowdirtystate\fP:
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_char_dirtystate\fP (\fI*\fP, ✚) \- the number of \(dqdirty\(dq changes, i.e. unstaged files with changes
.IP \(bu 2
\fB$__fish_git_prompt_char_invalidstate\fP (#, ✖) \- the number of \(dqunmerged\(dq changes, e.g. additional changes to already added files
.IP \(bu 2
\fB$__fish_git_prompt_char_stagedstate\fP (+, ●) \- the number of staged files without additional changes
.IP \(bu 2
\fB$__fish_git_prompt_color_dirtystate\fP (red with showcolorhints, same as color_flags otherwise)
.IP \(bu 2
\fB$__fish_git_prompt_color_invalidstate\fP
.IP \(bu 2
\fB$__fish_git_prompt_color_stagedstate\fP (green with showcolorhints, color_flags otherwise)
.UNINDENT
.sp
Variables used with \fBshowstashstate\fP:
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_char_stashstate\fP (\fB$\fP, ⚑)
.IP \(bu 2
\fB$__fish_git_prompt_color_stashstate\fP (same as color_flags)
.UNINDENT
.sp
Variables used with \fBshowuntrackedfiles\fP:
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_char_untrackedfiles\fP (%, …) \- the symbol for untracked files
.IP \(bu 2
\fB$__fish_git_prompt_color_untrackedfiles\fP (same as color_flags)
.UNINDENT
.sp
Variables used with \fBshowupstream\fP (also implied by informative status):
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_char_upstream_ahead\fP (>, ↑) \- the character for the commits this repository is ahead of upstream
.IP \(bu 2
\fB$__fish_git_prompt_char_upstream_behind\fP (<, ↓) \- the character for the commits this repository is behind upstream
.IP \(bu 2
\fB$__fish_git_prompt_char_upstream_diverged\fP (<>, ↓↑) \- the symbol if this repository is both ahead and behind upstream
.IP \(bu 2
\fB$__fish_git_prompt_char_upstream_equal\fP (=) \- the symbol if this repo is equal to upstream
.IP \(bu 2
\fB$__fish_git_prompt_char_upstream_prefix\fP (\(aq\(aq)
.IP \(bu 2
\fB$__fish_git_prompt_color_upstream\fP
.UNINDENT
.sp
Colors used with \fBshowcolorhints\fP:
.INDENT 0.0
.IP \(bu 2
\fB$__fish_git_prompt_color_branch\fP (green) \- the color of the branch if nothing else applies
.IP \(bu 2
\fB$__fish_git_prompt_color_branch_detached\fP (red) the color of the branch if it\(aqs detached (e.g. a commit is checked out)
.IP \(bu 2
\fB$__fish_git_prompt_color_branch_dirty\fP (no default) the color of the branch if it\(aqs dirty and not detached
.IP \(bu 2
\fB$__fish_git_prompt_color_branch_staged\fP (no default) the color of the branch if it just has something staged and is otherwise clean
.IP \(bu 2
\fB$__fish_git_prompt_color_flags\fP (\-\-bold blue) \- the default color for dirty/staged/stashed/untracked state
.UNINDENT
.sp
Note that all colors can also have a corresponding \fB_done\fP color. For example, the contents of \fB$__fish_git_prompt_color_upstream_done\fP is printed right _after_ the upstream.
.sp
See also fish_vcs_prompt \%<>, which will call all supported version control prompt functions, including git, Mercurial and Subversion.
.SS Example
.sp
A simple prompt that displays git info:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
# ...
set \-g __fish_git_prompt_showupstream auto
printf \(aq%s %s$\(aq $PWD (fish_git_prompt)
end
.EE
.UNINDENT
.UNINDENT
.SS fish_greeting \- display a welcome message in interactive shells
.SS Synopsis
.nf
\fBfish_greeting\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_greeting
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
When an interactive fish starts, it executes fish_greeting and displays its output.
.sp
The default fish_greeting is a function that prints a variable of the same name (\fB$fish_greeting\fP), so you can also just change that if you just want to change the text.
.sp
If \fBSHELL_WELCOME\fP \%<#\:envvar-SHELL_WELCOME> is set, it is displayed after the greeting. This is a standard environment variable that may be set by tools like systemd\(aqs \fBrun0\fP to display session information.
.sp
While you could also just put \fBecho\fP calls into config.fish, fish_greeting takes care of only being used in interactive shells, so it won\(aqt be used e.g. with \fBscp\fP (which executes a shell), which prevents some errors.
.SS Example
.sp
To just empty the text, with the default greeting function:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-U fish_greeting
.EE
.UNINDENT
.UNINDENT
.sp
or \fBset \-g fish_greeting\fP in config.fish \%<#\:configuration>\&.
.sp
A simple greeting:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_greeting
echo Hello friend!
echo The time is (set_color yellow)(date +%T)(set_color \-\-reset) and this machine is called $hostname
end
.EE
.UNINDENT
.UNINDENT
.SS fish_hg_prompt \- output Mercurial information for use in a prompt
.SS Synopsis
.nf
\fBfish_hg_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
printf \(aq%s\(aq $PWD (fish_hg_prompt) \(aq $ \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The fish_hg_prompt function displays information about the current Mercurial repository, if any.
.sp
Mercurial \% (\fBhg\fP) must be installed.
.sp
By default, only the current branch is shown because \fBhg status\fP can be slow on a large repository. You can enable a more informative prompt by setting the variable \fB$fish_prompt_hg_show_informative_status\fP, for example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set fish_prompt_hg_show_informative_status
.EE
.UNINDENT
.UNINDENT
.sp
If you enabled the informative status, there are numerous customization options, which can be controlled with fish variables.
.INDENT 0.0
.IP \(bu 2
\fB$fish_color_hg_clean\fP, \fB$fish_color_hg_modified\fP and \fB$fish_color_hg_dirty\fP are colors used when the repository has the respective status.
.UNINDENT
.sp
Some colors for status symbols:
.INDENT 0.0
.IP \(bu 2
\fB$fish_color_hg_added\fP
.IP \(bu 2
\fB$fish_color_hg_renamed\fP
.IP \(bu 2
\fB$fish_color_hg_copied\fP
.IP \(bu 2
\fB$fish_color_hg_deleted\fP
.IP \(bu 2
\fB$fish_color_hg_untracked\fP
.IP \(bu 2
\fB$fish_color_hg_unmerged\fP
.UNINDENT
.sp
The status symbols themselves:
.INDENT 0.0
.IP \(bu 2
\fB$fish_prompt_hg_status_added\fP, default \(aq✚\(aq
.IP \(bu 2
\fB$fish_prompt_hg_status_modified\fP, default \(aq*\(aq
.IP \(bu 2
\fB$fish_prompt_hg_status_copied\fP, default \(aq⇒\(aq
.IP \(bu 2
\fB$fish_prompt_hg_status_deleted\fP, default \(aq✖\(aq
.IP \(bu 2
\fB$fish_prompt_hg_status_untracked\fP, default \(aq?\(aq
.IP \(bu 2
\fB$fish_prompt_hg_status_unmerged\fP, default \(aq!\(aq
.UNINDENT
.sp
Finally, \fB$fish_prompt_hg_status_order\fP, which can be used to change the order the status symbols appear in. It defaults to \fBadded modified copied deleted untracked unmerged\fP\&.
.sp
See also fish_vcs_prompt \%<>, which will call all supported version control prompt functions, including git, Mercurial and Subversion.
.SS Example
.sp
A simple prompt that displays hg info:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
...
set \-g fish_prompt_hg_show_informative_status
printf \(aq%s %s$\(aq $PWD (fish_hg_prompt)
end
.EE
.UNINDENT
.UNINDENT
.SS fish_indent \- indenter and prettifier
.SS Synopsis
.nf
\fBfish_indent\fP [\fIOPTIONS\fP] [\fIFILE\fP \&...]
.fi
.sp
.SS Description
.sp
\fBfish_indent\fP is used to indent a piece of fish code. \fBfish_indent\fP reads commands from standard input or the given filenames and outputs them to standard output or a specified file (if \fB\-w\fP is given).
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-w\fP or \fB\-\-write\fP
Indents a specified file and immediately writes to that file.
.TP
\fB\-i\fP or \fB\-\-no\-indent\fP
Do not indent commands; only reformat to one job per line.
.TP
\fB\-\-only\-indent\fP
Do not reformat, only indent each line.
.TP
\fB\-\-only\-unindent\fP
Do not reformat, only unindent each line.
.TP
\fB\-c\fP or \fB\-\-check\fP
Do not indent, only return 0 if the code is already indented as fish_indent would, the number of failed files otherwise. Also print the failed filenames if not reading from standard input.
.TP
\fB\-v\fP or \fB\-\-version\fP
Displays the current \fBfish\fP version and then exits.
.TP
\fB\-\-ansi\fP
Colorizes the output using ANSI escape sequences using the colors defined in the environment (such as \fBfish_color_command\fP \%<#\:envvar-fish_color_command>).
.TP
\fB\-\-html\fP
Outputs HTML, which supports syntax highlighting if the appropriate CSS is defined. The CSS class names are the same as the variable names, such as \fBfish_color_command\fP\&.
.TP
\fB\-\-dump\-parse\-tree\fP
Dumps information about the parsed statements to standard error. This is likely to be of interest only to people working on the fish source code.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS fish_is_root_user \- check if the current user is root
.SS Synopsis
.nf
\fBfish_is_root_user\fP
.fi
.sp
.SS Description
.sp
\fBfish_is_root_user\fP will check if the current user is root. It can be useful
for the prompt to display something different if the user is root, for example.
.SS Example
.sp
A simple example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function example \-\-description \(aqJust an example\(aq
if fish_is_root_user
do_something_different
end
end
.EE
.UNINDENT
.UNINDENT
.SS fish_key_reader \- explore what characters keyboard keys send
.SS Synopsis
.nf
\fBfish_key_reader\fP [\fIOPTIONS\fP]
.fi
.sp
.SS Description
.sp
\fBfish_key_reader\fP is used to explain how you would bind a certain key sequence. By default, it prints the bind \%<> command for one key sequence read interactively over standard input.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-c\fP or \fB\-\-continuous\fP
Begins a session where multiple key sequences can be inspected. By default the program exits after capturing a single key sequence.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.TP
\fB\-V\fP or \fB\-\-verbose\fP
Explain what sequence was received in addition to the decoded key.
.TP
\fB\-v\fP or \fB\-\-version\fP
Displays the current \fBfish\fP version and then exits.
.UNINDENT
.SS Usage Notes
.sp
\fBfish_key_reader\fP intentionally disables handling of many signals. To terminate \fBfish_key_reader\fP in \fB\-\-continuous\fP mode do:
.INDENT 0.0
.IP \(bu 2
press \fBctrl\fP\-\fBc\fP twice, or
.IP \(bu 2
press \fBctrl\fP\-\fBd\fP twice, or
.IP \(bu 2
type \fBexit\fP, or
.IP \(bu 2
type \fBquit\fP
.UNINDENT
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish_key_reader
Press a key:
# press up\-arrow
bind up \(aqdo something\(aq
.EE
.UNINDENT
.UNINDENT
.SS fish_mode_prompt \- define the appearance of the mode indicator
.SS Synopsis
.nf
\fBfish_mode_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_mode_prompt
echo \-n \(dq$fish_bind_mode \(dq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_mode_prompt\fP function outputs the mode indicator for use in vi mode.
.sp
The default \fBfish_mode_prompt\fP function will output indicators about the current vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. The \fB$fish_bind_mode\fP variable can be used to determine the current mode. It will be one of \fBdefault\fP, \fBinsert\fP, \fBreplace_one\fP, \fBreplace\fP, \fBvisual\fP, or \fBoperator\fP\&.
.sp
You can also define an empty \fBfish_mode_prompt\fP function to remove the vi mode indicators:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_mode_prompt; end
funcsave fish_mode_prompt
.EE
.UNINDENT
.UNINDENT
.sp
\fBfish_mode_prompt\fP will be executed when the vi mode changes. If it produces any output, it is displayed and used. If it does not, the other prompt functions (fish_prompt \%<> and fish_right_prompt \%<>) will be executed as well in case they contain a mode display.
.sp
If \fBfish_transient_prompt\fP \%<#\:envvar-fish_transient_prompt> is set to 1, \fBfish_mode_prompt \-\-final\-rendering\fP is run before executing the commandline.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_mode_prompt
switch $fish_bind_mode
case default
set_color \-\-bold red
echo \(aqN\(aq
case insert
set_color \-\-bold green
echo \(aqI\(aq
case replace_one
set_color \-\-bold green
echo \(aqR\(aq
case replace
set_color \-\-bold bryellow
echo \(aqR\(aq
case visual
set_color \-\-bold brmagenta
echo \(aqV\(aq
case operator f F t T
set_color \-\-bold cyan
echo \(aqN\(aq
case \(aq*\(aq
set_color \-\-bold red
echo \(aq?\(aq
end
set_color \-\-reset
end
.EE
.UNINDENT
.UNINDENT
.sp
Outputting multiple lines is not supported in \fBfish_mode_prompt\fP\&.
.SS fish_opt \- create an option specification for the argparse command
.SS Synopsis
.nf
\fBfish_opt\fP [\fB\-s\fP \fIALPHANUM\fP] [\fB\-l\fP \fILONG\-NAME\fP] [\fB\-ormd\fP] [\fB\-\-long\-only\fP] [\fB\-v\fP \fICOMMAND\fP \fIOPTIONS\fP \&...\fB ]\fP
\fBfish_opt\fP \fB\-\-help\fP
.fi
.sp
.SS Description
.sp
This command provides a way to produce option specifications suitable for use with the argparse \%<> command. You can, of course, write the option specifications by hand without using this command. But you might prefer to use this for the clarity it provides.
.sp
The following \fBargparse\fP options are available:
.INDENT 0.0
.TP
\fB\-s\fP or \fB\-\-short\fP \fIALPHANUM\fP
Takes a single letter or number that is used as the short flag in the option being defined. Either this option or the \fB\-\-long\fP option must be provided.
.TP
\fB\-l\fP or \fB\-\-long\fP \fILONG\-NAME\fP
Takes a string that is used as the long flag in the option being defined. This option is optional and has no default. If no long flag is defined then only the short flag will be allowed when parsing arguments using the option specification.
.TP
\fB\-\-long\-only\fP
Deprecated. The option being defined will only allow the long flag name to be used, even if the short flag is defined (i.e., \fB\-\-short\fP is specified).
.TP
\fB\-o\fP or \fB\-\-optional\-val\fP
The option being defined can take a value, but it is optional rather than required. If the option is seen more than once when parsing arguments, only the last value seen is saved. This means the resulting flag variable created by \fBargparse\fP will zero elements if no value was given with the option else it will have exactly one element.
.TP
\fB\-r\fP or \fB\-\-required\-val\fP
The option being defined requires a value. If the option is seen more than once when parsing arguments, only the last value seen is saved. This means the resulting flag variable created by \fBargparse\fP will have exactly one element.
.TP
\fB\-m\fP or \fB\-\-multiple\-vals\fP
The value of each instance of the option is accumulated. If \fB\-\-optional\-val\fP is provided, the value is optional, and an empty string is stored if no value is provided. Otherwise, the \fB\-\-requiured\-val\fP option is implied and each instance of the option requires a value. This means the resulting flag variable created by \fBargparse\fP will have one element for each instance of this option in the arguments, even for instances that did not provide a value.
.TP
\fB\-d\fP or \fB\-\-delete\fP
The option and any values will be deleted from the \fB$argv_opts\fP variables set by \fBargparse\fP
(as with other options, it will also be deleted from \fB$argv\fP).
.TP
\fB\-v\fP or \fB\-\-validate\fP \fICOMMAND\fP \fIOPTION...\fP
This option must be the last one, and requires one of \fB\-o\fP, \fB\-r\fP, or \fB\-m\fP\&. All the remaining arguments are interpreted a fish script to run to validate the value of the argument, see \fBargparse\fP documentation for more details. Note that the interpretation of \fICOMMAND\fP \fIOPTION...\fP is similar to \fBeval\fP, so you may need to quote or escape special characters \fItwice\fP if you want them to be interpreted literally when the validate script is run.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Examples
.sp
Define a single option specification for the boolean help flag:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l options (fish_opt \-s h \-l help)
argparse $options \-\- $argv
.EE
.UNINDENT
.UNINDENT
.sp
Same as above but with a second flag that requires a value:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l options (fish_opt \-s h \-l help)
set options $options (fish_opt \-s m \-l max \-r)
argparse $options \-\- $argv
.EE
.UNINDENT
.UNINDENT
.sp
Same as above but the value of the second flag cannot be the empty string:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l options (fish_opt \-s h \-l help)
set options $options (fish_opt \-s m \-l max \-rv test \e$_flag_value != \(dq\(aq\(aq\(dq)
argparse $options \-\- $argv
.EE
.UNINDENT
.UNINDENT
.sp
Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only a long flag name (\fB\-\-token\fP) is defined:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l options (fish_opt \-\-short=h \-\-long=help)
set options $options (fish_opt \-\-short=m \-\-long=max \-\-required\-val \-\-validate test \e$_flag_value != \(dq\(aq\(aq\(dq)
set options $options (fish_opt \-\-long=token \-\-multiple\-vals)
argparse $options \-\- $argv
.EE
.UNINDENT
.UNINDENT
.SS fish_prompt \- define the appearance of the command line prompt
.SS Synopsis
.nf
\fBfish_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_prompt\fP function is executed when the prompt is to be shown, and the output is used as a prompt.
.sp
The exit status of commands within \fBfish_prompt\fP will not modify the value of $status \%<#\:variables-status> outside of the \fBfish_prompt\fP function.
.sp
If \fBfish_transient_prompt\fP \%<#\:envvar-fish_transient_prompt> is set to 1, \fBfish_prompt \-\-final\-rendering\fP is run before executing the commandline.
.sp
If \fBSHELL_PROMPT_PREFIX\fP \%<#\:envvar-SHELL_PROMPT_PREFIX> or \fBSHELL_PROMPT_SUFFIX\fP \%<#\:envvar-SHELL_PROMPT_SUFFIX> are set, they are automatically prepended and appended to the left prompt. This applies to all prompts regardless of whether \fBfish_prompt\fP has been customized.
.sp
\fBfish\fP ships with a number of example prompts that can be chosen with the \fBfish_config\fP command.
.SS Example
.sp
A simple prompt:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt \-d \(dqWrite out the prompt\(dq
# This shows up as USER@HOST /home/user/ >, with the directory colored
# $USER and $hostname are set by fish, so you can just use them
# instead of using \(gawhoami\(ga and \(gahostname\(ga
printf \(aq%s@%s %s%s%s > \(aq $USER $hostname \e
(set_color $fish_color_cwd) (prompt_pwd) (set_color \-\-reset)
end
.EE
.UNINDENT
.UNINDENT
.SS fish_right_prompt \- define the appearance of the right\-side command line prompt
.SS Synopsis
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_right_prompt
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
\fBfish_right_prompt\fP is similar to \fBfish_prompt\fP, except that it appears on the right side of the terminal window.
.sp
Multiple lines are not supported in \fBfish_right_prompt\fP\&.
.sp
If \fBfish_transient_prompt\fP \%<#\:envvar-fish_transient_prompt> is set to 1, \fBfish_right_prompt \-\-final\-rendering\fP is run before executing the commandline.
.SS Example
.sp
A simple right prompt:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_right_prompt \-d \(dqWrite out the right prompt\(dq
date \(aq+%m/%d/%y\(aq
end
.EE
.UNINDENT
.UNINDENT
.SS fish_should_add_to_history \- decide whether a command should be added to the history
.SS Synopsis
.nf
\fBfish_should_add_to_history\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_should_add_to_history
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_should_add_to_history\fP function is executed before fish adds a command to history, and its return status decides whether that is done.
.sp
If it returns 0, the command is stored in history, when it returns anything else, it is not. In the latter case the command can still be recalled for one command.
.sp
The first argument to \fBfish_should_add_to_history\fP is the commandline. History is added \fIbefore\fP a command is run, so e.g. \fBstatus\fP \%<#\:envvar-status> can\(aqt be checked. This is so commands that don\(aqt finish like exec \- execute command in current process \%<> and long\-running commands are available in new sessions immediately.
.sp
If \fBfish_should_add_to_history\fP doesn\(aqt exist, fish will save a command to history unless it starts with a space. If it does exist, this function takes over all of the duties, so commands starting with space are saved unless \fBfish_should_add_to_history\fP says otherwise.
.SS Example
.sp
A simple example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_should_add_to_history
for cmd in vault mysql ls
string match \-qr \(dq^$cmd\(dq \-\- $argv; and return 1
end
return 0
end
.EE
.UNINDENT
.UNINDENT
.sp
This refuses to store any immediate \(dqvault\(dq, \(dqmysql\(dq or \(dqls\(dq calls. Commands starting with space would be stored.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_should_add_to_history
# I don\(aqt want \(gagit pull\(gas in my history when I\(aqm in a specific repository
if string match \-qr \(aq^git pull\(aq \-\- \(dq$argv\(dq
and string match \-qr \(dq^/home/me/my\-secret\-project/\(dq \-\- (pwd \-P)
return 1
end
return 0
end
.EE
.UNINDENT
.UNINDENT
.SS fish_status_to_signal \- convert exit codes to human\-friendly signals
.SS Synopsis
.nf
\fBfish_status_to_signal\fP \fINUM\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
echo \-n (fish_status_to_signal $pipestatus | string join \(aq|\(aq) (prompt_pwd) \(aq$ \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
\fBfish_status_to_signal\fP converts exit codes to their corresponding human\-friendly signals if one exists.
This is likely to be useful for prompts in conjunction with the \fB$status\fP and \fB$pipestatus\fP variables.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ sleep 5
^C⏎
>_ fish_status_to_signal $status
SIGINT
.EE
.UNINDENT
.UNINDENT
.SS fish_svn_prompt \- output Subversion information for use in a prompt
.SS Synopsis
.nf
\fBfish_svn_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
printf \(aq%s\(aq $PWD (fish_svn_prompt) \(aq $ \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The fish_svn_prompt function displays information about the current Subversion repository, if any.
.sp
Subversion \% (\fBsvn\fP) must be installed.
.sp
There are numerous customization options, which can be controlled with fish variables.
.INDENT 0.0
.IP \(bu 2
.INDENT 2.0
.TP
.B \fB__fish_svn_prompt_color_revision\fP
the colour of the revision number to display in the prompt
.UNINDENT
.IP \(bu 2
.INDENT 2.0
.TP
.B \fB__fish_svn_prompt_char_separator\fP
the separator between status characters
.UNINDENT
.UNINDENT
.sp
A number of variables control the symbol (\(dqdisplay\(dq) and color (\(dqcolor\(dq) for the different status indicators:
.INDENT 0.0
.IP \(bu 2
\fB__fish_svn_prompt_char_added_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_added_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_conflicted_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_conflicted_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_deleted_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_deleted_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_ignored_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_ignored_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_modified_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_modified_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_replaced_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_replaced_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_unversioned_external_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_unversioned_external_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_unversioned_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_unversioned_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_missing_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_missing_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_versioned_obstructed_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_versioned_obstructed_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_locked_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_locked_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_scheduled_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_scheduled_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_switched_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_switched_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_present_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_present_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_other_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_other_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_stolen_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_stolen_color\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_broken_display\fP
.IP \(bu 2
\fB__fish_svn_prompt_char_token_broken_color\fP
.UNINDENT
.sp
See also fish_vcs_prompt \%<>, which will call all supported version control prompt functions, including git, Mercurial and Subversion.
.SS Example
.sp
A simple prompt that displays svn info:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
...
printf \(aq%s %s$\(aq $PWD (fish_svn_prompt)
end
.EE
.UNINDENT
.UNINDENT
.SS fish_tab_title \- define the terminal tab\(aqs title
.SS Synopsis
.nf
\fBfish_title\fP
\fBfish_tab_title\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
...
end
function fish_tab_title
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_title\fP function is executed before and after a new command is executed or put into the foreground and the output is used as a titlebar message.
.sp
The first argument to \fBfish_title\fP contains the most recently executed foreground command as a string, if any.
.sp
This requires that your terminal supports programmable titles \%<#\:term-compat-osc-0> and the feature is turned on.
.sp
To disable setting the title, use an empty function (see below).
.sp
To set the terminal tab title to something other than the terminal window title,
define the \fBfish_tab_title\fP function, which works like \fBfish_title\fP but overrides that one.
.SS Example
.sp
A simple title:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
set \-q argv[1]; or set argv fish
# Looks like ~/d/fish: git log
# or /e/apt: fish
echo (fish_prompt_pwd_dir_length=1 prompt_pwd): $argv;
end
.EE
.UNINDENT
.UNINDENT
.sp
Do not change the title:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
end
.EE
.UNINDENT
.UNINDENT
.sp
Change the tab title only:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_tab_title
echo fish $fish_pid
end
.EE
.UNINDENT
.UNINDENT
.SS fish_title \- define the terminal\(aqs title
.SS Synopsis
.nf
\fBfish_title\fP
\fBfish_tab_title\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
...
end
function fish_tab_title
...
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_title\fP function is executed before and after a new command is executed or put into the foreground and the output is used as a titlebar message.
.sp
The first argument to \fBfish_title\fP contains the most recently executed foreground command as a string, if any.
.sp
This requires that your terminal supports programmable titles \%<#\:term-compat-osc-0> and the feature is turned on.
.sp
To disable setting the title, use an empty function (see below).
.sp
To set the terminal tab title to something other than the terminal window title,
define the \fBfish_tab_title\fP function, which works like \fBfish_title\fP but overrides that one.
.SS Example
.sp
A simple title:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
set \-q argv[1]; or set argv fish
# Looks like ~/d/fish: git log
# or /e/apt: fish
echo (fish_prompt_pwd_dir_length=1 prompt_pwd): $argv;
end
.EE
.UNINDENT
.UNINDENT
.sp
Do not change the title:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_title
end
.EE
.UNINDENT
.UNINDENT
.sp
Change the tab title only:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_tab_title
echo fish $fish_pid
end
.EE
.UNINDENT
.UNINDENT
.SS fish_update_completions \- update completions using manual pages
.SS Synopsis
.nf
\fBfish_update_completions\fP
.fi
.sp
.SS Description
.sp
\fBfish_update_completions\fP parses manual pages installed on the system, and attempts to create completion files in the \fBfish\fP configuration directory.
.sp
This does not overwrite custom completions.
.sp
There are no parameters for \fBfish_update_completions\fP\&.
.SS fish_vcs_prompt \- output version control system information for use in a prompt
.SS Synopsis
.nf
\fBfish_vcs_prompt\fP
.fi
.sp
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
printf \(aq%s\(aq $PWD (fish_vcs_prompt) \(aq $ \(aq
end
.EE
.UNINDENT
.UNINDENT
.SS Description
.sp
The \fBfish_vcs_prompt\fP function displays information about the current version control system (VCS) repository, if any.
.sp
It calls out to VCS\-specific functions. The currently supported systems are:
.INDENT 0.0
.IP \(bu 2
fish_git_prompt \%<>
.IP \(bu 2
fish_hg_prompt \%<>
.IP \(bu 2
fish_darcs_prompt \%<>
.IP \(bu 2
fish_svn_prompt \%<>
.UNINDENT
.sp
If a VCS isn\(aqt installed, the respective function does nothing.
.sp
The Subversion prompt is disabled by default, because it\(aqs slow on large repositories. To enable it, modify \fBfish_vcs_prompt\fP to uncomment it. See funced \%<>\&.
.sp
For more information, see the documentation for each of the functions above.
.SS Example
.sp
A simple prompt that displays all known VCS info:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
...
set \-g __fish_git_prompt_showupstream auto
printf \(aq%s %s$\(aq $PWD (fish_vcs_prompt)
end
.EE
.UNINDENT
.UNINDENT
.SS fish_vi_key_bindings \- set vi key bindings for fish
.SS Synopsis
.nf
\fBfish_vi_key_bindings\fP
\fBfish_vi_key_bindings\fP [\fB\-\-no\-erase\fP] [\fIINIT_MODE\fP]
.fi
.sp
.SS Description
.sp
\fBfish_vi_key_bindings\fP sets the vi key bindings for \fBfish\fP shell.
.sp
If a valid \fIINIT_MODE\fP is provided (insert, default, visual), then that mode will become the default
\&. If no \fIINIT_MODE\fP is given, the mode defaults to insert mode.
.sp
The following parameters are available:
.INDENT 0.0
.TP
\fB\-\-no\-erase\fP
Does not clear previous set bindings
.UNINDENT
.sp
Further information on how to use vi mode \%<#\:vi-mode>\&.
.SS Differences from Vim
.sp
fish\(aqs vi mode aims to be familiar to vim users, but there are some differences:
.INDENT 0.0
.TP
\fBWord character handling\fP
In vim, underscore (\fB_\fP) is treated as a keyword character by default, so word motions like \fBw\fP, \fBb\fP, and \fBe\fP treat \fBfoo_bar\fP as a single word. In fish, underscore is treated as punctuation, so word motions stop at underscores. For example, pressing \fBw\fP on \fBfoo_bar\fP in fish stops at the \fB_\fP, while in vim it would jump past the entire identifier.
.UNINDENT
.SS Examples
.sp
To start using vi key bindings:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_vi_key_bindings
.EE
.UNINDENT
.UNINDENT
.sp
or \fBset \-g fish_key_bindings fish_vi_key_bindings\fP in config.fish \%<#\:configuration>\&.
.SS for \- perform a set of commands multiple times
.SS Synopsis
.nf
\fBfor\fP \fIVARNAME\fP \fBin\fP [\fIVALUES\fP \&...]\fB;\fP \fICOMMANDS\fP \&...\fB;\fP \fBend\fP
.fi
.sp
.SS Description
.sp
\fBfor\fP is a loop construct. It will perform the commands specified by \fICOMMANDS\fP multiple times. On each iteration, the local variable specified by \fIVARNAME\fP is assigned a new value from \fIVALUES\fP\&. If \fIVALUES\fP is empty, \fICOMMANDS\fP will not be executed at all. The \fIVARNAME\fP is visible when the loop terminates and will contain the last value assigned to it. If \fIVARNAME\fP does not already exist it will be set in the local scope. For our purposes if the \fBfor\fP block is inside a function there must be a local variable with the same name. If the \fBfor\fP block is not nested inside a function then global and universal variables of the same name will be used if they exist.
.sp
Much like set \%<>, \fBfor\fP does not modify $status, but the evaluation of its subordinate commands can.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in foo bar baz; echo $i; end
# would output:
foo
bar
baz
.EE
.UNINDENT
.UNINDENT
.SS Notes
.sp
The \fBVARNAME\fP was local to the for block in releases prior to 3.0.0. This means that if you did something like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for var in a b c
if break_from_loop
break
end
end
echo $var
.EE
.UNINDENT
.UNINDENT
.sp
The last value assigned to \fBvar\fP when the loop terminated would not be available outside the loop. What \fBecho $var\fP would write depended on what it was set to before the loop was run. Likely nothing.
.SS funced \- edit a function interactively
.SS Synopsis
.nf
\fBfunced\fP [\fIOPTIONS\fP] \fINAME\fP
.fi
.sp
.SS Description
.sp
\fBfunced\fP provides an interface to edit the definition of the function \fINAME\fP\&.
.sp
If the \fB$VISUAL\fP environment variable is set, it will be used as the program to edit the function. If \fB$VISUAL\fP is unset but \fB$EDITOR\fP is set, that will be used. Otherwise, a built\-in editor will be used. Note that to enter a literal newline using the built\-in editor you should press \fBalt\fP\-\fBenter\fP\&. Pressing \fBenter\fP signals that you are done editing the function. This does not apply to an external editor like emacs or vim.
.sp
\fBfunced\fP will try to edit the original file that a function is defined in, which might include variable definitions or helper functions as well. If changes cannot be saved to the original file, a copy will be created in the user\(aqs function directory.
.sp
If there is no function called \fINAME\fP, a new function will be created with the specified name.
.INDENT 0.0
.TP
\fB\-e command\fP or \fB\-\-editor command\fP
Open the function body inside the text editor given by the command (for example, \fB\-e vi\fP). The special command \fBfish\fP will use the built\-in editor (same as specifying \fB\-i\fP).
.TP
\fB\-i\fP or \fB\-\-interactive\fP
Force opening the function body in the built\-in editor even if \fB$VISUAL\fP or \fB$EDITOR\fP is defined.
.TP
\fB\-s\fP or \fB\-\-save\fP
Automatically save the function after successfully editing it.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Example
.sp
Say you want to modify your prompt.
.sp
Run:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ funced fish_prompt
.EE
.UNINDENT
.UNINDENT
.sp
This will open up your editor, allowing you to modify the function. When you\(aqre done, save and quit. fish will reload the function, so you should see the changes right away.
.sp
When you\(aqre done, use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ funcsave fish_prompt
.EE
.UNINDENT
.UNINDENT
.sp
For more, see funcsave \%<>\&. To view a function\(aqs current definition, use functions \%<> or type \%<>\&.
.SS funcsave \- save the definition of a function to the user\(aqs autoload directory
.SS Synopsis
.nf
\fBfuncsave\fP \fIFUNCTION_NAME\fP
\fBfuncsave\fP [\fB\-q\fP | \fB\-\-quiet\fP] [(\fB\-d\fP | \fB\-\-directory\fP) \fIDIR\fP] \fIFUNCTION_NAME\fP
.fi
.sp
.SS Description
.sp
\fBfuncsave\fP saves a function to a file in the fish configuration directory. This function will be automatically loaded \%<#\:syntax-function-autoloading> by current and future fish sessions. This can be useful to commit functions created interactively for permanent use.
.sp
If you have erased a function using functions \%<>\(aqs \fB\-\-erase\fP option, \fBfuncsave\fP will remove the saved function definition.
.sp
Because fish loads functions on\-demand, saved functions cannot serve as event handlers \%<#\:event> until they are run or otherwise sourced. To activate an event handler for every new shell, add the function to the configuration file \%<#\:configuration> instead of using \fBfuncsave\fP\&.
.sp
This is often used after funced \%<>, which opens the function in \fB$EDITOR\fP or \fB$VISUAL\fP and loads it into the current session afterwards.
.sp
To view a function\(aqs current definition, use functions \%<> or type \%<>\&.
.SS function \- create a function
.SS Synopsis
.nf
\fBfunction\fP \fINAME\fP [\fIOPTIONS\fP]\fB;\fP \fIBODY\fP\fB;\fP \fBend\fP
.fi
.sp
.SS Description
.sp
\fBfunction\fP creates a new function \fINAME\fP with the body \fIBODY\fP\&.
.sp
A function is a list of commands that will be executed when the name of the function is given as a command.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-a\fP \fINAMES\fP or \fB\-\-argument\-names\fP \fINAMES\fP
Assigns the value of successive command\-line arguments to the names given in \fINAMES\fP (separated by spaces). These are the same arguments given in \fBargv\fP \%<#\:envvar-argv>, and are still available there (unless \fB\-\-inherit\-variable argv\fP was used or one of the given \fINAMES\fP is \fBargv\fP). See also Argument Handling \%<#\:variables-argv>\&.
.TP
\fB\-d\fP \fIDESCRIPTION\fP or \fB\-\-description\fP \fIDESCRIPTION\fP
A description of what the function does, suitable as a completion description.
.TP
\fB\-w\fP \fIWRAPPED_COMMAND\fP or \fB\-\-wraps\fP \fIWRAPPED_COMMAND\fP
Inherit completions from the given \fIWRAPPED_COMMAND\fP\&.
This is used to say that this function completes like that command,
for example if you\(aqre creating an alias.
See the documentation for complete \%<> for more information.
If the wrapped command is the same as the function name, this will be ignored.
.TP
\fB\-e\fP \fIEVENT_NAME\fP or \fB\-\-on\-event\fP \fIEVENT_NAME\fP
Run this function when the specified named event is emitted. fish internally generates named events, for example, when showing the prompt. Custom events can be emitted using the emit \%<> command.
.TP
\fB\-v\fP \fIVARIABLE_NAME\fP or \fB\-\-on\-variable\fP \fIVARIABLE_NAME\fP
Run this function when the variable \fIVARIABLE_NAME\fP changes value. Note that \fBfish\fP makes no guarantees on any particular timing or even that the function will be run for every single \fBset\fP\&. Rather it will be run when the variable has been set at least once, possibly skipping some values or being run when the variable has been set to the same value (except for universal variables set in other shells \- only changes in the value will be picked up for those).
.TP
\fB\-j\fP \fIPID\fP or \fB\-\-on\-job\-exit\fP \fIPID\fP
Run this function when the job containing a child process with the given process ID \fIPID\fP exits. Instead of a PID, the string \(aqcaller\(aq can be specified. This is only allowed when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.
This will not trigger for disowned \%<> jobs.
.TP
\fB\-p\fP \fIPID\fP or \fB\-\-on\-process\-exit\fP \fIPID\fP
Run this function when the fish child process with process ID PID exits. Instead of a PID, for backward compatibility, \(dq\fB%self\fP\(dq can be specified as an alias for \fB$fish_pid\fP, and the function will be run when the current fish instance exits.
This will not trigger for disowned \%<> jobs.
.TP
\fB\-s\fP \fISIGSPEC\fP or \fB\-\-on\-signal\fP \fISIGSPEC\fP
Run this function when the signal \fBSIGSPEC\fP is delivered. \fBSIGSPEC\fP can be a signal number, or the signal name, such as \fBSIGHUP\fP (or just \fBHUP\fP). Note that the signal must have been delivered to \fBfish\fP; for example, \fBctrl\fP\-\fBc\fP sends \fBSIGINT\fP to the foreground process group, which will not be \fBfish\fP if you are running another command at the time. Observing a signal will prevent fish from exiting in response to that signal.
.TP
\fB\-S\fP or \fB\-\-no\-scope\-shadowing\fP
Allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are \(dqshadowed\(dq, and their contents are independent of the calling function.
.sp
It\(aqs important to note that this does not capture referenced variables or the scope at the time of function declaration! At this time, fish does not have any concept of closures, and variable lifetimes are never extended. In other words, by using \fB\-\-no\-scope\-shadowing\fP the scope of the function each time it is run is shared with the scope it was \fIcalled\fP from rather than the scope it was \fIdefined\fP in.
.TP
\fB\-V\fP or \fB\-\-inherit\-variable NAME\fP
Snapshots the value of the variable \fBNAME\fP and defines a local variable with that same name and value when the function is defined. This is similar to a closure in other languages like Python but a bit different. Note the word \(dqsnapshot\(dq in the first sentence. If you change the value of the variable after defining the function, even if you do so in the same scope (typically another function) the new value will not be used by the function you just created using this option. See the \fBfunction notify\fP example below for how this might be used.
.UNINDENT
.sp
The event handler switches (\fBon\-event\fP, \fBon\-variable\fP, \fBon\-job\-exit\fP, \fBon\-process\-exit\fP and \fBon\-signal\fP) cause a function to run automatically at specific events. New named events for \fB\-\-on\-event\fP can be fired using the emit \%<> builtin. fish already generates a few events, see Event handlers \%<#\:event> for more.
.sp
Functions names cannot be reserved words. These are elements of fish syntax or builtin commands which are essential for the operations of the shell. Current reserved words are \fB[\fP, \fB_\fP, \fBand\fP, \fBargparse\fP, \fBbegin\fP, \fBbreak\fP, \fBbuiltin\fP, \fBcase\fP, \fBcommand\fP, \fBcontinue\fP, \fBelse\fP, \fBend\fP, \fBeval\fP, \fBexec\fP, \fBfor\fP, \fBfunction\fP, \fBif\fP, \fBnot\fP, \fBor\fP, \fBread\fP, \fBreturn\fP, \fBset\fP, \fBstatus\fP, \fBstring\fP, \fBswitch\fP, \fBtest\fP, \fBtime\fP, and \fBwhile\fP\&.
.sp
Care should be taken when creating a function of the same name as an existing shell builtin or common program. If the function behaves differently, it is very common for problems to occur within fish or in scripts written by others. Consider writing an abbreviation \%<> if you are wanting to replace one tool with another for interactive use.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function ll
ls \-l $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
will run the \fBls\fP command, using the \fB\-l\fP option, while passing on any additional files and switches to \fBls\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function debug \-a name val
echo [DEBUG] $name: $val >&2
end
set foo bar
debug foo bar
# prints: [DEBUG] foo: bar
# OR
function debug2 \-a var
echo [DEBUG] $var: $$var >&2
end
set foo bar
debug2 foo
# prints: [DEBUG] foo: bar
.EE
.UNINDENT
.UNINDENT
.sp
will create a \fBdebug\fP command to print chosen variables to \fIstderr\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function mkdir \-d \(dqCreate a directory and set CWD\(dq
command mkdir $argv
if test $status = 0
switch $argv[(count $argv)]
case \(aq\-*\(aq
case \(aq*\(aq
cd $argv[(count $argv)]
return
end
end
end
.EE
.UNINDENT
.UNINDENT
.sp
This will run the \fBmkdir\fP command, and if it is successful, change the current working directory to the one just created.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function notify
set \-l job (jobs \-l \-g)
or begin; echo \(dqThere are no jobs\(dq >&2; return 1; end
function _notify_job_$job \-\-on\-job\-exit $job \-\-inherit\-variable job
echo \-n \ea # beep
functions \-e _notify_job_$job
end
end
.EE
.UNINDENT
.UNINDENT
.sp
This will beep when the most recent job completes.
.SS Notes
.sp
Events are only received from the current fish process as there is no way to send events from one fish process to another.
.SS See more
.sp
For more explanation of how functions fit into fish, see Functions \%<#\:syntax-function>\&.
.SS functions \- print or erase functions
.SS Synopsis
.nf
\fBfunctions\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-n\fP | \fB\-\-names\fP] [\fB\-\-color\fP \fIWHEN\fP]
\fBfunctions\fP [\fB\-D\fP | \fB\-\-details\fP] [\fB\-v\fP] [\fB\-\-color\fP \fIWHEN\fP] \fIFUNCTION\fP
\fBfunctions\fP \fB\-c\fP \fIOLDNAME\fP \fINEWNAME\fP
\fBfunctions\fP \fB\-d\fP \fIDESCRIPTION\fP \fIFUNCTION\fP
\fBfunctions\fP [\fB\-e\fP | \fB\-q\fP] \fIFUNCTION\fP \&...
.fi
.sp
.SS Description
.sp
\fBfunctions\fP prints or erases functions.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-all\fP
Lists all functions, even those whose name starts with an underscore.
.TP
\fB\-c\fP or \fB\-\-copy\fP \fIOLDNAME\fP \fINEWNAME\fP
Creates a new function named \fINEWNAME\fP, using the definition of the \fIOLDNAME\fP function.
.TP
\fB\-d\fP or \fB\-\-description\fP \fIDESCRIPTION\fP
Changes the description of this function.
.TP
\fB\-e\fP or \fB\-\-erase\fP
Causes the specified functions to be erased. This also means that it is prevented from autoloading in the current session. Use funcsave \%<> to remove the saved copy.
.TP
\fB\-D\fP or \fB\-\-details\fP
Reports the path name where the specified function is defined or could be autoloaded, \fBstdin\fP if the function was defined interactively or on the command line or by reading standard input, \fB\-\fP if the function was created via source \%<>, and \fBn/a\fP if the function isn\(aqt available. (Functions created via alias \%<> will return \fB\-\fP, because \fBalias\fP uses \fBsource\fP internally. Copied functions will return where the function was copied.) If the \fB\-\-verbose\fP option is also specified then five lines are written:
.INDENT 7.0
.IP \(bu 2
the path name as already described,
.IP \(bu 2
if the function was copied, the path name to where the function was originally defined, otherwise \fBautoloaded\fP, \fBnot\-autoloaded\fP or \fBn/a\fP,
.IP \(bu 2
the line number within the file or zero if not applicable,
.IP \(bu 2
\fBscope\-shadowing\fP if the function shadows the vars in the calling function (the normal case if it wasn\(aqt defined with \fB\-\-no\-scope\-shadowing\fP), else \fBno\-scope\-shadowing\fP, or \fBn/a\fP if the function isn\(aqt defined,
.IP \(bu 2
the function description minimally escaped so it is a single line, or \fBn/a\fP if the function isn\(aqt defined or has no description.
.UNINDENT
.sp
You should not assume that only five lines will be written since we may add additional information to the output in the future.
.TP
\fB\-\-no\-details\fP
Turns off function path reporting, so just the definition will be printed.
.TP
\fB\-n\fP or \fB\-\-names\fP
Lists the names of all defined functions.
.TP
\fB\-q\fP or \fB\-\-query\fP
Tests if the specified functions exist.
.TP
\fB\-v\fP or \fB\-\-verbose\fP
Make some output more verbose.
.TP
\fB\-H\fP or \fB\-\-handlers\fP
Show all event handlers.
.TP
\fB\-t\fP or \fB\-\-handlers\-type\fP \fITYPE\fP
Show all event handlers matching the given \fITYPE\fP\&.
.TP
\fB\-\-color\fP \fIWHEN\fP
Controls when to use syntax highlighting colors when printing function definitions.
\fIWHEN\fP can be \fBauto\fP (the default, colorize if the output is a terminal \%<>), \fBalways\fP, or \fBnever\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
The default behavior of \fBfunctions\fP, when called with no arguments, is to print the names of all defined functions. Unless the \fB\-a\fP option is given, no functions starting with underscores are included in the output.
.sp
If any non\-option parameters are given, the definition of the specified functions are printed.
.sp
Copying a function using \fB\-c\fP copies only the body of the function, and does not attach any event notifications from the original function.
.sp
Only one function\(aqs description can be changed in a single invocation of \fBfunctions \-d\fP\&.
.sp
The exit status of \fBfunctions\fP is the number of functions specified in the argument list that do not exist, which can be used in concert with the \fB\-q\fP option.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
functions \-n
# Displays a list of currently\-defined functions
functions \-c foo bar
# Copies the \(aqfoo\(aq function to a new function called \(aqbar\(aq
functions \-e bar
# Erases the function \(ga\(gabar\(ga\(ga
.EE
.UNINDENT
.UNINDENT
.SS See more
.sp
For more explanation of how functions fit into fish, see Functions \%<#\:syntax-function>\&.
.SS help \- display fish documentation
.SS Synopsis
.nf
\fBhelp\fP [\fISECTION\fP]
.fi
.sp
.SS Description
.sp
\fBhelp\fP displays the fish help documentation.
.sp
If a \fISECTION\fP is specified, the help for that command is shown.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.sp
If the \fBBROWSER\fP \%<#\:envvar-BROWSER> environment variable is set, it will be used to display the documentation.
Otherwise, fish will search for a suitable browser.
To use a different browser than as described above, you can set \fB$fish_help_browser\fP
This variable may be set as a list, where the first element is the browser command and the rest are browser options.
.SS Example
.sp
\fBhelp fg\fP shows the documentation for the fg \%<> builtin.
.SS Notes
.sp
Most builtin commands, including this one, display their help in the terminal when given the \fB\-\-help\fP option.
.SS history \- show and manipulate command history
.SS Synopsis
.nf
\fBhistory\fP [\fBsearch\fP] [\fB\-\-show\-time\fP] [\fB\-\-case\-sensitive\fP]
[\fB\-\-exact\fP | \fB\-\-prefix\fP | \fB\-\-contains\fP] [\fB\-\-max\fP \fIN\fP] [\fB\-\-null\fP] [\fB\-\-reverse\fP]
[\fISEARCH_STRING\fP \&...]
\fBhistory\fP \fBdelete\fP [\fB\-\-case\-sensitive\fP]
[\fB\-\-exact\fP | \fB\-\-prefix\fP | \fB\-\-contains\fP] \fISEARCH_STRING\fP \&...
\fBhistory\fP \fBmerge\fP
\fBhistory\fP \fBsave\fP
\fBhistory\fP \fBclear\fP
\fBhistory\fP \fBclear\-session\fP
\fBhistory\fP \fBappend\fP \fICOMMAND\fP \&...
.fi
.sp
.SS Description
.sp
\fBhistory\fP is used to search, delete, and otherwise manipulate the history of interactive commands \%<#\:history-search>\&.
.sp
The following operations (sub\-commands) are available:
.INDENT 0.0
.TP
\fBsearch\fP
Returns history items matching the search string. If no search string is provided it returns all history items. This is the default operation if no other operation is specified. You only have to explicitly say \fBhistory search\fP if you wish to search for one of the subcommands. The \fB\-\-contains\fP search option will be used if you don\(aqt specify a different search option. Entries are ordered newest to oldest unless you use the \fB\-\-reverse\fP flag. If stdout is attached to a tty the output will be piped through your pager by the history function. The history builtin writes the results to stdout.
.TP
\fBdelete\fP
Deletes history items. The \fB\-\-contains\fP search option will be used if you don\(aqt specify a different search option. If you don\(aqt specify \fB\-\-exact\fP a prompt will be displayed before any items are deleted asking you which entries are to be deleted. You can enter the word \(dqall\(dq to delete all matching entries. You can enter a single ID (the number in square brackets) to delete just that single entry. You can enter more than one ID, or an ID range separated by a space to delete multiple entries. Press [enter] to not delete anything. Note that the interactive delete behavior is a feature of the history function. The history builtin only supports \fB\-\-exact \-\-case\-sensitive\fP deletion.
.TP
\fBmerge\fP
Immediately incorporates history changes from other sessions. Ordinarily \fBfish\fP ignores history changes from sessions started after the current one. This command applies those changes immediately.
.TP
\fBsave\fP
Immediately writes all changes to the history file. The shell automatically saves the history file; this option is provided for internal use and should not normally need to be used by the user.
.TP
\fBclear\fP
Clears the history file. A prompt is displayed before the history is erased asking you to confirm you really want to clear all history unless \fBbuiltin history\fP is used.
.TP
\fBclear\-session\fP
Clears the history file from all activity of the current session. Note: If \fBhistory merge\fP or \fBbuiltin history merge\fP is run in a session, only the history after this will be erased.
.TP
\fBappend\fP
Appends commands to the history without needing to execute them.
.UNINDENT
.sp
The following options are available:
.sp
These flags can appear before or immediately after one of the sub\-commands listed above.
.INDENT 0.0
.TP
\fB\-C\fP or \fB\-\-case\-sensitive\fP
Does a case\-sensitive search. The default is case\-insensitive.
.TP
\fB\-c\fP or \fB\-\-contains\fP
Searches items in the history that contain the specified text string. This is the default for the \fB\-\-search\fP flag. This is not currently supported by the \fBdelete\fP subcommand.
.TP
\fB\-e\fP or \fB\-\-exact\fP
Searches or deletes items in the history that exactly match the specified text string. This is the default for the \fBdelete\fP subcommand. Note that the match is case\-insensitive by default. If you really want an exact match, including letter case, you must use the \fB\-C\fP or \fB\-\-case\-sensitive\fP flag.
.TP
\fB\-p\fP or \fB\-\-prefix\fP
Searches items in the history that begin with the specified text string. This is not currently supported by the \fBdelete\fP subcommand.
.UNINDENT
.INDENT 0.0
.TP
\fB\-t\fP or \fB\-\-show\-time\fP
Prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format \fB# %c%n\fP\&. You can specify another format; e.g., \fB\-\-show\-time=\(dq%Y\-%m\-%d %H:%M:%S \(dq\fP or \fB\-\-show\-time=\(dq%a%I%p\(dq\fP\&. The short option, \fB\-t\fP, doesn\(aqt accept a strftime format string; it only uses the default format. Any strftime format is allowed, including \fB%s\fP to get the raw UNIX seconds since the epoch.
.TP
\fB\-z\fP or \fB\-\-null\fP
Causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by \fBread \-z\fP to correctly handle multiline history entries.
.TP
\fB\-\fP*NUMBER* \fB\-n\fP \fINUMBER\fP or \fB\-\-max\fP \fINUMBER\fP
Limits the matched history items to the first \fINUMBER\fP matching entries. This is only valid for \fBhistory search\fP\&.
.TP
\fB\-R\fP or \fB\-\-reverse\fP
Causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest.
.TP
\fB\-\-color\fP \fIWHEN\fP
Controls when to use syntax highlighting colors for the history entries.
\fIWHEN\fP can be \fBauto\fP (the default, colorize if the output is a terminal \%<>), \fBalways\fP, or \fBnever\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help for this command.
.UNINDENT
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
history clear
# Deletes all history items
history search \-\-contains \(dqfoo\(dq
# Outputs a list of all previous commands containing the string \(dqfoo\(dq.
history delete \-\-prefix \(dqfoo\(dq
# Interactively deletes commands which start with \(dqfoo\(dq from the history.
# You can select more than one entry by entering their IDs separated by a space.
.EE
.UNINDENT
.UNINDENT
.SS Customizing the name of the history file
.sp
By default interactive commands are logged to \fB$XDG_DATA_HOME/fish/fish_history\fP (typically \fB~/.local/share/fish/fish_history\fP).
.sp
You can set the \fBfish_history\fP variable to another name for the current shell session. The default value (when the variable is unset) is \fBfish\fP which corresponds to \fB$XDG_DATA_HOME/fish/fish_history\fP\&. If you set it to e.g. \fBfun\fP, the history would be written to \fB$XDG_DATA_HOME/fish/fun_history\fP\&. An empty string means history will not be stored at all. This is similar to the private session features in web browsers.
.sp
You can change \fBfish_history\fP at any time (by using \fBset \-x fish_history \(dqsession_name\(dq\fP) and it will take effect right away. If you set it to \fB\(dqdefault\(dq\fP, it will use the default session name (which is \fB\(dqfish\(dq\fP).
.sp
Other shells such as bash and zsh use a variable named \fBHISTFILE\fP for a similar purpose. fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than \fBfish\fP or \fBdefault\fP it will inhibit importing the bash history. That\(aqs because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation.
.SS Notes
.sp
If you specify both \fB\-\-prefix\fP and \fB\-\-contains\fP the last flag seen is used.
.sp
Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than \fBhistory search\fP you can type \fBhistory \-\-search\fP\&. Those long options are deprecated and will be removed in a future release.
.SS if \- conditionally execute a command
.SS Synopsis
.nf
\fBif\fP \fICONDITION\fP\fB;\fP \fICOMMANDS_TRUE\fP \&...\fB;\fP
[\fBelse\fP \fBif\fP \fICONDITION2\fP\fB;\fP \fICOMMANDS_TRUE2\fP \&...\fB;\fP]
[\fBelse\fP\fB;\fP \fICOMMANDS_FALSE\fP \&...\fB;\fP]
\fBend\fP
.fi
.sp
.SS Description
.sp
\fBif\fP will execute the command \fBCONDITION\fP\&. If the condition\(aqs exit status is 0, the commands \fBCOMMANDS_TRUE\fP will execute. If the exit status is not 0 and else \%<> is given, \fBCOMMANDS_FALSE\fP will be executed.
.sp
You can use not \%<>, and \%<> or or \%<> in the condition. See the second example below.
.sp
The exit status of the last foreground command to exit can always be accessed using the $status \%<#\:variables-status> variable.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code will print \fBfoo.txt exists\fP if the file foo.txt exists and is a regular file, otherwise it will print \fBbar.txt exists\fP if the file bar.txt exists and is a regular file, otherwise it will print \fBfoo.txt and bar.txt do not exist\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-f foo.txt
echo foo.txt exists
else if test \-f bar.txt
echo bar.txt exists
else
echo foo.txt and bar.txt do not exist
end
.EE
.UNINDENT
.UNINDENT
.sp
The following code will print \(dqfoo.txt exists and is readable\(dq if foo.txt is a regular file and readable
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-f foo.txt
and test \-r foo.txt
echo \(dqfoo.txt exists and is readable\(dq
end
.EE
.UNINDENT
.UNINDENT
.SS See also
.sp
\fBif\fP is only as useful as the command used as the condition.
.sp
fish ships a few:
.INDENT 0.0
.IP \(bu 2
test \- perform tests on files and text \%<> can compare numbers, strings and check paths
.IP \(bu 2
string \- manipulate strings \%<> can perform string operations including wildcard and regular expression matches
.IP \(bu 2
path \- manipulate and check paths \%<> can check paths for permissions, existence or type
.IP \(bu 2
contains \- test if a word is present in a list \%<> can check if an element is in a list
.UNINDENT
.SS isatty \- test if a file descriptor is a terminal
.SS Synopsis
.nf
\fBisatty\fP [\fIFILE_DESCRIPTOR\fP]
.fi
.sp
.SS Description
.sp
\fBisatty\fP tests if a file descriptor is a terminal (as opposed to a file). The name is derived from the system call of the same name, which for historical reasons refers to a teletypewriter (TTY).
.sp
\fBFILE DESCRIPTOR\fP may be either the number of a file descriptor, or one of the strings \fBstdin\fP, \fBstdout\fP, or \fBstderr\fP\&. If not specified, zero is assumed.
.sp
If the specified file descriptor is a terminal device, the exit status of the command is zero. Otherwise, the exit status is non\-zero. No messages are printed to standard error.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Examples
.sp
From an interactive shell, the commands below exit with a return value of zero:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
isatty
isatty stdout
isatty 2
echo | isatty 1
.EE
.UNINDENT
.UNINDENT
.sp
And these will exit non\-zero:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo | isatty
isatty 9
isatty stdout > file
isatty 2 2> file
.EE
.UNINDENT
.UNINDENT
.SS jobs \- print currently running jobs
.SS Synopsis
.nf
\fBjobs\fP [\fIOPTIONS\fP] [\fIPID\fP | \fB%\fP\fIJOBID\fP]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBjobs\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man jobs\fP\&.
.sp
\fBjobs\fP prints a list of the currently running jobs \%<#\:syntax-job-control> and their status.
.sp
\fBjobs\fP accepts the following options:
.INDENT 0.0
.TP
\fB\-c\fP or \fB\-\-command\fP
Prints the command name for each process in jobs.
.TP
\fB\-g\fP or \fB\-\-group\fP
Only prints the group ID of each job.
.TP
\fB\-l\fP or \fB\-\-last\fP
Prints only the last job to be started.
.TP
\fB\-p\fP or \fB\-\-pid\fP
Prints the process ID for each process in all jobs.
.TP
\fB\-q\fP or \fB\-\-query\fP
Prints no output for evaluation of jobs by exit status only. For compatibility with old fish versions this is also \fB\-\-quiet\fP (but this is deprecated).
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
On systems that support this feature, jobs will print the CPU usage of each job since the last command was executed. The CPU usage is expressed as a percentage of full CPU activity. Note that on multiprocessor systems, the total activity may be more than 100%.
.sp
Arguments of the form \fIPID\fP or \fI%JOBID\fP restrict the output to jobs with the selected process identifiers or job numbers respectively.
.sp
If the output of \fBjobs\fP is redirected or if it is part of a command substitution, the column header that is usually printed is omitted, making it easier to parse.
.sp
The exit status of \fBjobs\fP is \fB0\fP if there are running background jobs and \fB1\fP otherwise.
.SS Example
.sp
\fBjobs\fP outputs a summary of the current jobs, such as two long\-running tasks in this example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
Job Group State Command
2 26012 running nc \-l 55232 < /dev/random &
1 26011 running python tests/test_11.py &
.EE
.UNINDENT
.UNINDENT
.SS math \- perform mathematics calculations
.SS Synopsis
.nf
\fBmath\fP [(\fB\-s\fP | \fB\-\-scale\fP) \fIN\fP] [(\fB\-b\fP | \fB\-\-base\fP) \fIBASE\fP] [(\fB\-m\fP | \fB\-\-scale\-mode\fP) \fIMODE\fP] \fIEXPRESSION\fP \&...
.fi
.sp
.SS Description
.sp
\fBmath\fP performs mathematical calculations.
It supports simple operations such as addition, subtraction, and so on, as well as functions like \fBabs()\fP, \fBsqrt()\fP and \fBln()\fP\&.
.sp
By default, the output shows up to 6 decimal places.
To change the number of decimal places, use the \fB\-\-scale\fP option, including \fB\-\-scale=0\fP for integer output.
.sp
Keep in mind that parameter expansion happens before expressions are evaluated.
This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis (\fB()\fP) and the asterisk (\fB*\fP) glob character have to be escaped or quoted.
\fBx\fP can also be used to denote multiplication, but it needs to be followed by whitespace to distinguish it from hexadecimal numbers.
.sp
Parentheses for functions are optional \- \fBmath sin pi\fP prints \fB0\fP\&.
However, a comma will bind to the inner function, so \fBmath pow sin 3, 5\fP is an error because it tries to give \fBsin\fP the arguments \fB3\fP and \fB5\fP\&.
When in doubt, use parentheses.
.sp
\fBmath\fP ignores whitespace between arguments and takes its input as multiple arguments (internally joined with a space), so \fBmath 2 +2\fP and \fBmath \(dq2 + 2\(dq\fP work the same.
\fBmath 2 2\fP is an error.
.sp
\fBNote:\fP
.INDENT 0.0
.INDENT 3.5
math is a simple tool for simple uses, provided for convenience. It internally works with floats for simplicity of implementation and can\(aqt do a number of things real calculators can.
If you find yourself limited by that, use a more full\-featured tool.
.UNINDENT
.UNINDENT
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-s\fP \fIN\fP or \fB\-\-scale\fP \fIN\fP
Sets the scale of the result.
\fBN\fP must be an integer or the word \(dqmax\(dq for the maximum scale.
A scale of zero causes results to be truncated by default. Any non\-integer component is thrown away.
So \fB3/2\fP returns \fB1\fP by default, rather than \fB2\fP which \fB1.5\fP would normally round to.
This is for compatibility with \fBbc\fP which was the basis for this command prior to fish 3.0.0.
Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places.
.TP
\fB\-b\fP \fIBASE\fP or \fB\-\-base\fP \fIBASE\fP
Sets the numeric base used for output (\fBmath\fP always understands hexadecimal numbers as input).
It currently understands \(dqhex\(dq or \(dq16\(dq for hexadecimal and \(dqoctal\(dq or \(dq8\(dq for octal and implies a scale of 0 (other scales cause an error), so it will truncate the result down to an integer.
This might change in the future.
Hex numbers will be printed with a \fB0x\fP prefix.
Octal numbers will have a prefix of \fB0\fP but aren\(aqt understood by \fBmath\fP as input.
.TP
\fB\-m\fP \fIMODE\fP or \fB\-\-scale\-mode\fP \fIMODE\fP
Sets scale behavior.
The \fBMODE\fP can be \fBtruncate\fP, \fBround\fP, \fBfloor\fP, \fBceiling\fP\&.
The default value of scale mode is \fBround\fP with non zero scale and \fBtruncate\fP with zero scale.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Return Values
.sp
If the expression is successfully evaluated and doesn\(aqt over/underflow or return NaN the return \fBstatus\fP is zero (success) else one.
.SS Syntax
.sp
\fBmath\fP knows some operators, constants, functions and can (obviously) read numbers.
.sp
For numbers, \fB\&.\fP is always the radix character regardless of locale \- \fB2.5\fP, not \fB2,5\fP\&.
Scientific notation (\fB10e5\fP) and hexadecimal (\fB0xFF\fP) are also available.
.sp
\fBmath\fP allows you to use underscores as visual separators for digit grouping. For example, you can write \fB1_000_000\fP, \fB0x_89_AB_CD_EF\fP, and \fB1.234_567_e89\fP\&.
.SS Operators
.sp
\fBmath\fP knows the following operators:
.INDENT 0.0
.TP
.B \fB+\fP
for addition
.TP
.B \fB\-\fP
for subtraction
.TP
.B \fB*\fP or \fBx\fP
for multiplication. \fB*\fP is the glob character and needs to be quoted or escaped, \fBx\fP needs to be followed by whitespace or it looks like \fB0x\fP hexadecimal notation.
.TP
.B \fB/\fP
for division
.TP
.B \fB^\fP
for exponentiation
.TP
.B \fB%\fP
for modulo
.TP
.B \fB(\fP or \fB)\fP
for grouping. These need to be quoted or escaped because \fB()\fP denotes a command substitution.
.UNINDENT
.sp
They are all used in an infix manner \- \fB5 + 2\fP, not \fB+ 5 2\fP\&.
.SS Constants
.sp
\fBmath\fP knows the following constants:
.INDENT 0.0
.TP
.B \fBe\fP
Euler\(aqs number
.TP
.B \fBpi\fP
π, you know this one.
Half of Tau
.TP
.B \fBtau\fP
Equivalent to 2π, or the number of radians in a circle
.UNINDENT
.sp
Use them without a leading \fB$\fP \- \fBpi \- 3\fP should be about 0.
.SS Functions
.sp
\fBmath\fP supports the following functions:
.INDENT 0.0
.TP
.B \fBabs\fP
the absolute value, with positive sign
.TP
.B \fBacos\fP
arc cosine
.TP
.B \fBasin\fP
arc sine
.TP
.B \fBatan\fP
arc tangent
.TP
.B \fBatan2\fP
arc tangent of two variables
.TP
.B \fBbitand\fP, \fBbitor\fP and \fBbitxor\fP
perform bitwise operations.
These will throw away any non\-integer parts and interpret the rest as an int.
.sp
Note: \fBbitnot\fP and \fBbitnand\fP don\(aqt exist. This is because numbers in math don\(aqt really have a \fIwidth\fP in terms of bits,
and these operations necessarily care about leading zeroes.
.sp
If you need to negate a specific number you can do it with an xor with a mask, e.g.:
.INDENT 7.0
.INDENT 3.5
.sp
.EX
> math \-\-base=hex bitxor 0x0F, 0xFF
0xF0
> math \-\-base=hex bitxor 0x2, 0x3
# Here we mask with 0x3 == 0b111, so our number is 3 bits wide
# Only the 1 bit isn\(aqt set.
0x1
.EE
.UNINDENT
.UNINDENT
.TP
.B \fBceil\fP
round number up to the nearest integer
.TP
.B \fBcos\fP
the cosine
.TP
.B \fBcosh\fP
hyperbolic cosine
.TP
.B \fBexp\fP
the base\-e exponential function
.TP
.B \fBfac\fP
factorial \- also known as \fBx!\fP (\fBx * (x \- 1) * (x \- 2) * ... * 1\fP)
.TP
.B \fBfloor\fP
round number down to the nearest integer
.TP
.B \fBln\fP
the base\-e logarithm
.TP
.B \fBlog\fP or \fBlog10\fP
the base\-10 logarithm. To compute the logarithm for an arbitrary base \fBb\fP, use \fBlog(x) / log(b)\fP\&.
.TP
.B \fBlog2\fP
the base\-2 logarithm
.TP
.B \fBmax\fP
returns the largest of the given numbers \- this takes an arbitrary number of arguments (but at least one)
.TP
.B \fBmin\fP
returns the smallest of the given numbers \- this takes an arbitrary number of arguments (but at least one)
.TP
.B \fBncr\fP
\(dqfrom n choose r\(dq combination function \- how many subsets of size r can be taken from n (order doesn\(aqt matter)
.TP
.B \fBnpr\fP
the number of subsets of size r that can be taken from a set of n elements (including different order)
.TP
.B \fBpow(x,y)\fP
returns x to the y (and can be written as \fBx ^ y\fP)
.TP
.B \fBround\fP
rounds to the nearest integer, away from 0
.TP
.B \fBsin\fP
the sine function
.TP
.B \fBsinh\fP
the hyperbolic sine
.TP
.B \fBsqrt\fP
the square root \- (can also be written as \fBx ^ 0.5\fP)
.TP
.B \fBtan\fP
the tangent
.TP
.B \fBtanh\fP
the hyperbolic tangent
.UNINDENT
.sp
All of the trigonometric functions use radians (the pi\-based scale, not 360°).
.SS Examples
.sp
\fBmath 1+1\fP outputs 2.
.sp
\fBmath $status \- 128\fP outputs the numerical exit status of the last command minus 128.
.sp
\fBmath 10 / 6\fP outputs \fB1.666667\fP\&.
.sp
\fBmath \-s0 10.0 / 6.0\fP outputs \fB1\fP\&.
.sp
\fBmath \-s3 10 / 6\fP outputs \fB1.667\fP\&.
.sp
\fBmath \(dqsin(pi)\(dq\fP outputs \fB0\fP\&.
.sp
\fBmath 5 \e* 2\fP or \fBmath \(dq5 * 2\(dq\fP or \fBmath 5 \(dq*\(dq 2\fP all output \fB10\fP\&.
.sp
\fBmath 0xFF\fP outputs 255, \fBmath 0 x 3\fP outputs 0 (because it computes 0 multiplied by 3).
.sp
\fBmath bitand 0xFE, 0x2e\fP outputs 46.
.sp
\fBmath \(dqbitor(9,2)\(dq\fP outputs 11.
.sp
\fBmath \-\-base=hex 192\fP prints \fB0xc0\fP\&.
.sp
\fBmath \(aqncr(49,6)\(aq\fP prints 13983816 \- that\(aqs the number of possible picks in 6\-from\-49 lotto.
.sp
\fBmath max 5,2,3,1\fP prints 5.
.SS Compatibility notes
.sp
fish 1.x and 2.x releases relied on the \fBbc\fP command for handling \fBmath\fP expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands.
.sp
You don\(aqt need to use \fB\-\-\fP before the expression, even if it begins with a minus sign which might otherwise be interpreted as an invalid option. If you do insert \fB\-\-\fP before the expression, it will cause option scanning to stop just like for every other command and it won\(aqt be part of the expression.
.SS nextd \- move forward through directory history
.SS Synopsis
.nf
\fBnextd\fP [\fB\-l\fP | \fB\-\-list\fP] [\fIPOS\fP]
.fi
.sp
.SS Description
.sp
\fBnextd\fP moves forwards \fIPOS\fP positions in the history of visited directories \%<#\:directory-history>; if the end of the history has been hit, a warning is printed.
.sp
If the \fB\-l\fP or \fB\-\-list\fP option is specified, the current directory history is also displayed.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.sp
Note that the \fBcd\fP command limits directory history to the 25 most recently visited directories. The history is stored in the \fBdirprev\fP and \fBdirnext\fP variables which this command manipulates.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cd /usr/src
# Working directory is now /usr/src
cd /usr/src/fish\-shell
# Working directory is now /usr/src/fish\-shell
prevd
# Working directory is now /usr/src
nextd
# Working directory is now /usr/src/fish\-shell
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the cdh \%<> command to display a prompt to quickly navigate the history
.IP \(bu 2
the dirh \%<> command to print the directory history
.IP \(bu 2
the prevd \%<> command to move backward
.UNINDENT
.SS not \- negate the exit status of a job
.SS Synopsis
.nf
\fBnot\fP \fICOMMAND\fP [\fIOPTIONS\fP \&...]
\fB! \fP\fICOMMAND\fP [\fIOPTIONS\fP \&...]
.fi
.sp
.SS Description
.sp
\fBnot\fP negates the exit status of another command. If the exit status is zero, \fBnot\fP returns 1. Otherwise, \fBnot\fP returns 0.
.sp
Some other shells only support the \fB!\fP alias.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code reports an error and exits if no file named spoon can be found.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if not test \-f spoon
echo There is no spoon
exit 1
end
.EE
.UNINDENT
.UNINDENT
.SS open \- open file in its default application
.SS Synopsis
.nf
\fBopen\fP \fIFILES\fP \&...
.fi
.sp
.SS Description
.sp
\fBopen\fP opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional \fBxdg\-open\fP utility, from the \fBxdg\-utils\fP package.
.sp
Note that this function will not be used if a command by this name exists (which is the case on macOS or Haiku).
.SS Example
.sp
\fBopen *.txt\fP opens all the text files in the current directory using your system\(aqs default text editor.
.SS or \- conditionally execute a command
.SS Synopsis
.nf
\fICOMMAND1\fP\fB;\fP \fBor\fP \fICOMMAND2\fP
.fi
.sp
.SS Description
.sp
\fBor\fP is used to execute a command if the previous command was not successful (returned a status of something other than 0).
.sp
\fBor\fP statements may be used as part of the condition in an if \%<> or while \%<> block.
.sp
\fBor\fP does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status \%<#\:variables-status> variable.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
The following code runs the \fBmake\fP command to build a program. If the build succeeds, the program is installed. If either step fails, \fBmake clean\fP is run, which removes the files created by the build process.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
make; and make install; or make clean
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
and \%<> command
.UNINDENT
.SS path \- manipulate and check paths
.SS Synopsis
.nf
\fBpath\fP \fBbasename\fP \fIGENERAL_OPTIONS\fP [(\fB\-E\fP | \fB\-\-no\-extension\fP)] [\fIPATH\fP \&...]
\fBpath\fP \fBdirname\fP \fIGENERAL_OPTIONS\fP [\fIPATH\fP \&...]
\fBpath\fP \fBextension\fP \fIGENERAL_OPTIONS\fP [\fIPATH\fP \&...]
\fBpath\fP \fBfilter\fP \fIGENERAL_OPTIONS\fP [\fB\-v\fP | \fB\-\-invert\fP]
[\fB\-d\fP] [\fB\-f\fP] [\fB\-l\fP] [\fB\-r\fP] [\fB\-w\fP] [\fB\-x\fP]
[(\fB\-t\fP | \fB\-\-type\fP) \fITYPE\fP] [(\fB\-p\fP | \fB\-\-perm\fP) \fIPERMISSION\fP] [\fB\-\-all\fP] [\fIPATH\fP \&...]
\fBpath\fP \fBis\fP \fIGENERAL_OPTIONS\fP [(\fB\-v\fP | \fB\-\-invert\fP)] [(\fB\-t\fP | \fB\-\-type\fP) \fITYPE\fP]
[\fB\-d\fP] [\fB\-f\fP] [\fB\-l\fP] [\fB\-r\fP] [\fB\-w\fP] [\fB\-x\fP]
[(\fB\-p\fP | \fB\-\-perm\fP) \fIPERMISSION\fP] [\fIPATH\fP \&...]
\fBpath\fP \fBmtime\fP \fIGENERAL_OPTIONS\fP [(\fB\-R\fP | \fB\-\-relative\fP)] [\fIPATH\fP \&...]
\fBpath\fP \fBnormalize\fP \fIGENERAL_OPTIONS\fP [\fIPATH\fP \&...]
\fBpath\fP \fBresolve\fP \fIGENERAL_OPTIONS\fP [\fIPATH\fP \&...]
\fBpath\fP \fBchange\-extension\fP \fIGENERAL_OPTIONS\fP \fIEXTENSION\fP [\fIPATH\fP \&...]
\fBpath\fP \fBsort\fP \fIGENERAL_OPTIONS\fP [\fB\-r\fP | \fB\-\-reverse\fP]
[\fB\-u\fP | \fB\-\-unique\fP] [\fB\-\-key\fP\fB=\fP(\fBbasename\fP | \fBdirname\fP | \fBpath\fP)] [\fIPATH\fP \&...]
\fIGENERAL_OPTIONS\fP
[\fB\-z\fP | \fB\-\-null\-in\fP] [\fB\-Z\fP | \fB\-\-null\-out\fP] [\fB\-q\fP | \fB\-\-quiet\fP]
.fi
.sp
.SS Description
.sp
\fBpath\fP performs operations on paths.
.sp
PATH arguments are taken from the command line unless standard input is connected to a pipe or a file, in which case they are read from standard input, one PATH per line. It is an error to supply PATH arguments on both the command line and on standard input.
.sp
Arguments starting with \fB\-\fP are normally interpreted as switches; \fB\-\-\fP causes the following arguments not to be treated as switches even if they begin with \fB\-\fP\&. Switches and required arguments are recognized only on the command line.
.sp
When a path starts with \fB\-\fP, \fBpath filter\fP and \fBpath normalize\fP will prepend \fB\&./\fP on output to avoid it being interpreted as an option otherwise, so it\(aqs safe to pass path\(aqs output to other commands that can handle relative paths.
.sp
All subcommands accept a \fB\-q\fP or \fB\-\-quiet\fP switch, which suppresses the usual output but exits with the documented status. In this case these commands will quit early, without reading all of the available input.
.sp
All subcommands also accept a \fB\-Z\fP or \fB\-\-null\-out\fP switch, which makes them print output separated with NUL instead of newlines. This is for further processing, e.g. passing to another \fBpath\fP, or \fBxargs \-0\fP\&. This is not recommended when the output goes to the terminal or a command substitution.
.sp
All subcommands also accept a \fB\-z\fP or \fB\-\-null\-in\fP switch, which makes them accept arguments from stdin separated with NULL\-bytes. Since Unix paths can\(aqt contain NULL, that makes it possible to handle all possible paths and read input from e.g. \fBfind \-print0\fP\&. If arguments are given on the commandline this has no effect. This should mostly be unnecessary since \fBpath\fP automatically starts splitting on NULL if one appears in the first PATH_MAX bytes, PATH_MAX being the operating system\(aqs maximum length for a path plus a NULL byte.
.sp
Some subcommands operate on the paths as strings and so work on nonexistent paths, while others need to access the paths themselves and so filter out nonexistent paths.
.sp
The following subcommands are available.
.SS \(dqbasename\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path basename [\-E | \-\-no\-extension] [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath basename\fP returns the last path component of the given path, by removing the directory prefix and removing trailing slashes. In other words, it is the part that is not the dirname. For files you might call it the \(dqfilename\(dq.
.sp
If the \fB\-E\fP or \fB\-\-no\-extension\fP option is used and the base name contained a period, the path is returned with the extension (or the last extension) removed, i.e. the \(dqfilename\(dq without an extension (akin to calling \fBpath change\-extension \(dq\(dq (path basename $path)\fP).
.sp
It returns 0 if there was a basename, i.e. if the path wasn\(aqt empty or just slashes.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path basename ./foo.mp4
foo.mp4
>_ path basename ../banana
banana
>_ path basename /usr/bin/
bin
>_ path basename /usr/bin/*
# This prints all files in /usr/bin/
# A selection:
cp
fish
grep
rm
.EE
.UNINDENT
.UNINDENT
.SS \(dqdirname\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path dirname [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath dirname\fP returns the dirname for the given path. This is the part before the last \(dq/\(dq, discounting trailing slashes. In other words, it is the part that is not the basename (discounting superfluous slashes).
.sp
It returns 0 if there was a dirname, i.e. if the path wasn\(aqt empty or just slashes.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path dirname ./foo.mp4
\&.
>_ path dirname ../banana
\&..
>_ path dirname /usr/bin/
/usr
.EE
.UNINDENT
.UNINDENT
.SS \(dqextension\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path extension [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath extension\fP returns the extension of the given path. This is the part after (and including) the last \(dq.\(dq, unless that \(dq.\(dq followed a \(dq/\(dq or the basename is \(dq.\(dq or \(dq..\(dq, in which case there is no extension and an empty line is printed.
.sp
If the filename ends in a \(dq.\(dq, only a \(dq.\(dq is printed.
.sp
It returns 0 if there was an extension.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path extension ./foo.mp4
\&.mp4
>_ path extension ../banana
# an empty line, status 1
>_ path extension ~/.config
# an empty line, status 1
>_ path extension ~/.config.d
\&.d
>_ path extension ~/.config.
\&.
>_ set \-l path (path change\-extension \(aq\(aq ./foo.mp4)
>_ set \-l extension (path extension ./foo.mp4)
> echo $path$extension
# reconstructs the original path again.
\&./foo.mp4
.EE
.UNINDENT
.UNINDENT
.SS \(dqfilter\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path filter [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] \e
[\-d] [\-f] [\-l] [\-r] [\-w] [\-x] \e
[\-v | \-\-invert] [(\-t | \-\-type) TYPE] [(\-p | \-\-perm) PERMISSION] [\-\-all] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath filter\fP returns all of the given paths that match the given checks. In all cases, the paths need to exist, nonexistent paths are always filtered.
.sp
The available filters are:
.INDENT 0.0
.IP \(bu 2
\fB\-t\fP or \fB\-\-type\fP with the options: \(dqdir\(dq, \(dqfile\(dq, \(dqlink\(dq, \(dqblock\(dq, \(dqchar\(dq, \(dqfifo\(dq and \(dqsocket\(dq, in which case the path needs to be a directory, file, link, block device, character device, named pipe or socket, respectively.
.IP \(bu 2
\fB\-d\fP, \fB\-f\fP and \fB\-l\fP are short for \fB\-\-type=dir\fP, \fB\-\-type=file\fP and \fB\-\-type=link\fP, respectively. There are no shortcuts for the other types.
.IP \(bu 2
\fB\-p\fP or \fB\-\-perm\fP with the options: \(dqread\(dq, \(dqwrite\(dq, and \(dqexec\(dq, as well as \(dqsuid\(dq, \(dqsgid\(dq, \(dquser\(dq (referring to the path owner) and \(dqgroup\(dq (referring to the path\(aqs group), in which case the path needs to have all of the given permissions for the current user.
.IP \(bu 2
\fB\-r\fP, \fB\-w\fP and \fB\-x\fP are short for \fB\-\-perm=read\fP, \fB\-\-perm=write\fP and \fB\-\-perm=exec\fP, respectively. There are no shortcuts for the other permissions.
.UNINDENT
.sp
Note that the path needs to be \fIany\fP of the given types, but have \fIall\fP of the given permissions. This is because having a path that is both writable and executable makes sense, but having a path that is both a directory and a file doesn\(aqt. Links will count as the type of the linked\-to file, so links to files count as files, links to directories count as directories.
.sp
The filter options can either be given as multiple options, or comma\-separated \- \fBpath filter \-t dir,file\fP or \fBpath filter \-\-type dir \-\-type file\fP are equivalent.
.sp
With \fB\-\-invert\fP, the meaning of the filtering is inverted \- any path that wouldn\(aqt pass (including by not existing) passes, and any path that would pass fails.
.sp
When a path starts with \fB\-\fP, \fBpath filter\fP will prepend \fB\&./\fP to avoid it being interpreted as an option otherwise.
.sp
It returns 0 if at least one path passed the filter.
.sp
With \fB\-\-all\fP, return status 0 (true) if all paths pass the filter, and status 1 (false) if any path fails. This is equivalent to \fBnot path filter \-v\fP\&. It produces no output, only a status.
.sp
When \fB\-\-all\fP combined with \fB\-\-invert\fP, it returns status 0 (true) if all paths fail the filter and status 1 (false) if any path passes.
.sp
\fBpath is\fP is shorthand for \fBpath filter \-q\fP, i.e. just checking without producing output, see The is subcommand\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path filter /usr/bin /usr/argagagji
# The (hopefully) nonexistent argagagji is filtered implicitly:
/usr/bin
>_ path filter \-\-type file /usr/bin /usr/bin/fish
# Only fish is a file
/usr/bin/fish
>_ path filter \-\-type file,dir \-\-perm exec,write /usr/bin/fish /home/me
# fish is a file, which passes, and executable, which passes,
# but probably not writable, which fails.
#
# $HOME is a directory and both writable and executable, typically.
# So it passes.
/home/me
>_ path filter \-fdxw /usr/bin/fish /home/me
# This is the same as above: \(dq\-f\(dq is \(dq\-\-type=file\(dq, \(dq\-d\(dq is \(dq\-\-type=dir\(dq,
# \(dq\-x\(dq is short for \(dq\-\-perm=exec\(dq and \(dq\-w\(dq short for \(dq\-\-perm=write\(dq!
/home/me
>_ path filter \-fx $PATH/*
# Prints all possible commands \- the first entry of each name is what fish would execute!
>_ path filter \-\-all /usr/bin /usr/argagagji
# This returns 1 (false) because not all paths pass the filter.
.EE
.UNINDENT
.UNINDENT
.SS \(dqis\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path is [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] \e
[\-d] [\-f] [\-l] [\-r] [\-w] [\-x] \e
[\-v | \-\-invert] [(\-t | \-\-type) TYPE] [(\-p | \-\-perm) PERMISSION] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath is\fP is short for \fBpath filter \-q\fP\&. It returns true if any of the given files passes the filter, but does not produce any output.
.sp
\fB\-\-quiet\fP can still be passed for compatibility but is redundant. The options are the same as for \fBpath filter\fP\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path is /usr/bin /usr/argagagji
# /usr/bin exists, so this returns a status of 0 (true). It prints nothing.
>_ path is /usr/argagagji
# /usr/argagagji does not, so this returns a status of 1 (false). It also prints nothing.
>_ path is \-fx /bin/sh
# /bin/sh is usually an executable file, so this returns true.
.EE
.UNINDENT
.UNINDENT
.SS \(dqmtime\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path mtime [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] [\-R | \-\-relative] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath mtime\fP returns the last modification time (\(dqmtime\(dq in unix jargon) of the given paths, in seconds since the unix epoch (the beginning of the 1st of January 1970).
.sp
With \fB\-\-relative\fP (or \fB\-R\fP), it prints the number of seconds since the modification time. It only reads the current time once at start, so in case multiple paths are given the times are all relative to the \fIstart\fP of \fBpath mtime \-R\fP running.
.sp
If you want to know if a file is newer or older than another file, consider using \fBtest \-nt\fP instead. See the test documentation \%<>\&.
.sp
It returns 0 if reading mtime for any path succeeded.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ date +%s
# This prints the current time as seconds since the epoch
1657217847
>_ path mtime /etc/
1657213796
>_ path mtime \-R /etc/
4078
# So /etc/ on this system was last modified a little over an hour ago
# This is the same as
>_ math (date +%s) \- (path mtime /etc/)
.EE
.UNINDENT
.UNINDENT
.SS \(dqnormalize\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path normalize [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath normalize\fP returns the normalized versions of all paths. That means it squashes duplicate \(dq/\(dq, collapses \(dq../\(dq with earlier components and removes \(dq.\(dq components.
.sp
Unlike \fBrealpath\fP or \fBpath resolve\fP, it does not make the paths absolute. It also does not resolve any symlinks. As such it can operate on non\-existent paths.
.sp
Because it operates on paths as strings and doesn\(aqt resolve symlinks, it works sort of like \fBpwd \-L\fP and \fBcd\fP\&. E.g. \fBpath normalize link/..\fP will return \fB\&.\fP, just like \fBcd link; cd ..\fP would return to the current directory. For a physical view of the filesystem, see \fBpath resolve\fP\&.
.sp
Leading \(dq./\(dq components are usually removed. But when a path starts with \fB\-\fP, \fBpath normalize\fP will add it instead to avoid confusion with options.
.sp
It returns 0 if any normalization was done, i.e. any given path wasn\(aqt in canonical form.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path normalize /usr/bin//../../etc/fish
# The \(dq//\(dq is squashed and the \(dq..\(dq components neutralize the components before
/etc/fish
>_ path normalize /bin//bash
# The \(dq//\(dq is squashed, but /bin isn\(aqt resolved even if your system links it to /usr/bin.
/bin/bash
>_ path normalize ./my/subdirs/../sub2
my/sub2
>_ path normalize \-\- \-/foo
\&./\-/foo
.EE
.UNINDENT
.UNINDENT
.SS \(dqresolve\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path resolve [\-z | \-\-null\-in] [\-Z | \-\-null\-out] [\-q | \-\-quiet] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath resolve\fP returns the normalized, physical and absolute versions of all paths. That means it resolves symlinks and does what \fBpath normalize\fP does: it squashes duplicate \(dq/\(dq, collapses \(dq../\(dq with earlier components and removes \(dq.\(dq components. Then it turns that path into the absolute path starting from the filesystem root \(dq/\(dq.
.sp
It is similar to \fBrealpath\fP, as it creates the \(dqreal\(dq, canonical version of the path. However, for paths that can\(aqt be resolved, e.g. if they don\(aqt exist or form a symlink loop, it will resolve as far as it can and normalize the rest.
.sp
Because it resolves symlinks, it works sort of like \fBpwd \-P\fP\&. E.g. \fBpath resolve link/..\fP will return the parent directory of what the link points to, just like \fBcd link; cd (pwd \-P)/..\fP would go to it. For a logical view of the filesystem, see \fBpath normalize\fP\&.
.sp
It returns 0 if any normalization or resolution was done, i.e. any given path wasn\(aqt in canonical form.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path resolve /bin//sh
# The \(dq//\(dq is squashed, and /bin is resolved if your system links it to /usr/bin.
# sh here is bash (this is common on linux systems)
/usr/bin/bash
>_ path resolve /bin/foo///bar/../baz
# Assuming /bin exists and is a symlink to /usr/bin, but /bin/foo doesn\(aqt.
# This resolves the /bin/ and normalizes the nonexistent rest:
/usr/bin/foo/baz
.EE
.UNINDENT
.UNINDENT
.SS \(dqchange\-extension\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path change\-extension [\-z | \-\-null\-in] [\-Z | \-\-null\-out] \e
[\-q | \-\-quiet] EXTENSION [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath change\-extension\fP returns the given paths, with their extension changed to the given new extension. The extension is the part after (and including) the last \(dq.\(dq, unless that \(dq.\(dq followed a \(dq/\(dq or the basename is \(dq.\(dq or \(dq..\(dq, in which case there is no previous extension and the new one is added.
.sp
If the extension is empty, any previous extension is stripped, along with the \(dq.\(dq. This is, of course, the inverse of \fBpath extension\fP\&.
.sp
One leading dot on the extension is ignored, so \(dq.mp3\(dq and \(dqmp3\(dq are treated the same.
.sp
It returns 0 if it was given any paths.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path change\-extension mp4 ./foo.wmv
\&./foo.mp4
>_ path change\-extension .mp4 ./foo.wmv
\&./foo.mp4
>_ path change\-extension \(aq\(aq ../banana
\&../banana
>_ path change\-extension \(aq\(aq ~/.config
/home/alfa/.config
>_ path change\-extension \(aq\(aq ~/.config.d
/home/alfa/.config
>_ path change\-extension \(aq\(aq ~/.config.
/home/alfa/.config
.EE
.UNINDENT
.UNINDENT
.SS \(dqsort\(dq subcommand
.INDENT 0.0
.INDENT 3.5
.sp
.EX
path sort [\-z | \-\-null\-in] [\-Z | \-\-null\-out] \e
[\-q | \-\-quiet] [\-r | \-\-reverse] \e
[\-\-key=basename|dirname|path] [PATH ...]
.EE
.UNINDENT
.UNINDENT
.sp
\fBpath sort\fP returns the given paths in sorted order. They are sorted in the same order as globs \- alphabetically, but with runs of numerical digits compared numerically.
.sp
With \fB\-\-reverse\fP or \fB\-r\fP the sort is reversed.
.sp
With \fB\-\-key=\fP only the given part of the path is compared, e.g. \fB\-\-key=dirname\fP causes only the dirname to be compared, \fB\-\-key=basename\fP only the basename and \fB\-\-key=path\fP causes the entire path to be compared (this is the default).
.sp
With \fB\-\-unique\fP or \fB\-u\fP the sort is deduplicated, meaning only the first of a run that have the same key is kept. So if you are sorting by basename, then only the first of each basename is used.
.sp
The sort used is stable, so sorting first by basename and then by dirname works and causes the files to be grouped according to directory.
.sp
It currently returns 0 if it was given any paths.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ path sort 10\-foo 2\-bar
2\-bar
10\-foo
>_ path sort \-\-reverse 10\-foo 2\-bar
10\-foo
2\-bar
>_ path sort \-\-unique \-\-key=basename $fish_function_path/*.fish
# prints a list of all function files fish would use, sorted by name.
.EE
.UNINDENT
.UNINDENT
.SS Combining \fBpath\fP
.sp
\fBpath\fP is meant to be easy to combine with itself, other tools and fish.
.sp
This is why
.INDENT 0.0
.IP \(bu 2
\fBpath\fP\(aqs output is automatically split by fish if it goes into a command substitution, so just doing \fB(path ...)\fP handles all paths, even those containing newlines, correctly
.IP \(bu 2
\fBpath\fP has \fB\-\-null\-in\fP to handle null\-delimited input (typically automatically detected!), and \fB\-\-null\-out\fP to pass on null\-delimited output
.UNINDENT
.sp
Some examples of combining \fBpath\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Expand all paths in the current directory, leave only executable files, and print their resolved path
path filter \-zZ \-xf \-\- * | path resolve \-z
# The same thing, but using find (note \-maxdepth needs to come first or find will scream)
# (this also depends on your particular version of find)
# Note the \(ga\-z\(ga is unnecessary for any sensible version of find \- if \(gapath\(ga sees a NULL,
# it will split on NULL automatically.
find . \-maxdepth 1 \-type f \-executable \-print0 | path resolve \-z
set \-l paths (path filter \-p exec $PATH/fish \-Z | path resolve)
.EE
.UNINDENT
.UNINDENT
.SS popd \- move through directory stack
.SS Synopsis
.nf
\fBpopd\fP
.fi
.sp
.SS Description
.sp
\fBpopd\fP removes the top directory from the directory stack \%<#\:directory-stack> and changes the working directory to the new top directory. Use pushd \%<> to add directories to the stack.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
pushd /usr/src
# Working directory is now /usr/src
# Directory stack contains /usr/src
pushd /usr/src/fish\-shell
# Working directory is now /usr/src/fish\-shell
# Directory stack contains /usr/src /usr/src/fish\-shell
popd
# Working directory is now /usr/src
# Directory stack contains /usr/src
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the dirs \%<> command to print the directory stack
.IP \(bu 2
the cdh \%<> command which provides a more intuitive way to navigate to recently visited directories.
.UNINDENT
.SS prevd \- move backward through directory history
.SS Synopsis
.nf
\fBprevd\fP [\fB\-l\fP | \fB\-\-list\fP] [\fIPOS\fP]
.fi
.sp
.SS Description
.sp
\fBprevd\fP moves backwards \fIPOS\fP positions in the history of visited directories \%<#\:directory-history>; if the beginning of the history has been hit, a warning is printed.
.sp
If the \fB\-l\fP or \fB\-\-list\fP flag is specified, the current history is also displayed.
.sp
Note that the \fBcd\fP command limits directory history to the 25 most recently visited directories. The history is stored in the \fBdirprev\fP and \fBdirnext\fP variables which this command manipulates.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cd /usr/src
# Working directory is now /usr/src
cd /usr/src/fish\-shell
# Working directory is now /usr/src/fish\-shell
prevd
# Working directory is now /usr/src
nextd
# Working directory is now /usr/src/fish\-shell
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the cdh \%<> command to display a prompt to quickly navigate the history
.IP \(bu 2
the dirh \%<> command to print the directory history
.IP \(bu 2
the nextd \%<> command to move forward
.UNINDENT
.SS printf \- display text according to a format string
.SS Synopsis
.nf
\fBprintf\fP \fIFORMAT\fP [\fIARGUMENT\fP \&...]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBprintf\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man printf\fP\&.
.sp
\fBprintf\fP uses the format string \fIFORMAT\fP to print the \fIARGUMENT\fP arguments. This means that it takes format specifiers in the format string and replaces each with an argument.
.sp
The \fIFORMAT\fP argument is re\-used as many times as necessary to convert all of the given arguments. So \fBprintf %s\en flounder catfish clownfish shark\fP will print four lines.
.sp
Unlike echo \%<>, \fBprintf\fP does not append a new line unless it is specified as part of the string.
.sp
It doesn\(aqt support any options, so there is no need for a \fB\-\-\fP separator, which makes it easier to use for arbitrary input than \fBecho\fP\&. [1]
.SS Format Specifiers
.sp
Valid format specifiers are taken from the C library function \fBprintf(3)\fP:
.INDENT 0.0
.IP \(bu 2
\fB%d\fP or \fB%i\fP: Argument will be used as decimal integer (signed or unsigned)
.IP \(bu 2
\fB%o\fP: An octal unsigned integer
.IP \(bu 2
\fB%u\fP: An unsigned decimal integer \- this means negative numbers will wrap around
.IP \(bu 2
\fB%x\fP or \fB%X\fP: An unsigned hexadecimal integer
.IP \(bu 2
\fB%f\fP, \fB%g\fP or \fB%G\fP: A floating\-point number. \fB%f\fP defaults to 6 places after the decimal point (which is locale\-dependent \- e.g. in de_DE it will be a \fB,\fP). \fB%g\fP and \fB%G\fP will trim trailing zeroes and switch to scientific notation (like \fB%e\fP) if the numbers get small or large enough.
.IP \(bu 2
\fB%e\fP or \fB%E\fP: A floating\-point number in scientific (XXXeYY) notation
.IP \(bu 2
\fB%s\fP: A string
.IP \(bu 2
\fB%b\fP: As a string, interpreting backslash escapes, except that octal escapes are of the form 0 or 0ooo.
.UNINDENT
.sp
\fB%%\fP signifies a literal \(dq%\(dq.
.sp
Conversion can fail, e.g. \(dq102.234\(dq can\(aqt losslessly convert to an integer, causing printf to print an error. If you are okay with losing information, silence errors with \fB2>/dev/null\fP\&.
.sp
A number between the \fB%\fP and the format letter specifies the width. The result will be left\-padded with spaces.
.SS Backslash Escapes
.sp
printf also knows a number of backslash escapes:
.INDENT 0.0
.IP \(bu 2
\fB\e\(dq\fP double quote
.IP \(bu 2
\fB\e\e\fP backslash
.IP \(bu 2
\fB\ea\fP alert (bell)
.IP \(bu 2
\fB\eb\fP backspace
.IP \(bu 2
\fB\ec\fP produce no further output
.IP \(bu 2
\fB\ee\fP escape
.IP \(bu 2
\fB\ef\fP form feed
.IP \(bu 2
\fB\en\fP new line
.IP \(bu 2
\fB\er\fP carriage return
.IP \(bu 2
\fB\et\fP horizontal tab
.IP \(bu 2
\fB\ev\fP vertical tab
.IP \(bu 2
\fB\eooo\fP octal number (ooo is 1 to 3 digits)
.IP \(bu 2
\fB\exhh\fP hexadecimal number (hhh is 1 to 2 digits)
.IP \(bu 2
\fB\euhhhh\fP 16\-bit Unicode character (hhhh is 4 digits)
.IP \(bu 2
\fB\eUhhhhhhhh\fP 32\-bit Unicode character (hhhhhhhh is 8 digits)
.UNINDENT
.SS Errors and Return Status
.sp
If the given argument doesn\(aqt work for the given format (like when you try to convert a number like 3.141592 to an integer), printf prints an error, to stderr. printf will then also return non\-zero, but will still try to print as much as it can.
.sp
It will also return non\-zero if no argument at all was given, in which case it will print nothing.
.sp
This printf has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try \fBcommand printf\fP\&.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
printf \(aq%s\et%s\en\(aq flounder fish
.EE
.UNINDENT
.UNINDENT
.sp
Will print \(dqflounder fish\(dq (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
printf \(aq%s: %d\(aq \(dqNumber of bananas in my pocket\(dq 42
.EE
.UNINDENT
.UNINDENT
.sp
Will print \(dqNumber of bananas in my pocket: 42\(dq, \fIwithout\fP a newline.
.SS See Also
.INDENT 0.0
.IP \(bu 2
the echo \%<> command, for simpler output
.UNINDENT
.SS Footnotes
.IP [1] 5
In fact, while fish\(aqs \fBecho\fP supports \fB\-\-\fP, POSIX forbids it, so other implementations can\(aqt be used if the input contains anything starting with \fB\-\fP\&.
.SS prompt_hostname \- print the hostname, shortened for use in the prompt
.SS Synopsis
.nf
\fBprompt_hostname\fP
.fi
.sp
.SS Description
.sp
\fBprompt_hostname\fP prints a shortened version the current hostname for use in the prompt. It will print just the first component of the hostname, everything up to the first dot.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
echo \-n (whoami)@(prompt_hostname) (prompt_pwd) \(aq$ \(aq
end
.EE
.UNINDENT
.UNINDENT
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# The machine\(aqs full hostname is foo.bar.com
>_ prompt_hostname
foo
.EE
.UNINDENT
.UNINDENT
.SS prompt_login \- describe the login suitable for prompt
.SS Synopsis
.nf
\fBprompt_login\fP
.fi
.sp
.SS Description
.sp
\fBprompt_login\fP is a function to describe the current login. It will show the user, the host and also whether the shell is running in a chroot (currently Debian\(aqs \fBdebian_chroot\fP file is supported).
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
echo \-n (prompt_login) (prompt_pwd) \(aq$ \(aq
end
.EE
.UNINDENT
.UNINDENT
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ prompt_login
root@bananablaster
.EE
.UNINDENT
.UNINDENT
.SS prompt_pwd \- print pwd suitable for prompt
.SS Synopsis
.nf
\fBprompt_pwd\fP
.fi
.sp
.SS Description
.sp
\fBprompt_pwd\fP is a function to print the current working directory in a way suitable for prompts. It will replace the home directory with \(dq~\(dq and shorten every path component but the last to a default of one character.
.sp
To change the number of characters per path component, pass \fB\-\-dir\-length=\fP or set \fBfish_prompt_pwd_dir_length\fP to the number of characters. Setting it to 0 or an invalid value will disable shortening entirely. This defaults to 1.
.sp
To keep some components unshortened, pass \fB\-\-full\-length\-dirs=\fP or set \fBfish_prompt_pwd_full_dirs\fP to the number of components. This defaults to 1, keeping the last component.
.sp
If any positional arguments are given, \fBprompt_pwd\fP shortens them instead of \fBPWD\fP \%<#\:envvar-PWD>\&.
.SS Options
.INDENT 0.0
.TP
\fB\-d\fP or \fB\-\-dir\-length\fP \fIMAX\fP
Causes the components to be shortened to \fIMAX\fP characters each. This overrides \fBfish_prompt_pwd_dir_length\fP\&.
.TP
\fB\-D\fP or \fB\-\-full\-length\-dirs\fP \fINUM\fP
Keeps \fINUM\fP components (counted from the right) as full length without shortening. This overrides \fBfish_prompt_pwd_full_dirs\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ cd ~/
>_ echo $PWD
/home/alfa
>_ prompt_pwd
~
>_ cd /tmp/banana/sausage/with/mustard
>_ prompt_pwd
/t/b/s/w/mustard
>_ set \-g fish_prompt_pwd_dir_length 3
>_ prompt_pwd
/tmp/ban/sau/wit/mustard
>_ prompt_pwd \-\-full\-length\-dirs=2 \-\-dir\-length=1
/t/b/s/with/mustard
>_ echo (prompt_pwd | string split /)[\-1]
mustard
>_ echo (string join / (prompt_pwd | string split /)[\-3..\-1])
s/with/mustard
.EE
.UNINDENT
.UNINDENT
.SS psub \- perform process substitution
.SS Synopsis
.nf
\fICOMMAND1\fP ( \fICOMMAND2\fP | \fBpsub\fP [\fB\-F\fP | \fB\-\-fifo\fP] [\fB\-f\fP | \fB\-\-file\fP] [(\fB\-s\fP | \fB\-\-suffix\fP) \fISUFFIX\fP] )
.fi
.sp
.SS Description
.sp
Some shells (e.g., ksh, bash) feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. \fBpsub\fP combined with a regular command substitution provides the same functionality.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-f\fP or \fB\-\-file\fP
Use a regular file instead of a named pipe to communicate with the calling process. This will cause \fBpsub\fP to be significantly slower when large amounts of data are involved, but has the advantage that the reading process can seek in the stream. This is the default.
.TP
\fB\-F\fP or \fB\-\-fifo\fP
Use a named pipe rather than a file. You should only use this if the command produces no more than 8 KiB of output. The limit on the amount of data a FIFO can buffer varies with the OS but is typically 8 KiB, 16 KiB or 64 KiB. If you use this option and the command on the left of the psub pipeline produces more output a deadlock is likely to occur.
.TP
\fB\-s\fP or \fB\-\-suffix\fP \fISUFFIX\fP
Append SUFFIX to the filename.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
diff (sort a.txt | psub) (sort b.txt | psub)
# shows the difference between the sorted versions of files \(ga\(gaa.txt\(ga\(ga and \(ga\(gab.txt\(ga\(ga.
source\-highlight \-f esc (cpp main.c | psub \-f \-s .c)
# highlights \(ga\(gamain.c\(ga\(ga after preprocessing as a C source.
.EE
.UNINDENT
.UNINDENT
.SS pushd \- push directory to directory stack
.SS Synopsis
.nf
\fBpushd\fP \fIDIRECTORY\fP
.fi
.sp
.SS Description
.sp
The \fBpushd\fP function adds \fIDIRECTORY\fP to the top of the directory stack \%<#\:directory-stack> and makes it the current working directory. popd \%<> will pop it off and return to the original directory.
.sp
Without arguments, it exchanges the top two directories in the stack.
.sp
\fBpushd +NUMBER\fP rotates the stack counter\-clockwise i.e. from bottom to top
.sp
\fBpushd \-NUMBER\fP rotates clockwise i.e. top to bottom.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cd ~/dir1
pushd ~/dir2
pushd ~/dir3
# Working directory is now ~/dir3
# Directory stack contains ~/dir2 ~/dir1
pushd /tmp
# Working directory is now /tmp
# Directory stack contains ~/dir3 ~/dir2 ~/dir1
pushd +1
# Working directory is now ~/dir3
# Directory stack contains ~/dir2 ~/dir1 /tmp
popd
# Working directory is now ~/dir2
# Directory stack contains ~/dir1 /tmp
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
the dirs \%<> command to print the directory stack
.IP \(bu 2
the cdh \%<> command which provides a more intuitive way to navigate to recently visited directories.
.UNINDENT
.SS pwd \- output the current working directory
.SS Synopsis
.nf
\fBpwd\fP [\fB\-P\fP | \fB\-\-physical\fP]
\fBpwd\fP [\fB\-L\fP | \fB\-\-logical\fP]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBpwd\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man pwd\fP\&.
.sp
\fBpwd\fP outputs (prints) the current working directory.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-L\fP or \fB\-\-logical\fP
Output the logical working directory, without resolving symlinks (default behavior).
.TP
\fB\-P\fP or \fB\-\-physical\fP
Output the physical working directory, with symlinks resolved.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS See Also
.sp
Navigate directories using the directory history \%<#\:directory-history> or the directory stack \%<#\:directory-stack>
.SS random \- generate random number
.SS Synopsis
.nf
\fBrandom\fP
\fBrandom\fP \fISEED\fP
\fBrandom\fP \fISTART\fP \fIEND\fP
\fBrandom\fP \fISTART\fP \fISTEP\fP \fIEND\fP
\fBrandom\fP \fBchoice\fP [\fIITEMS\fP \&...]
.fi
.sp
.SS Description
.sp
\fBrandom\fP generates a pseudo\-random integer from a uniform distribution. The
range (inclusive) depends on the arguments.
.sp
No arguments indicate a range of 0 to 32767 (inclusive).
.sp
If one argument is specified, the internal engine will be seeded with the
argument for future invocations of \fBrandom\fP and no output will be produced.
.sp
Two arguments indicate a range from \fISTART\fP to \fIEND\fP (both \fISTART\fP and \fIEND\fP included).
.sp
Three arguments indicate a range from \fISTART\fP to \fIEND\fP with a spacing of \fISTEP\fP
between possible outputs.
.sp
\fBrandom choice\fP will select one random item from the succeeding arguments.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.sp
Note that seeding the engine will NOT give the same result across different
systems.
.sp
You should not consider \fBrandom\fP cryptographically secure, or even
statistically accurate.
.SS Example
.sp
The following code will count down from a random even number between 10 and 20 to 1:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in (seq (random 10 2 20) \-1 1)
echo $i
end
.EE
.UNINDENT
.UNINDENT
.sp
And this will open a random picture from any of the subdirectories:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
open (random choice **.jpg)
.EE
.UNINDENT
.UNINDENT
.sp
Or, to only get even numbers from 2 to 20:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
random 2 2 20
.EE
.UNINDENT
.UNINDENT
.sp
Or odd numbers from 1 to 3:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
random 1 2 3 # or 1 2 4
.EE
.UNINDENT
.UNINDENT
.SS read \- read line of input into variables
.SS Synopsis
.nf
\fBread\fP [\fIOPTIONS\fP] [\fIVARIABLE\fP \&...]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBread\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man read\fP\&.
.sp
\fBread\fP reads from standard input and stores the result in shell variables. In an alternative mode, it can also print to its own standard output, for example for use in command substitutions.
.sp
By default, \fBread\fP reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given.
.sp
Unlike other shells, there is no default variable (such as \fBREPLY\fP) for storing the result \- instead, it is printed on standard output.
.sp
When \fBread\fP reaches the end\-of\-file (EOF) instead of the terminator, the exit status is set to 1.
Otherwise, it is set to 0.
.sp
If \fBread\fP sets a variable and you don\(aqt specify a scope, it will use the same rules that set \- display and change shell variables \%<> does \- if the variable exists, it will use it (in the lowest scope). If it doesn\(aqt, it will use an unexported function\-scoped variable.
.sp
The following options, like the corresponding ones in set \- display and change shell variables \%<>, control variable scope or attributes:
.INDENT 0.0
.TP
\fB\-U\fP or \fB\-\-universal\fP
Sets a universal variable.
The variable will be immediately available to all the user\(aqs \fBfish\fP instances on the machine, and will be persisted across restarts of the shell.
.TP
\fB\-f\fP or \fB\-\-function\fP
Sets a variable scoped to the executing function.
It is erased when the function ends.
.TP
\fB\-l\fP or \fB\-\-local\fP
Sets a locally\-scoped variable in this block.
It is erased when the block ends.
Outside of a block, this is the same as \fB\-\-function\fP\&.
.TP
\fB\-g\fP or \fB\-\-global\fP
Sets a globally\-scoped variable.
Global variables are available to all functions running in the same shell.
They can be modified or erased.
.TP
\fB\-u\fP or \fB\-\-unexport\fP
Prevents the variables from being exported to child processes (default behaviour).
.TP
\fB\-x\fP or \fB\-\-export\fP
Exports the variables to child processes.
.UNINDENT
.sp
The following options control the interactive mode:
.INDENT 0.0
.TP
\fB\-c\fP \fICMD\fP or \fB\-\-command\fP \fICMD\fP
Sets the initial string in the interactive mode command buffer to \fICMD\fP\&.
.TP
\fB\-s\fP or \fB\-\-silent\fP
Masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information.
.TP
\fB\-p\fP or \fB\-\-prompt\fP \fIPROMPT_CMD\fP
Uses the output of the shell command \fIPROMPT_CMD\fP as the prompt for the interactive mode. The default prompt command is \fBset_color green; echo \-n read; set_color \-\-reset; echo \-n \(dq> \(dq\fP
.TP
\fB\-P\fP or \fB\-\-prompt\-str\fP \fIPROMPT_STR\fP
Uses the literal \fIPROMPT_STR\fP as the prompt for the interactive mode.
.TP
\fB\-R\fP or \fB\-\-right\-prompt\fP \fIRIGHT_PROMPT_CMD\fP
Uses the output of the shell command \fIRIGHT_PROMPT_CMD\fP as the right prompt for the interactive mode. There is no default right prompt command.
.TP
\fB\-S\fP or \fB\-\-shell\fP
Enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. NOTE: Prior to fish 3.0, the short opt for \fB\-\-shell\fP was \fB\-s\fP, but it has been changed for compatibility with bash\(aqs \fB\-s\fP short opt for \fB\-\-silent\fP\&.
.UNINDENT
.sp
The following options control how much is read and how it is stored:
.INDENT 0.0
.TP
\fB\-d\fP or \fB\-\-delimiter\fP \fIDELIMITER\fP
Splits on \fIDELIMITER\fP\&. \fIDELIMITER\fP will be used as an entire string to split on, not a set of characters.
.TP
\fB\-n\fP or \fB\-\-nchars\fP \fINCHARS\fP
Makes \fBread\fP return after reading \fINCHARS\fP characters or the end of the line, whichever comes first.
.TP
\fB\-t\fP, \fB\-\-tokenize\fP or \fB\-\-tokenize\-raw\fP
Causes read to split the input into variables by the shell\(aqs tokenization rules.
This means it will honor quotes and escaping.
This option is of course incompatible with other options to control splitting like \fB\-\-delimiter\fP and does not honor \fBIFS\fP \%<#\:envvar-IFS> (like fish\(aqs tokenizer).
The \fB\-t\fP \-or \fB\-\-tokenize\fP variants perform quote removal, so e.g. \fBa\e b\fP is stored as \fBa b\fP\&.
However variables and command substitutions are not expanded.
.TP
\fB\-a\fP or \fB\-\-list\fP
Stores the result as a list in a single variable. This option is also available as \fB\-\-array\fP for backwards compatibility.
.TP
\fB\-z\fP or \fB\-\-null\fP
Marks the end of the line with the NUL character, instead of newline. This also disables interactive mode.
.TP
\fB\-L\fP or \fB\-\-line\fP
Reads each line into successive variables, and stops after each variable has been filled. This cannot be combined with the \fB\-\-null\fP option, or options to control splitting like \fB\-\-delimiter\fP\&.
.UNINDENT
.sp
Without the \fB\-\-line\fP option, \fBread\fP reads a single line of input from standard input, breaks it into tokens, and then assigns one token to each variable specified in \fIVARIABLES\fP\&. If there are more tokens than variables, the complete remainder is assigned to the last variable.
.sp
If no option to determine how to split like \fB\-\-delimiter\fP, \fB\-\-line\fP or \fB\-\-tokenize\fP is given, the variable \fBIFS\fP is used as a list of characters to split on. Relying on the use of \fBIFS\fP is deprecated and this behaviour will be removed in future versions. The default value of \fBIFS\fP contains space, tab and newline characters. As a special case, if \fBIFS\fP is set to the empty string, each character of the input is considered a separate token.
.sp
With the \fB\-\-line\fP option, \fBread\fP reads a line of input from standard input into each provided variable, stopping when each variable has been filled. The line is not tokenized.
.sp
If no variable names are provided, \fBread\fP enters a special case that provides redirection from standard input to standard output, useful for command substitution. For instance, the fish shell command below can be used to read a password from the console instead of hardcoding it in the command itself, which prevents it from showing up in fish\(aqs history:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
mysql \-uuser \-p(read)
.EE
.UNINDENT
.UNINDENT
.sp
When running in this mode, \fBread\fP does not split the input in any way and text is redirected to standard output without any further processing or manipulation.
.sp
If \fB\-l\fP or \fB\-\-list\fP is provided, only one variable name is allowed and the tokens are stored as a list in this variable.
.sp
In order to protect the shell from consuming too many system resources, \fBread\fP will only consume a
maximum of 100 MiB (104857600 bytes); if the terminator is not reached before this limit then \fIVARIABLE\fP
is set to empty and the exit status is set to 122. This limit can be altered with the
\fBfish_read_limit\fP \%<#\:envvar-fish_read_limit> variable. If set to 0 (zero), the limit is removed.
.SS Example
.sp
\fBread\fP has a few separate uses.
.sp
The following code stores the value \(aqhello\(aq in the shell variable \fBfoo\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo hello | read foo
.EE
.UNINDENT
.UNINDENT
.sp
The while \%<> command is a neat way to handle command output line\-by\-line:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
printf \(aq%s\en\(aq line1 line2 line3 line4 | while read \-l foo
echo \(dqThis is another line: $foo\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
Delimiters given via \(dq\-d\(dq are taken as one string:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo a==b==c | read \-d == \-l a b c
echo $a # a
echo $b # b
echo $c # c
.EE
.UNINDENT
.UNINDENT
.sp
\fB\-\-tokenize\fP honors quotes and escaping like the shell\(aqs argument passing:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo \(aqa\e b\(aq | read \-t first second
echo $first # outputs \(dqa b\(dq, $second is empty
echo \(aqa\(dqfoo bar\(dqb (command echo wurst)*\(dq \(dq{a,b}\(aq | read \-lt \-l a b c
echo $a # outputs \(aqafoo barb\(aq (without the quotes)
echo $b # outputs \(aq(command echo wurst)* {a,b}\(aq (without the quotes)
echo $c # nothing
.EE
.UNINDENT
.UNINDENT
.sp
For an example on interactive use, see Querying for user input \%<#\:user-input>\&.
.SS realpath \- convert a path to an absolute path without symlinks
.SS Synopsis
.nf
\fBrealpath\fP [\fIOPTIONS\fP] \fIPATH\fP
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBrealpath\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man realpath\fP\&.
.sp
\fBrealpath\fP follows all symbolic links encountered for the provided \fBPATH\fP \%<#\:envvar-PATH>, printing the absolute path resolved. fish \%<> provides a \fBrealpath\fP\-alike builtin intended to enrich systems where no such command is installed by default.
.sp
If a \fBrealpath\fP command exists, that will be preferred.
\fBbuiltin realpath\fP will explicitly use the fish implementation of \fBrealpath\fP\&.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-s\fP or \fB\-\-no\-symlinks\fP
Don\(aqt resolve symlinks, only make paths absolute, squash multiple slashes and remove trailing slashes.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS return \- stop the current inner function
.SS Synopsis
.nf
\fBreturn\fP [\fIN\fP]
.fi
.sp
.SS Description
.sp
\fBreturn\fP halts a currently running function.
The exit status is set to \fIN\fP if it is given.
If \fBreturn\fP is invoked outside of a function or dot script it is equivalent to exit.
.sp
It is often added inside of a conditional block such as an if \%<> statement or a switch \%<> statement to conditionally stop the executing function and return to the caller; it can also be used to specify the exit status of a function.
.sp
If at the top level of a script, it exits with the given status, like exit \%<>\&.
If at the top level in an interactive session, it will set \fBstatus\fP \%<#\:envvar-status>, but not exit the shell.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
An implementation of the false command as a fish function:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function false
return 1
end
.EE
.UNINDENT
.UNINDENT
.SS set \- display and change shell variables
.SS Synopsis
.nf
\fBset\fP [(\fB\-f\fP | \fB\-\-function\fP) (\fB\-l\fP | \fB\-\-local\fP) (\fB\-g\fP | \fB\-\-global\fP) (\fB\-U\fP | \fB\-\-universal\fP)]
[(\fB\-x\fP | \fB\-\-export\fP) (\fB\-u\fP | \fB\-\-unexport\fP)]
\fBset\fP (\fB\-S\fP | \fB\-\-show\fP) (\fB\-L\fP | \fB\-\-long\fP) [\fINAME\fP \&...]
\fBset\fP [\fB\-Uflg\fP] [\fB\-xu\fP] [\fB\-\-no\-event\fP] \fINAME\fP [\fIVALUE\fP \&...]
\fBset\fP [\fB\-Uflg\fP] [\fB\-\-no\-event\fP] \fINAME\fP[[\fIINDEX\fP \&...]] [\fIVALUE\fP \&...]
\fBset\fP (\fB\-a\fP | \fB\-\-append\fP) (\fB\-p\fP | \fB\-\-prepend\fP) [\fB\-Uflg\fP] [\fB\-\-no\-event\fP] \fINAME\fP \fIVALUE\fP \&...
\fBset\fP (\fB\-e\fP | \fB\-\-erase\fP) [\fB\-Uflg\fP] [\fB\-\-no\-event\fP] \fINAME\fP[[\fIINDEX\fP]] \&...
\fBset\fP (\fB\-q\fP | \fB\-\-query\fP) [\fB\-Uflg\fP] [\fB\-xu\fP] \fINAME\fP[[\fIINDEX\fP]] \&...
.fi
.sp
.SS Description
.sp
\fBset\fP manipulates shell variables \%<#\:variables>\&.
.sp
If both \fINAME\fP and \fIVALUE\fP are provided, \fBset\fP assigns any values to variable \fINAME\fP\&.
Variables in fish are lists \%<#\:variables-lists>, multiple values are allowed.
One or more variable \fIINDEX\fP can be specified including ranges (not for all options.)
.sp
If no \fIVALUE\fP is given, the variable will be set to the empty list.
.sp
If \fBset\fP is ran without arguments, it prints the names and values of all shell variables in sorted order.
Passing scope \%<#\:variables-scope> or export \%<#\:variables-export> flags allows filtering this to only matching variables, so \fBset \-\-local\fP would only show local variables.
.sp
With \fB\-\-erase\fP and optionally a scope flag \fBset\fP will erase the matching variable (or the variable of that name in the smallest possible scope).
.sp
With \fB\-\-show\fP, \fBset\fP will describe the given variable names, explaining how they have been defined \- in which scope with which values and options.
.sp
The following options control variable scope:
.INDENT 0.0
.TP
\fB\-U\fP or \fB\-\-universal\fP
Sets a universal variable.
The variable will be immediately available to all the user\(aqs \fBfish\fP instances on the machine, and will be persisted across restarts of the shell.
.TP
\fB\-f\fP or \fB\-\-function\fP
Sets a variable scoped to the executing function.
It is erased when the function ends.
.TP
\fB\-l\fP or \fB\-\-local\fP
Sets a locally\-scoped variable in this block.
It is erased when the block ends.
Outside of a block, this is the same as \fB\-\-function\fP\&.
.TP
\fB\-g\fP or \fB\-\-global\fP
Sets a globally\-scoped variable.
Global variables are available to all functions running in the same shell.
They can be modified or erased.
.UNINDENT
.sp
These options modify how variables operate:
.INDENT 0.0
.TP
\fB\-\-export\fP or \fB\-x\fP
Causes the specified shell variable to be exported to child processes (making it an \(dqenvironment variable\(dq).
.TP
\fB\-\-unexport\fP or \fB\-u\fP
Causes the specified shell variable to NOT be exported to child processes.
.TP
\fB\-\-path\fP
Treat specified variable as a path variable \%<#\:variables-path>; variable will be split on colons (\fB:\fP) and will be displayed joined by colons when quoted (\fBecho \(dq$PATH\(dq\fP) or exported.
.TP
\fB\-\-unpath\fP
Causes variable to no longer be treated as a path variable \%<#\:variables-path>\&.
Note: variables ending in \(dqPATH\(dq are automatically path variables.
.UNINDENT
.sp
Further options:
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-append\fP \fINAME\fP \fIVALUE\fP ...
Appends \fIVALUES\fP to the current set of values for variable \fBNAME\fP\&.
Can be used with \fB\-\-prepend\fP to both append and prepend at the same time.
This cannot be used when assigning to a variable slice.
.TP
\fB\-p\fP or \fB\-\-prepend\fP \fINAME\fP \fIVALUE\fP ...
Prepends \fIVALUES\fP to the current set of values for variable \fBNAME\fP\&.
This can be used with \fB\-\-append\fP to both append and prepend at the same time.
This cannot be used when assigning to a variable slice.
.TP
\fB\-e\fP or \fB\-\-erase\fP \fINAME\fP[\fIINDEX\fP]
Causes the specified shell variables to be erased.
Supports erasing from multiple scopes at once.
Individual items in a variable at \fIINDEX\fP in brackets can be specified.
.TP
\fB\-q\fP or \fB\-\-query\fP \fINAME\fP[\fIINDEX\fP]
Test if the specified variable names are defined.
If an \fIINDEX\fP is provided, check for items at that slot.
With a given scope (like \fB\-\-global\fP) or attribute (like \fB\-\-export\fP or \fB\-\-path\fP) check only variables that match.
Does not output anything, but the shell status is set to the number of variables specified that were not defined, up to a maximum of 255.
If no variable was given, it also returns 255.
.TP
\fB\-n\fP or \fB\-\-names\fP
List only the names of all defined variables, not their value.
The names are guaranteed to be sorted.
.TP
\fB\-S\fP or \fB\-\-show\fP
Shows information about the given variables.
If no variable names are given then all variables are shown in sorted order.
It shows the scopes the given variables are set in, along with the values in each and whether or not it is exported.
No other flags can be used with this option.
.TP
\fB\-\-no\-event\fP
Don\(aqt generate a variable change event when setting or erasing a variable.
We recommend using this carefully because the event handlers are usually set up for a reason.
Possible uses include modifying the variable inside a variable handler.
.TP
\fB\-L\fP or \fB\-\-long\fP
Do not abbreviate long values when printing set variables.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
If a variable is set to more than one value, the variable will be a list with the specified elements.
If a variable is set to zero elements, it will become a list with zero elements.
.sp
If the variable name is one or more list elements, such as \fBPATH[1 3 7]\fP, only those list elements specified will be changed.
If you specify a negative index when expanding or assigning to a list variable, the index will be calculated from the end of the list.
For example, the index \-1 means the last index of a list.
.sp
The scoping rules when creating or updating a variable are:
.INDENT 0.0
.IP \(bu 2
Variables may be explicitly set as universal, global, function, or local.
Variables with the same name but in a different scope will not be changed.
.IP \(bu 2
If the scope of a variable is not explicitly set \fIbut a variable by that name has been previously defined\fP, the scope of the existing variable is used.
If the variable is already defined in multiple scopes, the variable with the narrowest scope will be updated.
.IP \(bu 2
If a variable\(aqs scope is not explicitly set and there is no existing variable by that name, the variable will be local to the currently executing function.
Note that this is different from using the \fB\-l\fP or \fB\-\-local\fP flag, in which case the variable will be local to the most\-inner currently executing block, while without them the variable will be local to the function as a whole.
If no function is executing, the variable will be set in the global scope.
.UNINDENT
.sp
The exporting rules when creating or updating a variable are identical to the scoping rules for variables:
.INDENT 0.0
.IP \(bu 2
Variables may be explicitly set to either exported or not exported.
When an exported variable goes out of scope, it is unexported.
.IP \(bu 2
If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept.
.IP \(bu 2
If a variable is not explicitly set to be either exported or unexported and has never before been defined, the variable will not be exported.
.UNINDENT
.sp
In query mode, the scope to be examined can be specified.
Whether the variable has to be a path variable or exported can also be specified.
.sp
In erase mode, if variable indices are specified, only the specified slices of the list variable will be erased.
.sp
\fBset\fP requires all options to come before any other arguments.
For example, \fBset flags \-l\fP will have the effect of setting the value of the variable \fBflags\fP to \(aq\-l\(aq, not making the variable local.
.SS Exit status
.sp
In assignment mode, \fBset\fP does not modify the exit status, but passes along whatever \fBstatus\fP \%<#\:envvar-status> was set, including by command substitutions.
This allows capturing the output and exit status of a subcommand, like in \fBif set output (command)\fP\&.
.sp
In query mode, the exit status is the number of variables that were not found.
.sp
In erase mode, \fBset\fP exits with a zero exit status in case of success, with a non\-zero exit status if the commandline was invalid, if any of the variables did not exist or was a special read\-only variable \%<#\:variables-special>\&.
.SS Examples
.sp
Print all global, exported variables:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-gx
.EE
.UNINDENT
.UNINDENT
.sp
Set the value of the variable _$foo_ to be \(aqhi\(aq.:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set foo hi
.EE
.UNINDENT
.UNINDENT
.sp
Append the value \(dqthere\(dq to the variable $foo:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-a foo there
.EE
.UNINDENT
.UNINDENT
.sp
Remove _$smurf_ from the scope:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-e smurf
.EE
.UNINDENT
.UNINDENT
.sp
Remove _$smurf_ from the global and universal scopes:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-e \-Ug smurf
.EE
.UNINDENT
.UNINDENT
.sp
Change the fourth element of the $PATH list to ~/bin:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set PATH[4] ~/bin
.EE
.UNINDENT
.UNINDENT
.sp
Outputs the path to Python if \fBtype \-p\fP returns true:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if set python_path (type \-p python)
echo \(dqPython is at $python_path\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
Setting a variable doesn\(aqt modify $status; a command substitution still will, though:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo $status
0
> false
> set foo bar
> echo $status
1
> true
> set foo banana (false)
> echo $status
1
.EE
.UNINDENT
.UNINDENT
.sp
\fBVAR=VALUE command\fP sets a variable for just one command, like other shells.
This runs fish with a temporary home directory:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> HOME=(mktemp \-d) fish
.EE
.UNINDENT
.UNINDENT
.sp
(which is essentially the same as):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> begin; set \-lx HOME (mktemp \-d); fish; end
.EE
.UNINDENT
.UNINDENT
.SS Notes
.INDENT 0.0
.IP \(bu 2
fish versions prior to 3.0 supported the syntax \fBset PATH[1] PATH[4] /bin /sbin\fP, which worked like \fBset PATH[1 4] /bin /sbin\fP\&.
.UNINDENT
.SS set_color \- set the terminal color
.SS Synopsis
.nf
\fBset_color\fP [\fIOPTIONS\fP] [\fIVALUE\fP]
.fi
.sp
.SS Description
.sp
\fBset_color\fP controls the color and styling of text in the terminal.
It writes non\-printing color and text style escape sequences to standard output.
.sp
\fIVALUE\fP describes the styling.
\fIVALUE\fP can be a reserved color name like \fBred\fP or an RGB color value given as 3 or 6 hexadecimal digits (\(dqF27\(dq or \(dqFF2277\(dq).
A special keyword \fBnormal\fP resets text formatting to terminal defaults, however it is not recommended and the \fB\-\-reset\fP option is preferred as it is less confusing and more future\-proof.
.sp
Valid colors include:
.INDENT 0.0
.INDENT 3.5
.INDENT 0.0
.IP \(bu 2
\fBblack\fP, \fBred\fP, \fBgreen\fP, \fByellow\fP, \fBblue\fP, \fBmagenta\fP, \fBcyan\fP, \fBwhite\fP
.IP \(bu 2
\fBbrblack\fP, \fBbrred\fP, \fBbrgreen\fP, \fBbryellow\fP, \fBbrblue\fP, \fBbrmagenta\fP, \fBbrcyan\fP, \fBbrwhite\fP
.UNINDENT
.UNINDENT
.UNINDENT
.sp
The \fIbr\fP\- (as in \(aqbright\(aq) forms are full\-brightness variants of the 8 standard\-brightness colors on many terminals. \fBbrblack\fP has higher brightness than \fBblack\fP \- towards gray.
.sp
An RGB value with three or six hex digits, such as A0FF33 or f2f can be used.
A three digit value is equivalent to specifying each digit twice; e.g., \fBset_color 2BC\fP is the same as \fBset_color 22BBCC\fP\&.
Hexadecimal RGB values can be in lower or uppercase.
.sp
If \fBfish_term24bit\fP \%<#\:envvar-fish_term24bit> is set to 0, fish will translate RGB values to the nearest color on the 256\-color palette.
If \fBfish_term256\fP \%<#\:envvar-fish_term256> is also set to 0, fish will translate them to the 16\-color palette instead.
fish launched as \fBfish \-d term_support\fP will include diagnostic messages that indicate the color support mode in use.
.sp
If multiple colors are specified, fish prefers the first RGB one.
However if \fBfish_term256\fP \%<#\:envvar-fish_term256> is set to 0, fish prefers the first named color specified.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-f\fP or \fB\-\-foreground\fP \fICOLOR\fP
Sets the foreground color.
This is equivalent to calling \fBset_color COLOR\fP with the exception that the keyword \fBnormal\fP will only reset the foreground color to its default, instead of all colors and modes.
It cannot be used with \fIVALUE\fP or \fB\-\-print\-colors\fP\&.
.TP
\fB\-b\fP or \fB\-\-background\fP \fICOLOR\fP
Sets the background color.
.TP
\fB\-\-underline\-color\fP \fICOLOR\fP
Set the underline color.
.TP
\fB\-c\fP or \fB\-\-print\-colors\fP
Prints the given colors or a colored list of the 16 named colors.
It cannot be used with \fB\-\-foreground\fP\&.
.TP
\fB\-o\fP or \fB\-\-bold\fP
Sets bold mode.
.TP
\fB\-d\fP or \fB\-\-dim\fP
Sets dim mode.
.TP
\fB\-i\fP or \fB\-\-italics\fP, or \fB\-iSTATE\fP or \fB\-\-italics=STATE\fP
Sets italics mode. The state can be \fBon\fP (default), or \fBoff\fP\&.
.TP
\fB\-r\fP or \fB\-\-reverse\fP, or \fB\-rSTATE\fP or \fB\-\-reverse=STATE\fP
Sets reverse mode. The state can be \fBon\fP (default), or \fBoff\fP\&.
.TP
\fB\-s\fP or \fB\-\-strikethrough\fP, or \fB\-sSTATE\fP or \fB\-\-strikethrough=STATE\fP
Sets strikethrough mode. The state can be \fBon\fP (default), or \fBoff\fP\&.
.TP
\fB\-u\fP or \fB\-\-underline\fP, or \fB\-uSTYLE\fP or \fB\-\-underline=STYLE\fP
Set the underline mode; supported styles are \fBsingle\fP (default), \fBdouble\fP, \fBcurly\fP, \fBdotted\fP, \fBdashed\fP and \fBoff\fP\&.
.TP
\fB\-\-reset\fP
Reset the text formatting to the terminal defaults before applying the new colors and modes.
This is equivalent to calling \fBset_color normal\fP except that it is possible to set the foreground color in the same call (e.g. \fBset_color \-\-reset green\fP)
.TP
\fB\-\-theme=THEME\fP
Ignored.
Color variables \%<#\:variables-color> that contain only this option are treated like missing / empty color variables,
i.e. fish will use the fallback color instead.
fish_config theme choose \%<> erases all color variable \%<#\:fish-config-color-variables>
whose value includes this option, and adds this option to all color variables it sets.
This allows identifying variables set by a theme,
and it allows fish to update color variables whenever \fBfish_terminal_color_theme\fP \%<#\:envvar-fish_terminal_color_theme> changes.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.SS Notes
.INDENT 0.0
.IP 1. 3
Using \fBset_color normal\fP will reset all colors and modes to the terminal\(aqs default.
.IP 2. 3
In contrast, \fBset_color \-\-foreground normal\fP will only reset the foreground color and leave all the other colors and modes unchanged.
.IP 3. 3
Because of the risk of confusion, \fBset_color \-\-reset\fP is recommended over \fBset_color normal\fP\&.
.IP 4. 3
Setting the background color only affects subsequently written characters. fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. Look for a config option.
.IP 5. 3
Some terminals use the \fB\-\-bold\fP escape sequence to switch to a brighter color set rather than increasing the weight of text.
.IP 6. 3
If you use \fBset_color\fP in a command substitution or a pipe, these characters will also be captured.
This may or may not be desirable.
Checking the exit status of \fBisatty stdout\fP before using \fBset_color\fP can be useful to decide not to colorize output in a script.
.UNINDENT
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set_color red; echo \(dqRoses are red\(dq
set_color blue; echo \(dqViolets are blue\(dq
set_color 62A; echo \(dqEggplants are dark purple\(dq
set_color normal; echo \(dqNormal is nice\(dq # Resets the background too
.EE
.UNINDENT
.UNINDENT
.SS source \- evaluate contents of file
.SS Synopsis
.nf
\fBsource\fP \fIFILE\fP [\fIARGUMENTS\fP \&...]
\fISOMECOMMAND\fP | \fBsource\fP
\fB\&. \fP\fIFILE\fP [\fIARGUMENTS\fP \&...]
.fi
.sp
.SS Description
.sp
\fBsource\fP evaluates the commands of the specified \fIFILE\fP in the current shell as a new block of code. This is different from starting a new process to perform the commands (i.e. \fBfish < FILE\fP) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the \fBargv\fP \%<#\:envvar-argv> variable. The \fBargv\fP \%<#\:envvar-argv> variable will not include the name of the sourced file.
.sp
fish will search the working directory to resolve relative paths but will not search \fBPATH\fP \%<#\:envvar-PATH> .
.sp
If no file is specified and a file or pipeline is connected to standard input, or if the file name \fB\-\fP is used, \fBsource\fP will read from standard input. If no file is specified and there is no redirected file or pipeline on standard input, an error will be printed.
.sp
The exit status of \fBsource\fP is the exit status of the last job to execute. If something goes wrong while opening or reading the file, \fBsource\fP exits with a non\-zero status.
.sp
Some other shells only support the \fB\&.\fP alias (a single period).
The use of \fB\&.\fP is deprecated in favour of \fBsource\fP, and \fB\&.\fP will be removed in a future version of fish.
.sp
\fBsource\fP creates a new local scope \%<#\:variables-scope>; \fBset \-\-local\fP within a sourced block will not affect variables in the enclosing scope.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
source ~/.config/fish/config.fish
# Causes fish to re\-read its initialization file.
.EE
.UNINDENT
.UNINDENT
.SS status \- query fish runtime information
.SS Synopsis
.nf
\fBstatus\fP
\fBstatus\fP \fBis\-login\fP
\fBstatus\fP \fBis\-interactive\fP
\fBstatus\fP \fBis\-interactive\-read\fP
\fBstatus\fP \fBis\-block\fP
\fBstatus\fP \fBis\-breakpoint\fP
\fBstatus\fP \fBis\-command\-substitution\fP
\fBstatus\fP \fBis\-no\-job\-control\fP
\fBstatus\fP \fBis\-full\-job\-control\fP
\fBstatus\fP \fBis\-interactive\-job\-control\fP
\fBstatus\fP \fBcurrent\-command\fP
\fBstatus\fP \fBcurrent\-commandline\fP
\fBstatus\fP \fBfilename\fP
\fBstatus\fP \fBbasename\fP
\fBstatus\fP \fBdirname\fP
\fBstatus\fP \fBfish\-path\fP
\fBstatus\fP \fBfunction\fP
\fBstatus\fP \fBline\-number\fP
\fBstatus\fP \fBstack\-trace\fP
\fBstatus\fP \fBjob\-control\fP \fICONTROL_TYPE\fP
\fBstatus\fP \fBfeatures\fP
\fBstatus\fP \fBtest\-feature\fP \fIFEATURE\fP
\fBstatus\fP \fBbuild\-info\fP
\fBstatus\fP \fBget\-file\fP \fIFILE\fP
\fBstatus\fP \fBlist\-files\fP [\fIPATH\fP \&...]
\fBstatus\fP \fBterminal\fP
\fBstatus\fP \fBtest\-terminal\-feature\fP \fIFEATURE\fP
\fBstatus\fP \fBlanguage\fP [\fBlist\-available\fP|\fBset\fP [\fILANGUAGE\fP \&...]|\fBunset\fP]
.fi
.sp
.SS Description
.sp
With no arguments, \fBstatus\fP displays a summary of the current login and job control status of the shell.
.sp
The following operations (subcommands) are available:
.INDENT 0.0
.TP
\fBis\-command\-substitution\fP, \fB\-c\fP or \fB\-\-is\-command\-substitution\fP
Returns 0 if fish is currently executing a command substitution.
.TP
\fBis\-block\fP, \fB\-b\fP or \fB\-\-is\-block\fP
Returns 0 if fish is currently executing a block of code.
.TP
\fBis\-breakpoint\fP
Returns 0 if fish is currently showing a prompt in the context of a breakpoint \%<> command. See also the fish_breakpoint_prompt \%<> function.
.TP
\fBis\-interactive\fP, \fB\-i\fP or \fB\-\-is\-interactive\fP
Returns 0 if fish is interactive \- that is, connected to a keyboard.
.TP
\fBis\-interactive\-read\fP or \fB\-\-is\-interactive\-read\fP
Returns 0 if fish is running an interactive read \%<> builtin which is connected to a keyboard.
.TP
\fBis\-login\fP, \fB\-l\fP or \fB\-\-is\-login\fP
Returns 0 if fish is a login shell \- that is, if fish should perform login tasks such as setting up \fBPATH\fP \%<#\:envvar-PATH>\&.
.TP
\fBis\-full\-job\-control\fP or \fB\-\-is\-full\-job\-control\fP
Returns 0 if full job control is enabled.
.TP
\fBis\-interactive\-job\-control\fP or \fB\-\-is\-interactive\-job\-control\fP
Returns 0 if interactive job control is enabled.
.TP
\fBis\-no\-job\-control\fP or \fB\-\-is\-no\-job\-control\fP
Returns 0 if no job control is enabled.
.TP
\fBcurrent\-command\fP
Prints the name of the currently\-running function or command, like the deprecated \fB_\fP \%<#\:envvar-_> variable.
.TP
\fBcurrent\-commandline\fP
Prints the entirety of the currently\-running commandline, inclusive of all jobs and operators.
.TP
\fBfilename\fP, \fBcurrent\-filename\fP, \fB\-f\fP or \fB\-\-current\-filename\fP
Prints the filename of the currently\-running script. If the current script was called via a symlink, this will return the symlink. If the current script was received by piping into source \%<>, then this will return \fB\-\fP\&.
.TP
\fBbasename\fP
Prints just the filename of the running script, without any path components before.
.TP
\fBdirname\fP
Prints just the path to the running script, without the actual filename itself. This can be relative to \fBPWD\fP \%<#\:envvar-PWD> (including just \(dq.\(dq), depending on how the script was called. This is the same as passing the filename to \fBdirname(3)\fP\&. It\(aqs useful if you want to use other files in the current script\(aqs directory or similar.
.TP
\fBfish\-path\fP
Prints the absolute path to the currently executing instance of fish. This is a best\-effort attempt and the exact output is down to what the platform gives fish. In some cases you might only get \(dqfish\(dq.
.TP
\fBfunction\fP or \fBcurrent\-function\fP
Prints the name of the currently called function if able, when missing displays \(dqNot a function\(dq (or equivalent translated string).
.TP
\fBline\-number\fP, \fBcurrent\-line\-number\fP, \fB\-n\fP or \fB\-\-current\-line\-number\fP
Prints the line number of the currently running script.
.TP
\fBstack\-trace\fP, \fBprint\-stack\-trace\fP, \fB\-t\fP or \fB\-\-print\-stack\-trace\fP
Prints a stack trace of all function calls on the call stack.
.TP
\fBjob\-control\fP, \fB\-j\fP or \fB\-\-job\-control\fP \fICONTROL_TYPE\fP
Sets the job control type to \fICONTROL_TYPE\fP, which can be \fBnone\fP, \fBfull\fP, or \fBinteractive\fP\&.
.TP
\fBfeatures\fP
Lists all available feature flags \%<#\:featureflags>\&.
.TP
\fBtest\-feature\fP \fIFEATURE\fP
Returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized.
.TP
\fBbuild\-info\fP
This prints information on how fish was build \- which architecture, which build system or profile was used, etc.
This is mainly useful for debugging.
.UNINDENT
.INDENT 0.0
.TP
\fBget\-file\fP \fIFILE\fP
This prints a file embedded in the fish binary at compile time. This includes the default set of functions and completions,
as well as the man pages and themes. Which files are included depends on build settings.
Returns 0 if the file was included, 1 otherwise.
.TP
\fBlist\-files\fP \fIFILE...\fP
This lists the files embedded in the fish binary at compile time. Only files where the path starts with the optional \fIFILE\fP argument are shown.
Returns 0 if something was printed, 1 otherwise.
.UNINDENT
.INDENT 0.0
.TP
\fBterminal\fP
Prints the name and version of the terminal fish is running inside (for example as reported via XTVERSION \%<#\:term-compat-xtversion>).
This is not available during early startup but only starting from when the first interactive prompt is shown, possibly via builtin read \%<>,
so before the first \fBfish_prompt\fP or \fBfish_read\fP event \%<#\:event>\&.
.UNINDENT
.INDENT 0.0
.TP
\fBterminal\-os\fP
Prints the name of the operating system (OS) the terminal is running on, as reported via XTGETTCAP query\-os\-name \%<#\:term-compat-xtgettcap>\&.
Like status terminal, this only works once the first interactive prompt is shown.
Returns 1 if the OS name is not available.
.UNINDENT
.INDENT 0.0
.TP
\fBtest\-terminal\-feature\fP \fIFEATURE\fP
Returns 0 when the terminal was detected \%<#\:term-compat-xtgettcap> to support the given feature.
Like status terminal, this only works once the first interactive prompt is shown.
.sp
Currently the only available \fIFEATURE\fP is scroll\-content\-up \%<#\:term-compat-indn>\&.
An error will be printed when passed an unrecognized feature.
.UNINDENT
.INDENT 0.0
.TP
\fBlanguage\fP
Show or modify message localization settings.
When invoked without arguments, the current language settings are shown.
.sp
Available subcommands:
.sp
\fBlist\-available\fP
prints the language names for which fish has translations.
These names can be used with the \fBset\fP subcommand.
.sp
\fBset\fP
sets the language precedence for fish\(aqs messages.
Overrides language settings configured via environment variables \%<#\:variables-locale>, but only applies to fish itself, not to any child processes.
Takes a list of language names from the set shown by the \fBlist\-available\fP subcommand.
For some languages, fish\(aqs translation catalogs are incomplete, meaning not all messages can be shown in these languages.
Therefore, we allow specifying a list here, with translations taken from the first specified language which has a translation available for a message.
For example, after running \fBstatus language set pt_BR fr\fP, all messages which have a translation into Brazilian Portuguese will be shown in that language.
The remaining messages will be shown in French, if a French translation is available.
If none of the specified languages have a translation available for a message, the message will be shown in English.
.sp
\fBunset\fP
undoes the effects of the \fBset\fP subcommand.
Language settings will be taken from environment variables again.
.UNINDENT
.SS Notes
.sp
For backwards compatibility most subcommands can also be specified as a long or short option. For example, rather than \fBstatus is\-login\fP you can type \fBstatus \-\-is\-login\fP\&. The flag forms are deprecated and may be removed in a future release.
.sp
You can only specify one subcommand per invocation even if you use the flag form of the subcommand.
.SS string \- manipulate strings
.SS Synopsis
.nf
\fBstring\fP \fBcollect\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP] [\fB\-N\fP | \fB\-\-no\-trim\-newlines\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBescape\fP [\fB\-n\fP | \fB\-\-no\-quoted\fP] [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBjoin\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBjoin0\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBlength\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBlower\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBmatch\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-e\fP | \fB\-\-entire\fP] [\fB\-i\fP | \fB\-\-ignore\-case\fP]
[\fB\-g\fP | \fB\-\-groups\-only\fP] [\fB\-r\fP | \fB\-\-regex\fP] [\fB\-n\fP | \fB\-\-index\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-v\fP | \fB\-\-invert\fP]
\fIPATTERN\fP [\fISTRING\fP \&...]
\fBstring\fP \fBpad\fP [\fB\-r\fP | \fB\-\-right\fP] [\fB\-C\fP | \fB\-\-center\fP] [(\fB\-c\fP | \fB\-\-char\fP) \fICHAR\fP] [(\fB\-w\fP | \fB\-\-width\fP) \fIINTEGER\fP]
[\fISTRING\fP \&...]
\fBstring\fP \fBrepeat\fP [(\fB\-n\fP | \fB\-\-count\fP) \fICOUNT\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-N\fP | \fB\-\-no\-newline\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBrepeat\fP [\fB\-N\fP | \fB\-\-no\-newline\fP] [\fB\-q\fP | \fB\-\-quiet\fP] \fICOUNT\fP [\fISTRING\fP \&...]
\fBstring\fP \fBreplace\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-f\fP | \fB\-\-filter\fP] [\fB\-i\fP | \fB\-\-ignore\-case\fP]
[\fB\-r\fP | \fB\-\-regex\fP] [\fB\-q\fP | \fB\-\-quiet\fP] \fIPATTERN\fP \fIREPLACE\fP [\fISTRING\fP \&...]
\fBstring\fP \fBshorten\fP [(\fB\-c\fP | \fB\-\-char\fP) \fICHARS\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIINTEGER\fP]
[\fB\-N\fP | \fB\-\-no\-newline\fP] [\fB\-l\fP | \fB\-\-left\fP] [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBsplit\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBsplit0\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBsub\fP [(\fB\-s\fP | \fB\-\-start\fP) \fISTART\fP] [(\fB\-e\fP | \fB\-\-end\fP) \fIEND\fP] [(\fB\-l\fP | \fB\-\-length\fP) \fILENGTH\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBtrim\fP [\fB\-l\fP | \fB\-\-left\fP] [\fB\-r\fP | \fB\-\-right\fP] [(\fB\-c\fP | \fB\-\-chars\fP) \fICHARS\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBunescape\fP [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBupper\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring\fP performs operations on strings.
.sp
\fISTRING\fP arguments are taken from the command line unless standard input is connected to a pipe or a file, in which case they are read from standard input, one \fISTRING\fP per line. It is an error to supply \fISTRING\fP arguments on the command line and on standard input.
.sp
Arguments beginning with \fB\-\fP are normally interpreted as switches; \fB\-\-\fP causes the following arguments not to be treated as switches even if they begin with \fB\-\fP\&. Switches and required arguments are recognized only on the command line.
.sp
Most subcommands accept a \fB\-q\fP or \fB\-\-quiet\fP switch, which suppresses the usual output but exits with the documented status. In this case these commands will quit early, without reading all of the available input.
.sp
The following subcommands are available.
.SS \(dqcollect\(dq subcommand
.nf
\fBstring\fP \fBcollect\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP] [\fB\-N\fP | \fB\-\-no\-trim\-newlines\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring collect\fP collects its input into a single output argument, without splitting the output when used in a command substitution. This is useful when trying to collect multiline output from another command into a variable. Exit status: 0 if any output argument is non\-empty, or 1 otherwise.
.sp
A command like \fBecho (cmd | string collect)\fP is mostly equivalent to a quoted command substitution (\fBecho \(dq$(cmd)\(dq\fP). The main difference is that the former evaluates to zero or one elements whereas the quoted command substitution always evaluates to one element due to string interpolation.
.sp
If invoked with multiple arguments instead of input, \fBstring collect\fP preserves each argument separately, where the number of output arguments is equal to the number of arguments given to \fBstring collect\fP\&.
.sp
Any trailing newlines on the input are trimmed, just as with \fB\(dq$(cmd)\(dq\fP substitution. Use \fB\-\-no\-trim\-newlines\fP to disable this behavior, which may be useful when running a command such as \fBset contents (cat filename | string collect \-N)\fP\&.
.sp
With \fB\-\-allow\-empty\fP, \fBstring collect\fP always prints one (empty) argument. This can be used to prevent an argument from disappearing.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ echo \(dqzero $(echo one\entwo\enthree) four\(dq
zero one
two
three four
>_ echo \e\(dq(echo one\entwo\enthree | string collect)\e\(dq
\(dqone
two
three\(dq
>_ echo \e\(dq(echo one\entwo\enthree | string collect \-N)\e\(dq
\(dqone
two
three
\(dq
>_ echo foo(true | string collect \-\-allow\-empty)bar
foobar
.EE
.UNINDENT
.UNINDENT
.SS \(dqescape\(dq and \(dqunescape\(dq subcommands
.nf
\fBstring\fP \fBescape\fP [\fB\-n\fP | \fB\-\-no\-quoted\fP] [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBunescape\fP [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring escape\fP escapes each \fISTRING\fP in one of several ways.
.sp
\fB\-\-style=script\fP (default) alters the string such that it can be passed back to \fBeval\fP to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If \fB\-n\fP or \fB\-\-no\-quoted\fP is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise.
.sp
\fB\-\-style=var\fP ensures the string can be used as a variable name by hex encoding any non\-alphanumeric characters. The string is first converted to UTF\-8 before being encoded.
.sp
\fB\-\-style=url\fP ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF\-8 before being encoded.
.sp
\fB\-\-style=regex\fP escapes an input string for literal matching within a regex expression. The string is first converted to UTF\-8 before being encoded.
.sp
\fBstring unescape\fP performs the inverse of the \fBstring escape\fP command. If the string to be unescaped is not properly formatted it is ignored. For example, doing \fBstring unescape \-\-style=var (string escape \-\-style=var $str)\fP will return the original string. There is no support for unescaping \fB\-\-style=regex\fP\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ echo \ex07 | string escape
\ecg
>_ string escape \-\-style=var \(aqa1 b2\(aq\eu6161
a1_20_b2_E6_85_A1_
.EE
.UNINDENT
.UNINDENT
.SS \(dqjoin\(dq and \(dqjoin0\(dq subcommands
.nf
\fBstring\fP \fBjoin\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fB\-\-\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBjoin0\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fB\-\-\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
Joins its \fISTRING\fP arguments into a single string separated by \fISEP\fP (for \fBstring join\fP) or by the
zero byte (NUL) (for \fBstring join0\fP).
Exit status: 0 if at least one join was performed, or 1 otherwise.
.INDENT 0.0
.TP
\fB\-n\fP, \fB\-\-no\-empty\fP
Exclude empty strings from consideration (e.g. \fBstring join \-n + a b \(dq\(dq c\fP would expand to \fBa+b+c\fP not \fBa+b++c\fP).
.TP
\fB\-q\fP, \fB\-\-quiet\fP
Do not print the strings, only set the exit status as described above.
.UNINDENT
.sp
\fBWARNING\fP:
Insert a \fB\-\-\fP before positional arguments to prevent them from being interpreted as flags.
Otherwise, any strings starting with \fB\-\fP will be treated as flag arguments, meaning they will most likely result in the command failing.
This is also true if you specify a variable which expands to such a string instead of a literal string.
If you don\(aqt need to append flag arguments at the end of the command,
just always use \fB\-\-\fP to avoid unwelcome surprises.
.sp
\fBstring join0\fP adds a trailing NUL. This is most useful in conjunction with tools that accept NUL\-delimited input, such as \fBsort \-z\fP\&.
.sp
Because Unix uses NUL as the string terminator, passing the output of \fBstring join0\fP as an \fIargument\fP to a command (via a command substitution \%<#\:expand-command-substitution>) won\(aqt actually work.
fish will pass the correct bytes along, but the command won\(aqt be able to tell where the argument ends.
This is a limitation of Unix\(aq argument passing.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ seq 3 | string join ...
1...2...3
# Give a list of NUL\-separated filenames to du (this is a GNU extension)
>_ string join0 file1 file2 file\enwith\enmultiple\enlines | du \-\-files0\-from=\-
# Just put the strings together without a separator
>_ string join \(aq\(aq a b c
abc
>_ set \-l markdown_list \(aq\- first\(aq \(aq\- second\(aq \(aq\- third\(aq
# Strings with leading hyphens (also in variable expansions) are interpreted as flag arguments by default.
>_ string join \en $markdown_list
string join: \- first: unknown option
# Use \(aq\-\-\(aq to prevent this.
>_ string join \-\- \en $markdown_list
\- first
\- second
\- third
.EE
.UNINDENT
.UNINDENT
.SS \(dqlength\(dq subcommand
.nf
\fBstring\fP \fBlength\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-V\fP | \fB\-\-visible\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring length\fP reports the length of each string argument in characters. Exit status: 0 if at least one non\-empty \fISTRING\fP was given, or 1 otherwise.
.sp
With \fB\-V\fP or \fB\-\-visible\fP, it uses the visible width of the arguments. That means it will discount escape sequences fish knows about, account for $fish_emoji_width and $fish_ambiguous_width. It will also count each line (separated by \fB\en\fP) on its own, and with a carriage return (\fB\er\fP) count only the widest stretch on a line. The intent is to measure the number of columns the \fISTRING\fP would occupy in the current terminal.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string length \(aqhello, world\(aq
12
>_ set str foo
>_ string length \-q $str; echo $status
0
# Equivalent to test \-n \(dq$str\(dq
>_ string length \-\-visible (set_color red)foobar
# the set_color is discounted, so this is the width of \(dqfoobar\(dq
6
>_ string length \-\-visible 🐟🐟🐟🐟
# depending on $fish_emoji_width, this is either 4 or 8
# in new terminals it should be
8
>_ string length \-\-visible abcdef\er123
# this displays as \(dq123def\(dq, so the width is 6
6
>_ string length \-\-visible a\enbc
# counts \(dqa\(dq and \(dqbc\(dq as separate lines, so it prints width for each
1
2
.EE
.UNINDENT
.UNINDENT
.SS \(dqlower\(dq subcommand
.nf
\fBstring\fP \fBlower\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring lower\fP converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the \fB\-q\fP flag you can readily test whether a string is already lowercase.
.SS \(dqmatch\(dq subcommand
.nf
\fBstring\fP \fBmatch\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-e\fP | \fB\-\-entire\fP] [\fB\-i\fP | \fB\-\-ignore\-case\fP]
[\fB\-g\fP | \fB\-\-groups\-only\fP] [\fB\-r\fP | \fB\-\-regex\fP] [\fB\-n\fP | \fB\-\-index\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-v\fP | \fB\-\-invert\fP] [(\fB\-m\fP | \fB\-\-max\-matches\fP) \fIMAX\fP]
\fIPATTERN\fP [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring match\fP tests each \fISTRING\fP against \fIPATTERN\fP and prints matching substrings. Only the first match for each \fISTRING\fP is reported unless \fB\-a\fP or \fB\-\-all\fP is given, in which case all matches are reported.
.sp
If you specify the \fB\-e\fP or \fB\-\-entire\fP then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to \fBgrep\fP without the \fB\-o\fP flag). You can, obviously, achieve the same result by prepending and appending \fB*\fP or \fB\&.*\fP depending on whether or not you have specified the \fB\-\-regex\fP flag. The \fB\-\-entire\fP flag is a way to avoid having to complicate the pattern in that fashion and make the intent of the \fBstring match\fP clearer. Without \fB\-\-entire\fP and \fB\-\-regex\fP, a \fIPATTERN\fP will need to match the entire \fISTRING\fP before it will be reported.
.sp
Matching can be made case\-insensitive with \fB\-\-ignore\-case\fP or \fB\-i\fP\&.
.sp
If \fB\-\-groups\-only\fP or \fB\-g\fP is given, only the capturing groups will be reported \- meaning the full match will be skipped. This is incompatible with \fB\-\-entire\fP and \fB\-\-invert\fP, and requires \fB\-\-regex\fP\&. It is useful as a simple cutting tool instead of \fBstring replace\fP, so you can choose \(dqthis part\(dq of a string.
.sp
If \fB\-\-index\fP or \fB\-n\fP is given, each match is reported as a 1\-based start position and a length. By default, PATTERN is interpreted as a glob pattern matched against each entire \fISTRING\fP argument. A glob pattern is only considered a valid match if it matches the entire \fISTRING\fP\&.
.sp
If \fB\-\-regex\fP or \fB\-r\fP is given, \fIPATTERN\fP is interpreted as a Perl\-compatible regular expression, which does not have to match the entire \fISTRING\fP\&. For a regular expression containing capturing groups, multiple items will be reported for each match, one for the entire match and one for each capturing group. With this, only the matching part of the \fISTRING\fP will be reported, unless \fB\-\-entire\fP is given.
.sp
When matching via regular expressions, \fBstring match\fP automatically sets variables for all named capturing groups (\fB(?expression)\fP). It will create a variable with the name of the group, in the default scope, for each named capturing group, and set it to the value of the capturing group in the first matched argument. If a named capture group matched an empty string, the variable will be set to the empty string (like \fBset var \(dq\(dq\fP). If it did not match, the variable will be set to nothing (like \fBset var\fP). When \fB\-\-regex\fP is used with \fB\-\-all\fP, this behavior changes. Each named variable will contain a list of matches, with the first match contained in the first element, the second match in the second, and so on. If the group was empty or did not match, the corresponding element will be an empty string.
.sp
If \fB\-\-invert\fP or \fB\-v\fP is used the selected lines will be only those which do not match the given glob pattern or regular expression.
.sp
If \fB\-\-max\-matches MAX\fP or \fB\-m MAX\fP is used, \fBstring\fP will stop checking for matches after MAX lines of input have matched. This can be used as an \(dqearly exit\(dq optimization when processing long inputs but expecting a limited and fixed number of outputs that might be found considerably before the input stream has been exhausted. If combined with \fB\-\-invert\fP or \fB\-v\fP, considers only inverted matches.
.sp
Exit status: 0 if at least one match was found, or 1 otherwise.
.SS Match Glob Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string match \(aqa\(aq a
a
>_ string match \(aqa*b\(aq axxb
axxb
>_ string match \-i \(aqa*B\(aq Axxb
Axxb
>_ string match \-\- \(aq\-*\(aq \-h foo \-\-version bar
# To match things that look like options, we need a \(ga\-\-\(ga
# to tell string its options end there.
\-h
\-\-version
>_ echo \(aqok?\(aq | string match \(aq*?\(aq
ok?
# Note that only the second STRING will match here.
>_ string match \(aqfoo\(aq \(aqfoo1\(aq \(aqfoo\(aq \(aqfoo2\(aq
foo
>_ string match \-e \(aqfoo\(aq \(aqfoo1\(aq \(aqfoo\(aq \(aqfoo2\(aq
foo1
foo
foo2
>_ string match \(aqfoo*\(aq \(aqfoo1\(aq \(aqfoo\(aq \(aqfoo2\(aq
foo1
foo2
.EE
.UNINDENT
.UNINDENT
.SS Match Regex Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string match \-r \(aqcat|dog|fish\(aq \(aqnice dog\(aq
dog
>_ string match \-r \-v \(dqc.*[12]\(dq {cat,dog}(seq 1 4)
dog1
dog2
cat3
dog3
cat4
dog4
>_ string match \-r \-\- \(aq\-.*\(aq \-h foo \-\-version bar
# To match things that look like options, we need a \(ga\-\-\(ga
# to tell string its options end there.
\-h
\-\-version
>_ string match \-r \(aq(\ed\ed?):(\ed\ed):(\ed\ed)\(aq 2:34:56
2:34:56
2
34
56
>_ string match \-r \(aq^(\ew{2,4})\e1$\(aq papa mud murmur
papa
pa
murmur
mur
>_ string match \-r \-a \-n at ratatat
2 2
4 2
6 2
>_ string match \-r \-i \(aq0x[0\-9a\-f]{1,8}\(aq \(aqint magic = 0xBadC0de;\(aq
0xBadC0de
>_ echo $version
3.1.2\-1575\-ga2ff32d90
>_ string match \-rq \(aq(?\ed+).(?\ed+).(?\ed+)\(aq \-\- $version
>_ echo \(dqYou are using fish $major!\(dq
You are using fish 3!
>_ string match \-raq \(aq *(?[^.!?]+)(?[.!?])?\(aq \(dqhello, friend. goodbye\(dq
>_ printf \(dq%s\en\(dq \-\- $sentence
hello, friend
goodbye
>_ printf \(dq%s\en\(dq \-\- $punctuation
\&.
>_ string match \-rq \(aq(?hello)\(aq \(aqhi\(aq
>_ count $word
0
.EE
.UNINDENT
.UNINDENT
.SS \(dqpad\(dq subcommand
.nf
\fBstring\fP \fBpad\fP [\fB\-r\fP | \fB\-\-right\fP] [\fB\-C\fP | \fB\-\-center\fP] [(\fB\-c\fP | \fB\-\-char\fP) \fICHAR\fP] [(\fB\-w\fP | \fB\-\-width\fP) \fIINTEGER\fP]
[\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring pad\fP extends each \fISTRING\fP to the given visible width by adding \fICHAR\fP to the left. That means the width of all visible characters added together, excluding escape sequences and accounting for \fBfish_emoji_width\fP \%<#\:envvar-fish_emoji_width> and \fBfish_ambiguous_width\fP \%<#\:envvar-fish_ambiguous_width>\&. It is the amount of columns in a terminal the \fISTRING\fP occupies.
.sp
The escape sequences reflect what fish knows about, and how it computes its output. Your terminal might support more escapes, or not support escape sequences that fish knows about.
.sp
If \fB\-C\fP or \fB\-\-center\fP is given, add the padding to before and after the string. If it is impossible to perfectly center the result (because the required amount of padding is an odd number), extra padding will be added to the left, unless \fB\-\-right\fP is also given.
.sp
If \fB\-r\fP or \fB\-\-right\fP is given, add the padding after a string.
.sp
If \fB\-c\fP or \fB\-\-char\fP is given, pad with \fICHAR\fP instead of whitespace.
.sp
The output is padded to the maximum width of all input strings. If \fB\-w\fP or \fB\-\-width\fP is given, use at least that.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string pad \-w 10 abc abcdef
abc
abcdef
>_ string pad \-\-right \-\-char=🐟 \(dqfish are pretty\(dq \(dqrich. \(dq
fish are pretty
rich. 🐟🐟🐟🐟
>_ string pad \-w$COLUMNS (date)
# Prints the current time on the right edge of the screen.
.EE
.UNINDENT
.UNINDENT
.SS See also
.INDENT 0.0
.IP \(bu 2
The printf \%<> command can do simple padding, for example \fBprintf %10s\en\fP works like \fBstring pad \-w10\fP\&.
.IP \(bu 2
string length \%<> with the \fB\-\-visible\fP option can be used to show what fish thinks the width is.
.UNINDENT
.SS \(dqshorten\(dq subcommand
.nf
\fBstring\fP \fBshorten\fP [(\fB\-c\fP | \fB\-\-char\fP) \fICHARS\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIINTEGER\fP]
[\fB\-N\fP | \fB\-\-no\-newline\fP] [\fB\-l\fP | \fB\-\-left\fP] [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring shorten\fP truncates each \fISTRING\fP to the given visible width and adds an ellipsis to indicate it. \(dqVisible width\(dq means the width of all visible characters added together, excluding escape sequences and accounting for \fBfish_emoji_width\fP \%<#\:envvar-fish_emoji_width> and \fBfish_ambiguous_width\fP \%<#\:envvar-fish_ambiguous_width>\&. It is the amount of columns in a terminal the \fISTRING\fP occupies.
.sp
The escape sequences reflect what fish knows about, and how it computes its output. Your terminal might support more escapes, or not support escape sequences that fish knows about.
.sp
If \fB\-m\fP or \fB\-\-max\fP is given, truncate at the given width. Otherwise, the lowest non\-zero width of all input strings is used. A max of 0 means no shortening takes place, all STRINGs are printed as\-is.
.sp
If \fB\-N\fP or \fB\-\-no\-newline\fP is given, only the first line (or last line with \fB\-\-left\fP) of each STRING is used, and an ellipsis is added if it was multiline. This only works for STRINGs being given as arguments, multiple lines given on stdin will be interpreted as separate STRINGs instead.
.sp
If \fB\-c\fP or \fB\-\-char\fP is given, add \fICHAR\fP instead of an ellipsis. This can also be empty or more than one character.
.sp
If \fB\-l\fP or \fB\-\-left\fP is given, remove text from the left on instead, so this prints the longest \fIsuffix\fP of the string that fits. With \fB\-\-no\-newline\fP, this will take from the last line instead of the first.
.sp
If \fB\-q\fP or \fB\-\-quiet\fP is given, \fBstring shorten\fP only runs for the return value \- if anything would be shortened, it returns 0, else 1.
.sp
The default ellipsis is \fB…\fP\&. If fish thinks your system is incapable because of your locale, it will use \fB\&...\fP instead.
.sp
The return value is 0 if any shortening occurred, 1 otherwise.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string shorten foo foobar
# No width was given, we infer, and \(dqfoo\(dq is the shortest.
foo
fo…
>_ string shorten \-\-char=\(dq...\(dq foo foobar
# The target width is 3 because of \(dqfoo\(dq,
# and our ellipsis is 3 too, so we can\(aqt really show anything.
# This is the default ellipsis if your locale doesn\(aqt allow \(dq…\(dq.
foo
\&...
>_ string shorten \-\-char=\(dq\(dq \-\-max 4 abcdef 123456
# Leaving the char empty makes us not add an ellipsis
# So this truncates at 4 columns:
abcd
1234
>_ touch \(dqa multiline\(dq\en\(dqfile\(dq
>_ for file in *; string shorten \-N \-\- $file; end
# Shorten the multiline file so we only show one line per file:
a multiline…
>_ ss \-p | string shorten \-m$COLUMNS \-c \(dq\(dq
# \(gass\(ga from Linux\(aq iproute2 shows socket information, but prints extremely long lines.
# This shortens input so it fits on the screen without overflowing lines.
>_ git branch | string match \-rg \(aq^\e* (.*)\(aq | string shorten \-m20
# Take the current git branch and shorten it at 20 columns.
# Here the branch is \(dqbuiltin\-path\-with\-expand\(dq
builtin\-path\-with\-e…
>_ git branch | string match \-rg \(aq^\e* (.*)\(aq | string shorten \-m20 \-\-left
# Taking 20 columns from the right instead:
…in\-path\-with\-expand
.EE
.UNINDENT
.UNINDENT
.SS See also
.INDENT 0.0
.IP \(bu 2
string pad \%<> does the inverse of this command, adding padding to a specific width instead.
.IP \(bu 2
The printf \%<> command can do simple padding, for example \fBprintf %10s\en\fP works like \fBstring pad \-w10\fP\&.
.IP \(bu 2
string length \%<> with the \fB\-\-visible\fP option can be used to show what fish thinks the width is.
.UNINDENT
.SS \(dqrepeat\(dq subcommand
.nf
\fBstring\fP \fBrepeat\fP [(\fB\-n\fP | \fB\-\-count\fP) \fICOUNT\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-N\fP | \fB\-\-no\-newline\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBrepeat\fP [\fB\-N\fP | \fB\-\-no\-newline\fP] [\fB\-q\fP | \fB\-\-quiet\fP] \fICOUNT\fP [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring repeat\fP repeats the \fISTRING\fP \fB\-n\fP or \fB\-\-count\fP times. The \fB\-m\fP or \fB\-\-max\fP option will limit the number of outputted characters (excluding the newline). This option can be used by itself or in conjunction with \fB\-\-count\fP\&. If both \fB\-\-count\fP and \fB\-\-max\fP are present, max char will be outputted unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both \fB\-\-count\fP and \fB\-\-max\fP will accept a number greater than or equal to zero, in the case of zero, nothing will be outputted. The first argument is interpreted as \fICOUNT\fP if \fB\-\-count\fP or \fB\-\-max\fP are not explicitly specified. If \fB\-N\fP or \fB\-\-no\-newline\fP is given, the output won\(aqt contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise.
.SS Examples
.SS Repeat Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string repeat \-n 2 \(aqfoo \(aq
foo foo
>_ echo foo | string repeat \-n 2
foofoo
>_ string repeat \-n 2 \-m 5 \(aqfoo\(aq
foofo
>_ string repeat \-m 5 \(aqfoo\(aq
foofo
>_ string repeat 2 \(aqfoo\(aq
foofoo
>_ string repeat 2 \-n 3
222
.EE
.UNINDENT
.UNINDENT
.SS \(dqreplace\(dq subcommand
.nf
\fBstring\fP \fBreplace\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-f\fP | \fB\-\-filter\fP] [\fB\-i\fP | \fB\-\-ignore\-case\fP]
[\fB\-r\fP | \fB\-\-regex\fP] [(\fB\-m\fP | \fB\-\-max\-matches\fP) \fIMAX\fP] [\fB\-q\fP | \fB\-\-quiet\fP]
\fIPATTERN\fP \fIREPLACEMENT\fP [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring replace\fP is similar to \fBstring match\fP but replaces non\-overlapping matching substrings with a replacement string and prints the result. By default, \fIPATTERN\fP is treated as a literal substring to be matched.
.sp
If \fB\-r\fP or \fB\-\-regex\fP is given, \fIPATTERN\fP is interpreted as a Perl\-compatible regular expression, and \fIREPLACEMENT\fP can contain C\-style escape sequences like \fBt\fP as well as references to capturing groups by number or name as \fI$n\fP or \fI${n}\fP\&.
.sp
If you specify the \fB\-f\fP or \fB\-\-filter\fP flag then each input string is printed only if a replacement was done. This is useful where you would otherwise use this idiom: \fBa_cmd | string match pattern | string replace pattern new_pattern\fP\&. You can instead just write \fBa_cmd | string replace \-\-filter pattern new_pattern\fP\&.
.sp
If \fB\-\-max\-matches MAX\fP or \fB\-m MAX\fP is used, \fBstring replace\fP will stop all processing after MAX lines of input have matched the specified pattern. In the event of \fB\-\-filter\fP or \fB\-f\fP, this means the output will be MAX lines in length. This can be used as an \(dqearly exit\(dq optimization when processing long inputs but expecting a limited and fixed number of outputs that might be found considerably before the input stream has been exhausted.
.sp
Exit status: 0 if at least one replacement was performed, or 1 otherwise.
.SS Replace Literal Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string replace is was \(aqblue is my favorite\(aq
blue was my favorite
>_ string replace 3rd last 1st 2nd 3rd
1st
2nd
last
>_ string replace \-a \(aq \(aq _ \(aqspaces to underscores\(aq
spaces_to_underscores
.EE
.UNINDENT
.UNINDENT
.SS Replace Regex Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string replace \-r \-a \(aq[^\ed.]+\(aq \(aq \(aq \(aq0 one two 3.14 four 5x\(aq
0 3.14 5
>_ string replace \-r \(aq(\ew+)\es+(\ew+)\(aq \(aq$2 $1 $$\(aq \(aqleft right\(aq
right left $
>_ string replace \-r \(aq\es*newline\es*\(aq \(aq\en\(aq \(aqput a newline here\(aq
put a
here
.EE
.UNINDENT
.UNINDENT
.SS \(dqsplit\(dq and \(dqsplit0\(dq subcommands
.nf
\fBstring\fP \fBsplit\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP]] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBsplit0\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP]] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring split\fP splits each \fISTRING\fP on the separator \fISEP\fP, which can be an empty string. If \fB\-m\fP or \fB\-\-max\fP is specified, at most MAX splits are done on each \fISTRING\fP\&. If \fB\-r\fP or \fB\-\-right\fP is given, splitting is performed right\-to\-left. This is only useful in combination with \fB\-m\fP or \fB\-\-max\fP\&. With \fB\-n\fP or \fB\-\-no\-empty\fP, empty results are excluded from consideration (e.g. \fBhello\en\enworld\fP would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise.
.sp
Use \fB\-f\fP or \fB\-\-fields\fP to print out specific fields. FIELDS is a comma\-separated string of field numbers and/or spans. Each field is one\-indexed, and will be printed on separate lines. If a given field does not exist, then the command exits with status 1 and does not print anything, unless \fB\-\-allow\-empty\fP is used.
.sp
See also the \fB\-\-delimiter\fP option of the read \%<> command.
.sp
\fBstring split0\fP splits each \fISTRING\fP on the zero byte (NUL). Options are the same as \fBstring split\fP except that no separator is given.
.sp
\fBsplit0\fP has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as \fBfind \-print0\fP or \fBsort \-z\fP\&. See split0 examples below.
.sp
Be aware that commandline arguments cannot include NULs, so you likely want to pass to \fBstring split0\fP via a pipe, not a command substitution.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string split . example.com
example
com
>_ string split \-r \-m1 / /usr/local/bin/fish
/usr/local/bin
fish
>_ string split \(aq\(aq abc
a
b
c
>_ string split \-\-allow\-empty \-f1,3\-4,5 \(aq\(aq abcd
a
c
d
.EE
.UNINDENT
.UNINDENT
.SS NUL Delimited Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ # Count files in a directory, without being confused by newlines.
>_ # Note: Don\(aqt use \(gastring split0 (find . \-print0)\(ga, because arguments cannot include NUL.
>_ count (find . \-print0 | string split0)
42
>_ # Sort a list of elements which may contain newlines
>_ set foo beta alpha\engamma
>_ set foo (string join0 $foo | sort \-z | string split0)
>_ string escape $foo[1]
alpha\engamma
.EE
.UNINDENT
.UNINDENT
.SS \(dqsub\(dq subcommand
.nf
\fBstring\fP \fBsub\fP [(\fB\-s\fP | \fB\-\-start\fP) \fISTART\fP] [(\fB\-e\fP | \fB\-\-end\fP) \fIEND\fP] [(\fB\-l\fP | \fB\-\-length\fP) \fILENGTH\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring sub\fP prints a substring of each string argument. The start/end of the substring can be specified with \fB\-s\fP/\fB\-e\fP or \fB\-\-start\fP/\fB\-\-end\fP followed by a 1\-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with \fB\-l\fP or \fB\-\-length\fP\&. If the length or end is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. \fB\-\-length\fP is mutually exclusive with \fB\-\-end\fP\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string sub \-\-length 2 abcde
ab
>_ string sub \-s 2 \-l 2 abcde
bc
>_ string sub \-\-start=\-2 abcde
de
>_ string sub \-\-end=3 abcde
abc
>_ string sub \-e \-1 abcde
abcd
>_ string sub \-s 2 \-e \-1 abcde
bcd
>_ string sub \-s \-3 \-e \-2 abcde
c
.EE
.UNINDENT
.UNINDENT
.SS \(dqtrim\(dq subcommand
.nf
\fBstring\fP \fBtrim\fP [\fB\-l\fP | \fB\-\-left\fP] [\fB\-r\fP | \fB\-\-right\fP] [(\fB\-c\fP | \fB\-\-chars\fP) \fICHARS\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring trim\fP removes leading and trailing whitespace from each \fISTRING\fP\&. If \fB\-l\fP or \fB\-\-left\fP is given, only leading whitespace is removed. If \fB\-r\fP or \fB\-\-right\fP is given, only trailing whitespace is trimmed.
.sp
The \fB\-c\fP or \fB\-\-chars\fP switch causes the set of characters in \fICHARS\fP to be removed instead of whitespace. This is a set of characters, not a string \- if you pass \fB\-c foo\fP, it will remove any \(dqf\(dq or \(dqo\(dq, not just \(dqfoo\(dq as a whole.
.sp
Exit status: 0 if at least one character was trimmed, or 1 otherwise.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string trim \(aq abc \(aq
abc
>_ string trim \-\-right \-\-chars=yz xyzzy zany
x
zan
.EE
.UNINDENT
.UNINDENT
.SS \(dqupper\(dq subcommand
.nf
\fBstring\fP \fBupper\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.sp
\fBstring upper\fP converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the \fB\-q\fP flag you can readily test whether a string is already uppercase.
.SS Regular Expressions
.sp
Both the \fBmatch\fP and \fBreplace\fP subcommand support regular expressions when used with the \fB\-r\fP or \fB\-\-regex\fP option. The dialect is that of PCRE2.
.sp
In general, special characters are special by default, so \fBa+\fP matches one or more \(dqa\(dqs, while \fBa\e+\fP matches an \(dqa\(dq and then a \(dq+\(dq. \fB(a+)\fP matches one or more \(dqa\(dqs in a capturing group (\fB(?:XXXX)\fP denotes a non\-capturing group). For the replacement parameter of \fBreplace\fP, \fB$n\fP refers to the n\-th group of the match. In the match parameter, \fB\en\fP (e.g. \fB\e1\fP) refers back to groups.
.sp
Some features include repetitions:
.INDENT 0.0
.IP \(bu 2
\fB*\fP refers to 0 or more repetitions of the previous expression
.IP \(bu 2
\fB+\fP 1 or more
.IP \(bu 2
\fB?\fP 0 or 1.
.IP \(bu 2
\fB{n}\fP to exactly n (where n is a number)
.IP \(bu 2
\fB{n,m}\fP at least n, no more than m.
.IP \(bu 2
\fB{n,}\fP n or more
.UNINDENT
.sp
Character classes, some of the more important:
.INDENT 0.0
.IP \(bu 2
\fB\&.\fP any character except newline
.IP \(bu 2
\fB\ed\fP a decimal digit and \fB\eD\fP, not a decimal digit
.IP \(bu 2
\fB\es\fP whitespace and \fB\eS\fP, not whitespace
.IP \(bu 2
\fB\ew\fP a \(dqword\(dq character and \fB\eW\fP, a \(dqnon\-word\(dq character
.IP \(bu 2
\fB[...]\fP (where \(dq...\(dq is some characters) is a character set
.IP \(bu 2
\fB[^...]\fP is the inverse of the given character set
.IP \(bu 2
\fB[x\-y]\fP is the range of characters from x\-y
.IP \(bu 2
\fB[[:xxx:]]\fP is a named character set
.IP \(bu 2
\fB[[:^xxx:]]\fP is the inverse of a named character set
.IP \(bu 2
\fB[[:alnum:]]\fP : \(dqalphanumeric\(dq
.IP \(bu 2
\fB[[:alpha:]]\fP : \(dqalphabetic\(dq
.IP \(bu 2
\fB[[:ascii:]]\fP : \(dq0\-127\(dq
.IP \(bu 2
\fB[[:blank:]]\fP : \(dqspace or tab\(dq
.IP \(bu 2
\fB[[:cntrl:]]\fP : \(dqcontrol character\(dq
.IP \(bu 2
\fB[[:digit:]]\fP : \(dqdecimal digit\(dq
.IP \(bu 2
\fB[[:graph:]]\fP : \(dqprinting, excluding space\(dq
.IP \(bu 2
\fB[[:lower:]]\fP : \(dqlower case letter\(dq
.IP \(bu 2
\fB[[:print:]]\fP : \(dqprinting, including space\(dq
.IP \(bu 2
\fB[[:punct:]]\fP : \(dqprinting, excluding alphanumeric\(dq
.IP \(bu 2
\fB[[:space:]]\fP : \(dqwhite space\(dq
.IP \(bu 2
\fB[[:upper:]]\fP : \(dqupper case letter\(dq
.IP \(bu 2
\fB[[:word:]]\fP : \(dqsame as w\(dq
.IP \(bu 2
\fB[[:xdigit:]]\fP : \(dqhexadecimal digit\(dq
.UNINDENT
.sp
Groups:
.INDENT 0.0
.IP \(bu 2
\fB(...)\fP is a capturing group
.IP \(bu 2
\fB(?:...)\fP is a non\-capturing group
.IP \(bu 2
\fB\en\fP is a backreference (where n is the number of the group, starting with 1)
.IP \(bu 2
\fB$n\fP is a reference from the replacement expression to a group in the match expression.
.UNINDENT
.sp
And some other things:
.INDENT 0.0
.IP \(bu 2
\fB\eb\fP denotes a word boundary, \fB\eB\fP is not a word boundary.
.IP \(bu 2
\fB^\fP is the start of the string or line, \fB$\fP the end.
.IP \(bu 2
\fB|\fP is \(dqalternation\(dq, i.e. the \(dqor\(dq.
.UNINDENT
.SS Comparison to other tools
.sp
Most operations \fBstring\fP supports can also be done by external tools. Some of these include \fBgrep\fP, \fBsed\fP and \fBcut\fP\&.
.sp
If you are familiar with these, it is useful to know how \fBstring\fP differs from them.
.sp
In contrast to these classics, \fBstring\fP reads input either from stdin or as arguments. \fBstring\fP also does not deal with files, so it requires redirections to be used with them.
.sp
In contrast to \fBgrep\fP, \fBstring\fP\(aqs \fBmatch\fP defaults to glob\-mode, while \fBreplace\fP defaults to literal matching. If set to regex\-mode, they use PCRE regular expressions, which is comparable to \fBgrep\fP\(aqs \fB\-P\fP option. \fBmatch\fP defaults to printing just the match, which is like \fBgrep\fP with \fB\-o\fP (use \fB\-\-entire\fP to enable grep\-like behavior).
.sp
Like \fBsed\fP\(aqs \fBs/old/new/\fP command, \fBstring replace\fP still prints strings that don\(aqt match. \fBsed\fP\(aqs \fB\-n\fP in combination with a \fB/p\fP modifier or command is like \fBstring replace \-f\fP\&.
.sp
\fBstring split somedelimiter\fP is a replacement for \fBtr somedelimiter \en\fP\&.
.SS string\-collect \- join strings into one
.SS Synopsis
.nf
\fBstring\fP \fBcollect\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP] [\fB\-N\fP | \fB\-\-no\-trim\-newlines\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring collect\fP collects its input into a single output argument, without splitting the output when used in a command substitution. This is useful when trying to collect multiline output from another command into a variable. Exit status: 0 if any output argument is non\-empty, or 1 otherwise.
.sp
A command like \fBecho (cmd | string collect)\fP is mostly equivalent to a quoted command substitution (\fBecho \(dq$(cmd)\(dq\fP). The main difference is that the former evaluates to zero or one elements whereas the quoted command substitution always evaluates to one element due to string interpolation.
.sp
If invoked with multiple arguments instead of input, \fBstring collect\fP preserves each argument separately, where the number of output arguments is equal to the number of arguments given to \fBstring collect\fP\&.
.sp
Any trailing newlines on the input are trimmed, just as with \fB\(dq$(cmd)\(dq\fP substitution. Use \fB\-\-no\-trim\-newlines\fP to disable this behavior, which may be useful when running a command such as \fBset contents (cat filename | string collect \-N)\fP\&.
.sp
With \fB\-\-allow\-empty\fP, \fBstring collect\fP always prints one (empty) argument. This can be used to prevent an argument from disappearing.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ echo \(dqzero $(echo one\entwo\enthree) four\(dq
zero one
two
three four
>_ echo \e\(dq(echo one\entwo\enthree | string collect)\e\(dq
\(dqone
two
three\(dq
>_ echo \e\(dq(echo one\entwo\enthree | string collect \-N)\e\(dq
\(dqone
two
three
\(dq
>_ echo foo(true | string collect \-\-allow\-empty)bar
foobar
.EE
.UNINDENT
.UNINDENT
.SS string\-escape \- escape special characters
.SS Synopsis
.nf
\fBstring\fP \fBescape\fP [\fB\-n\fP | \fB\-\-no\-quoted\fP] [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBunescape\fP [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring escape\fP escapes each \fISTRING\fP in one of several ways.
.sp
\fB\-\-style=script\fP (default) alters the string such that it can be passed back to \fBeval\fP to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If \fB\-n\fP or \fB\-\-no\-quoted\fP is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise.
.sp
\fB\-\-style=var\fP ensures the string can be used as a variable name by hex encoding any non\-alphanumeric characters. The string is first converted to UTF\-8 before being encoded.
.sp
\fB\-\-style=url\fP ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF\-8 before being encoded.
.sp
\fB\-\-style=regex\fP escapes an input string for literal matching within a regex expression. The string is first converted to UTF\-8 before being encoded.
.sp
\fBstring unescape\fP performs the inverse of the \fBstring escape\fP command. If the string to be unescaped is not properly formatted it is ignored. For example, doing \fBstring unescape \-\-style=var (string escape \-\-style=var $str)\fP will return the original string. There is no support for unescaping \fB\-\-style=regex\fP\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ echo \ex07 | string escape
\ecg
>_ string escape \-\-style=var \(aqa1 b2\(aq\eu6161
a1_20_b2_E6_85_A1_
.EE
.UNINDENT
.UNINDENT
.SS string\-join \- join strings with delimiter
.SS Synopsis
.nf
\fBstring\fP \fBjoin\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fB\-\-\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBjoin0\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fB\-\-\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
Joins its \fISTRING\fP arguments into a single string separated by \fISEP\fP (for \fBstring join\fP) or by the
zero byte (NUL) (for \fBstring join0\fP).
Exit status: 0 if at least one join was performed, or 1 otherwise.
.INDENT 0.0
.TP
\fB\-n\fP, \fB\-\-no\-empty\fP
Exclude empty strings from consideration (e.g. \fBstring join \-n + a b \(dq\(dq c\fP would expand to \fBa+b+c\fP not \fBa+b++c\fP).
.TP
\fB\-q\fP, \fB\-\-quiet\fP
Do not print the strings, only set the exit status as described above.
.UNINDENT
.sp
\fBWARNING\fP:
Insert a \fB\-\-\fP before positional arguments to prevent them from being interpreted as flags.
Otherwise, any strings starting with \fB\-\fP will be treated as flag arguments, meaning they will most likely result in the command failing.
This is also true if you specify a variable which expands to such a string instead of a literal string.
If you don\(aqt need to append flag arguments at the end of the command,
just always use \fB\-\-\fP to avoid unwelcome surprises.
.sp
\fBstring join0\fP adds a trailing NUL. This is most useful in conjunction with tools that accept NUL\-delimited input, such as \fBsort \-z\fP\&.
.sp
Because Unix uses NUL as the string terminator, passing the output of \fBstring join0\fP as an \fIargument\fP to a command (via a command substitution \%<#\:expand-command-substitution>) won\(aqt actually work.
fish will pass the correct bytes along, but the command won\(aqt be able to tell where the argument ends.
This is a limitation of Unix\(aq argument passing.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ seq 3 | string join ...
1...2...3
# Give a list of NUL\-separated filenames to du (this is a GNU extension)
>_ string join0 file1 file2 file\enwith\enmultiple\enlines | du \-\-files0\-from=\-
# Just put the strings together without a separator
>_ string join \(aq\(aq a b c
abc
>_ set \-l markdown_list \(aq\- first\(aq \(aq\- second\(aq \(aq\- third\(aq
# Strings with leading hyphens (also in variable expansions) are interpreted as flag arguments by default.
>_ string join \en $markdown_list
string join: \- first: unknown option
# Use \(aq\-\-\(aq to prevent this.
>_ string join \-\- \en $markdown_list
\- first
\- second
\- third
.EE
.UNINDENT
.UNINDENT
.SS string\-join0 \- join strings with zero bytes
.SS Synopsis
.nf
\fBstring\fP \fBjoin\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fB\-\-\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBjoin0\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP] [\fB\-\-\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
Joins its \fISTRING\fP arguments into a single string separated by \fISEP\fP (for \fBstring join\fP) or by the
zero byte (NUL) (for \fBstring join0\fP).
Exit status: 0 if at least one join was performed, or 1 otherwise.
.INDENT 0.0
.TP
\fB\-n\fP, \fB\-\-no\-empty\fP
Exclude empty strings from consideration (e.g. \fBstring join \-n + a b \(dq\(dq c\fP would expand to \fBa+b+c\fP not \fBa+b++c\fP).
.TP
\fB\-q\fP, \fB\-\-quiet\fP
Do not print the strings, only set the exit status as described above.
.UNINDENT
.sp
\fBWARNING\fP:
Insert a \fB\-\-\fP before positional arguments to prevent them from being interpreted as flags.
Otherwise, any strings starting with \fB\-\fP will be treated as flag arguments, meaning they will most likely result in the command failing.
This is also true if you specify a variable which expands to such a string instead of a literal string.
If you don\(aqt need to append flag arguments at the end of the command,
just always use \fB\-\-\fP to avoid unwelcome surprises.
.sp
\fBstring join0\fP adds a trailing NUL. This is most useful in conjunction with tools that accept NUL\-delimited input, such as \fBsort \-z\fP\&.
.sp
Because Unix uses NUL as the string terminator, passing the output of \fBstring join0\fP as an \fIargument\fP to a command (via a command substitution \%<#\:expand-command-substitution>) won\(aqt actually work.
fish will pass the correct bytes along, but the command won\(aqt be able to tell where the argument ends.
This is a limitation of Unix\(aq argument passing.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ seq 3 | string join ...
1...2...3
# Give a list of NUL\-separated filenames to du (this is a GNU extension)
>_ string join0 file1 file2 file\enwith\enmultiple\enlines | du \-\-files0\-from=\-
# Just put the strings together without a separator
>_ string join \(aq\(aq a b c
abc
>_ set \-l markdown_list \(aq\- first\(aq \(aq\- second\(aq \(aq\- third\(aq
# Strings with leading hyphens (also in variable expansions) are interpreted as flag arguments by default.
>_ string join \en $markdown_list
string join: \- first: unknown option
# Use \(aq\-\-\(aq to prevent this.
>_ string join \-\- \en $markdown_list
\- first
\- second
\- third
.EE
.UNINDENT
.UNINDENT
.SS string\-length \- print string lengths
.SS Synopsis
.nf
\fBstring\fP \fBlength\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-V\fP | \fB\-\-visible\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring length\fP reports the length of each string argument in characters. Exit status: 0 if at least one non\-empty \fISTRING\fP was given, or 1 otherwise.
.sp
With \fB\-V\fP or \fB\-\-visible\fP, it uses the visible width of the arguments. That means it will discount escape sequences fish knows about, account for $fish_emoji_width and $fish_ambiguous_width. It will also count each line (separated by \fB\en\fP) on its own, and with a carriage return (\fB\er\fP) count only the widest stretch on a line. The intent is to measure the number of columns the \fISTRING\fP would occupy in the current terminal.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string length \(aqhello, world\(aq
12
>_ set str foo
>_ string length \-q $str; echo $status
0
# Equivalent to test \-n \(dq$str\(dq
>_ string length \-\-visible (set_color red)foobar
# the set_color is discounted, so this is the width of \(dqfoobar\(dq
6
>_ string length \-\-visible 🐟🐟🐟🐟
# depending on $fish_emoji_width, this is either 4 or 8
# in new terminals it should be
8
>_ string length \-\-visible abcdef\er123
# this displays as \(dq123def\(dq, so the width is 6
6
>_ string length \-\-visible a\enbc
# counts \(dqa\(dq and \(dqbc\(dq as separate lines, so it prints width for each
1
2
.EE
.UNINDENT
.UNINDENT
.SS string\-lower \- convert strings to lowercase
.SS Synopsis
.nf
\fBstring\fP \fBlower\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring lower\fP converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the \fB\-q\fP flag you can readily test whether a string is already lowercase.
.SS string\-match \- match substrings
.SS Synopsis
.nf
\fBstring\fP \fBmatch\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-e\fP | \fB\-\-entire\fP] [\fB\-i\fP | \fB\-\-ignore\-case\fP]
[\fB\-g\fP | \fB\-\-groups\-only\fP] [\fB\-r\fP | \fB\-\-regex\fP] [\fB\-n\fP | \fB\-\-index\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-v\fP | \fB\-\-invert\fP] [(\fB\-m\fP | \fB\-\-max\-matches\fP) \fIMAX\fP]
\fIPATTERN\fP [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring match\fP tests each \fISTRING\fP against \fIPATTERN\fP and prints matching substrings. Only the first match for each \fISTRING\fP is reported unless \fB\-a\fP or \fB\-\-all\fP is given, in which case all matches are reported.
.sp
If you specify the \fB\-e\fP or \fB\-\-entire\fP then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to \fBgrep\fP without the \fB\-o\fP flag). You can, obviously, achieve the same result by prepending and appending \fB*\fP or \fB\&.*\fP depending on whether or not you have specified the \fB\-\-regex\fP flag. The \fB\-\-entire\fP flag is a way to avoid having to complicate the pattern in that fashion and make the intent of the \fBstring match\fP clearer. Without \fB\-\-entire\fP and \fB\-\-regex\fP, a \fIPATTERN\fP will need to match the entire \fISTRING\fP before it will be reported.
.sp
Matching can be made case\-insensitive with \fB\-\-ignore\-case\fP or \fB\-i\fP\&.
.sp
If \fB\-\-groups\-only\fP or \fB\-g\fP is given, only the capturing groups will be reported \- meaning the full match will be skipped. This is incompatible with \fB\-\-entire\fP and \fB\-\-invert\fP, and requires \fB\-\-regex\fP\&. It is useful as a simple cutting tool instead of \fBstring replace\fP, so you can choose \(dqthis part\(dq of a string.
.sp
If \fB\-\-index\fP or \fB\-n\fP is given, each match is reported as a 1\-based start position and a length. By default, PATTERN is interpreted as a glob pattern matched against each entire \fISTRING\fP argument. A glob pattern is only considered a valid match if it matches the entire \fISTRING\fP\&.
.sp
If \fB\-\-regex\fP or \fB\-r\fP is given, \fIPATTERN\fP is interpreted as a Perl\-compatible regular expression, which does not have to match the entire \fISTRING\fP\&. For a regular expression containing capturing groups, multiple items will be reported for each match, one for the entire match and one for each capturing group. With this, only the matching part of the \fISTRING\fP will be reported, unless \fB\-\-entire\fP is given.
.sp
When matching via regular expressions, \fBstring match\fP automatically sets variables for all named capturing groups (\fB(?expression)\fP). It will create a variable with the name of the group, in the default scope, for each named capturing group, and set it to the value of the capturing group in the first matched argument. If a named capture group matched an empty string, the variable will be set to the empty string (like \fBset var \(dq\(dq\fP). If it did not match, the variable will be set to nothing (like \fBset var\fP). When \fB\-\-regex\fP is used with \fB\-\-all\fP, this behavior changes. Each named variable will contain a list of matches, with the first match contained in the first element, the second match in the second, and so on. If the group was empty or did not match, the corresponding element will be an empty string.
.sp
If \fB\-\-invert\fP or \fB\-v\fP is used the selected lines will be only those which do not match the given glob pattern or regular expression.
.sp
If \fB\-\-max\-matches MAX\fP or \fB\-m MAX\fP is used, \fBstring\fP will stop checking for matches after MAX lines of input have matched. This can be used as an \(dqearly exit\(dq optimization when processing long inputs but expecting a limited and fixed number of outputs that might be found considerably before the input stream has been exhausted. If combined with \fB\-\-invert\fP or \fB\-v\fP, considers only inverted matches.
.sp
Exit status: 0 if at least one match was found, or 1 otherwise.
.SS Examples
.SS Match Glob Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string match \(aqa\(aq a
a
>_ string match \(aqa*b\(aq axxb
axxb
>_ string match \-i \(aqa*B\(aq Axxb
Axxb
>_ string match \-\- \(aq\-*\(aq \-h foo \-\-version bar
# To match things that look like options, we need a \(ga\-\-\(ga
# to tell string its options end there.
\-h
\-\-version
>_ echo \(aqok?\(aq | string match \(aq*?\(aq
ok?
# Note that only the second STRING will match here.
>_ string match \(aqfoo\(aq \(aqfoo1\(aq \(aqfoo\(aq \(aqfoo2\(aq
foo
>_ string match \-e \(aqfoo\(aq \(aqfoo1\(aq \(aqfoo\(aq \(aqfoo2\(aq
foo1
foo
foo2
>_ string match \(aqfoo*\(aq \(aqfoo1\(aq \(aqfoo\(aq \(aqfoo2\(aq
foo1
foo2
.EE
.UNINDENT
.UNINDENT
.SS Match Regex Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string match \-r \(aqcat|dog|fish\(aq \(aqnice dog\(aq
dog
>_ string match \-r \-v \(dqc.*[12]\(dq {cat,dog}(seq 1 4)
dog1
dog2
cat3
dog3
cat4
dog4
>_ string match \-r \-\- \(aq\-.*\(aq \-h foo \-\-version bar
# To match things that look like options, we need a \(ga\-\-\(ga
# to tell string its options end there.
\-h
\-\-version
>_ string match \-r \(aq(\ed\ed?):(\ed\ed):(\ed\ed)\(aq 2:34:56
2:34:56
2
34
56
>_ string match \-r \(aq^(\ew{2,4})\e1$\(aq papa mud murmur
papa
pa
murmur
mur
>_ string match \-r \-a \-n at ratatat
2 2
4 2
6 2
>_ string match \-r \-i \(aq0x[0\-9a\-f]{1,8}\(aq \(aqint magic = 0xBadC0de;\(aq
0xBadC0de
>_ echo $version
3.1.2\-1575\-ga2ff32d90
>_ string match \-rq \(aq(?\ed+).(?\ed+).(?\ed+)\(aq \-\- $version
>_ echo \(dqYou are using fish $major!\(dq
You are using fish 3!
>_ string match \-raq \(aq *(?[^.!?]+)(?[.!?])?\(aq \(dqhello, friend. goodbye\(dq
>_ printf \(dq%s\en\(dq \-\- $sentence
hello, friend
goodbye
>_ printf \(dq%s\en\(dq \-\- $punctuation
\&.
>_ string match \-rq \(aq(?hello)\(aq \(aqhi\(aq
>_ count $word
0
.EE
.UNINDENT
.UNINDENT
.SS string\-pad \- pad strings to a fixed width
.SS Synopsis
.nf
\fBstring\fP \fBpad\fP [\fB\-r\fP | \fB\-\-right\fP] [\fB\-C\fP | \fB\-\-center\fP] [(\fB\-c\fP | \fB\-\-char\fP) \fICHAR\fP] [(\fB\-w\fP | \fB\-\-width\fP) \fIINTEGER\fP]
[\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring pad\fP extends each \fISTRING\fP to the given visible width by adding \fICHAR\fP to the left. That means the width of all visible characters added together, excluding escape sequences and accounting for \fBfish_emoji_width\fP \%<#\:envvar-fish_emoji_width> and \fBfish_ambiguous_width\fP \%<#\:envvar-fish_ambiguous_width>\&. It is the amount of columns in a terminal the \fISTRING\fP occupies.
.sp
The escape sequences reflect what fish knows about, and how it computes its output. Your terminal might support more escapes, or not support escape sequences that fish knows about.
.sp
If \fB\-C\fP or \fB\-\-center\fP is given, add the padding to before and after the string. If it is impossible to perfectly center the result (because the required amount of padding is an odd number), extra padding will be added to the left, unless \fB\-\-right\fP is also given.
.sp
If \fB\-r\fP or \fB\-\-right\fP is given, add the padding after a string.
.sp
If \fB\-c\fP or \fB\-\-char\fP is given, pad with \fICHAR\fP instead of whitespace.
.sp
The output is padded to the maximum width of all input strings. If \fB\-w\fP or \fB\-\-width\fP is given, use at least that.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string pad \-w 10 abc abcdef
abc
abcdef
>_ string pad \-\-right \-\-char=🐟 \(dqfish are pretty\(dq \(dqrich. \(dq
fish are pretty
rich. 🐟🐟🐟🐟
>_ string pad \-w$COLUMNS (date)
# Prints the current time on the right edge of the screen.
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
The printf \%<> command can do simple padding, for example \fBprintf %10s\en\fP works like \fBstring pad \-w10\fP\&.
.IP \(bu 2
string length \%<> with the \fB\-\-visible\fP option can be used to show what fish thinks the width is.
.UNINDENT
.SS string\-repeat \- multiply a string
.SS Synopsis
.nf
\fBstring\fP \fBrepeat\fP [(\fB\-n\fP | \fB\-\-count\fP) \fICOUNT\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-N\fP | \fB\-\-no\-newline\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBrepeat\fP [\fB\-N\fP | \fB\-\-no\-newline\fP] [\fB\-q\fP | \fB\-\-quiet\fP] \fICOUNT\fP [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring repeat\fP repeats the \fISTRING\fP \fB\-n\fP or \fB\-\-count\fP times. The \fB\-m\fP or \fB\-\-max\fP option will limit the number of outputted characters (excluding the newline). This option can be used by itself or in conjunction with \fB\-\-count\fP\&. If both \fB\-\-count\fP and \fB\-\-max\fP are present, max char will be outputted unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both \fB\-\-count\fP and \fB\-\-max\fP will accept a number greater than or equal to zero, in the case of zero, nothing will be outputted. The first argument is interpreted as \fICOUNT\fP if \fB\-\-count\fP or \fB\-\-max\fP are not explicitly specified. If \fB\-N\fP or \fB\-\-no\-newline\fP is given, the output won\(aqt contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise.
.SS Examples
.SS Repeat Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string repeat \-n 2 \(aqfoo \(aq
foo foo
>_ echo foo | string repeat \-n 2
foofoo
>_ string repeat \-n 2 \-m 5 \(aqfoo\(aq
foofo
>_ string repeat \-m 5 \(aqfoo\(aq
foofo
>_ string repeat 2 \(aqfoo\(aq
foofoo
>_ string repeat 2 \-n 3
222
.EE
.UNINDENT
.UNINDENT
.SS string\-replace \- replace substrings
.SS Synopsis
.nf
\fBstring\fP \fBreplace\fP [\fB\-a\fP | \fB\-\-all\fP] [\fB\-f\fP | \fB\-\-filter\fP] [\fB\-i\fP | \fB\-\-ignore\-case\fP]
[\fB\-r\fP | \fB\-\-regex\fP] [(\fB\-m\fP | \fB\-\-max\-matches\fP) \fIMAX\fP] [\fB\-q\fP | \fB\-\-quiet\fP]
\fIPATTERN\fP \fIREPLACEMENT\fP [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring replace\fP is similar to \fBstring match\fP but replaces non\-overlapping matching substrings with a replacement string and prints the result. By default, \fIPATTERN\fP is treated as a literal substring to be matched.
.sp
If \fB\-r\fP or \fB\-\-regex\fP is given, \fIPATTERN\fP is interpreted as a Perl\-compatible regular expression, and \fIREPLACEMENT\fP can contain C\-style escape sequences like \fBt\fP as well as references to capturing groups by number or name as \fI$n\fP or \fI${n}\fP\&.
.sp
If you specify the \fB\-f\fP or \fB\-\-filter\fP flag then each input string is printed only if a replacement was done. This is useful where you would otherwise use this idiom: \fBa_cmd | string match pattern | string replace pattern new_pattern\fP\&. You can instead just write \fBa_cmd | string replace \-\-filter pattern new_pattern\fP\&.
.sp
If \fB\-\-max\-matches MAX\fP or \fB\-m MAX\fP is used, \fBstring replace\fP will stop all processing after MAX lines of input have matched the specified pattern. In the event of \fB\-\-filter\fP or \fB\-f\fP, this means the output will be MAX lines in length. This can be used as an \(dqearly exit\(dq optimization when processing long inputs but expecting a limited and fixed number of outputs that might be found considerably before the input stream has been exhausted.
.sp
Exit status: 0 if at least one replacement was performed, or 1 otherwise.
.SS Examples
.SS Replace Literal Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string replace is was \(aqblue is my favorite\(aq
blue was my favorite
>_ string replace 3rd last 1st 2nd 3rd
1st
2nd
last
>_ string replace \-a \(aq \(aq _ \(aqspaces to underscores\(aq
spaces_to_underscores
.EE
.UNINDENT
.UNINDENT
.SS Replace Regex Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string replace \-r \-a \(aq[^\ed.]+\(aq \(aq \(aq \(aq0 one two 3.14 four 5x\(aq
0 3.14 5
>_ string replace \-r \(aq(\ew+)\es+(\ew+)\(aq \(aq$2 $1 $$\(aq \(aqleft right\(aq
right left $
>_ string replace \-r \(aq\es*newline\es*\(aq \(aq\en\(aq \(aqput a newline here\(aq
put a
here
.EE
.UNINDENT
.UNINDENT
.SS string\-shorten \- shorten strings to a width, with an ellipsis
.SS Synopsis
.nf
\fBstring\fP \fBshorten\fP [(\fB\-c\fP | \fB\-\-char\fP) \fICHARS\fP] [(\fB\-m\fP | \fB\-\-max\fP) \fIINTEGER\fP]
[\fB\-N\fP | \fB\-\-no\-newline\fP] [\fB\-l\fP | \fB\-\-left\fP] [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring shorten\fP truncates each \fISTRING\fP to the given visible width and adds an ellipsis to indicate it. \(dqVisible width\(dq means the width of all visible characters added together, excluding escape sequences and accounting for \fBfish_emoji_width\fP \%<#\:envvar-fish_emoji_width> and \fBfish_ambiguous_width\fP \%<#\:envvar-fish_ambiguous_width>\&. It is the amount of columns in a terminal the \fISTRING\fP occupies.
.sp
The escape sequences reflect what fish knows about, and how it computes its output. Your terminal might support more escapes, or not support escape sequences that fish knows about.
.sp
If \fB\-m\fP or \fB\-\-max\fP is given, truncate at the given width. Otherwise, the lowest non\-zero width of all input strings is used. A max of 0 means no shortening takes place, all STRINGs are printed as\-is.
.sp
If \fB\-N\fP or \fB\-\-no\-newline\fP is given, only the first line (or last line with \fB\-\-left\fP) of each STRING is used, and an ellipsis is added if it was multiline. This only works for STRINGs being given as arguments, multiple lines given on stdin will be interpreted as separate STRINGs instead.
.sp
If \fB\-c\fP or \fB\-\-char\fP is given, add \fICHAR\fP instead of an ellipsis. This can also be empty or more than one character.
.sp
If \fB\-l\fP or \fB\-\-left\fP is given, remove text from the left on instead, so this prints the longest \fIsuffix\fP of the string that fits. With \fB\-\-no\-newline\fP, this will take from the last line instead of the first.
.sp
If \fB\-q\fP or \fB\-\-quiet\fP is given, \fBstring shorten\fP only runs for the return value \- if anything would be shortened, it returns 0, else 1.
.sp
The default ellipsis is \fB…\fP\&. If fish thinks your system is incapable because of your locale, it will use \fB\&...\fP instead.
.sp
The return value is 0 if any shortening occurred, 1 otherwise.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string shorten foo foobar
# No width was given, we infer, and \(dqfoo\(dq is the shortest.
foo
fo…
>_ string shorten \-\-char=\(dq...\(dq foo foobar
# The target width is 3 because of \(dqfoo\(dq,
# and our ellipsis is 3 too, so we can\(aqt really show anything.
# This is the default ellipsis if your locale doesn\(aqt allow \(dq…\(dq.
foo
\&...
>_ string shorten \-\-char=\(dq\(dq \-\-max 4 abcdef 123456
# Leaving the char empty makes us not add an ellipsis
# So this truncates at 4 columns:
abcd
1234
>_ touch \(dqa multiline\(dq\en\(dqfile\(dq
>_ for file in *; string shorten \-N \-\- $file; end
# Shorten the multiline file so we only show one line per file:
a multiline…
>_ ss \-p | string shorten \-m$COLUMNS \-c \(dq\(dq
# \(gass\(ga from Linux\(aq iproute2 shows socket information, but prints extremely long lines.
# This shortens input so it fits on the screen without overflowing lines.
>_ git branch | string match \-rg \(aq^\e* (.*)\(aq | string shorten \-m20
# Take the current git branch and shorten it at 20 columns.
# Here the branch is \(dqbuiltin\-path\-with\-expand\(dq
builtin\-path\-with\-e…
>_ git branch | string match \-rg \(aq^\e* (.*)\(aq | string shorten \-m20 \-\-left
# Taking 20 columns from the right instead:
…in\-path\-with\-expand
.EE
.UNINDENT
.UNINDENT
.SS See Also
.INDENT 0.0
.IP \(bu 2
string pad \%<> does the inverse of this command, adding padding to a specific width instead.
.IP \(bu 2
The printf \%<> command can do simple padding, for example \fBprintf %10s\en\fP works like \fBstring pad \-w10\fP\&.
.IP \(bu 2
string length \%<> with the \fB\-\-visible\fP option can be used to show what fish thinks the width is.
.UNINDENT
.SS string\-split \- split strings by delimiter
.SS Synopsis
.nf
\fBstring\fP \fBsplit\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP]] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBsplit0\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP]] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring split\fP splits each \fISTRING\fP on the separator \fISEP\fP, which can be an empty string. If \fB\-m\fP or \fB\-\-max\fP is specified, at most MAX splits are done on each \fISTRING\fP\&. If \fB\-r\fP or \fB\-\-right\fP is given, splitting is performed right\-to\-left. This is only useful in combination with \fB\-m\fP or \fB\-\-max\fP\&. With \fB\-n\fP or \fB\-\-no\-empty\fP, empty results are excluded from consideration (e.g. \fBhello\en\enworld\fP would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise.
.sp
Use \fB\-f\fP or \fB\-\-fields\fP to print out specific fields. FIELDS is a comma\-separated string of field numbers and/or spans. Each field is one\-indexed, and will be printed on separate lines. If a given field does not exist, then the command exits with status 1 and does not print anything, unless \fB\-\-allow\-empty\fP is used.
.sp
See also the \fB\-\-delimiter\fP option of the read \%<> command.
.sp
\fBstring split0\fP splits each \fISTRING\fP on the zero byte (NUL). Options are the same as \fBstring split\fP except that no separator is given.
.sp
\fBsplit0\fP has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as \fBfind \-print0\fP or \fBsort \-z\fP\&. See split0 examples below.
.sp
Be aware that commandline arguments cannot include NULs, so you likely want to pass to \fBstring split0\fP via a pipe, not a command substitution.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string split . example.com
example
com
>_ string split \-r \-m1 / /usr/local/bin/fish
/usr/local/bin
fish
>_ string split \(aq\(aq abc
a
b
c
>_ string split \-\-allow\-empty \-f1,3\-4,5 \(aq\(aq abcd
a
c
d
.EE
.UNINDENT
.UNINDENT
.SS NUL Delimited Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ # Count files in a directory, without being confused by newlines.
>_ # Note: Don\(aqt use \(gastring split0 (find . \-print0)\(ga, because arguments cannot include NUL.
>_ count (find . \-print0 | string split0)
42
>_ # Sort a list of elements which may contain newlines
>_ set foo beta alpha\engamma
>_ set foo (string join0 $foo | sort \-z | string split0)
>_ string escape $foo[1]
alpha\engamma
.EE
.UNINDENT
.UNINDENT
.SS string\-split0 \- split on zero bytes
.SS Synopsis
.nf
\fBstring\fP \fBsplit\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP]] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] \fISEP\fP [\fISTRING\fP \&...]
\fBstring\fP \fBsplit0\fP [(\fB\-f\fP | \fB\-\-fields\fP) \fIFIELDS\fP [\fB\-a\fP | \fB\-\-allow\-empty\fP]] [(\fB\-m\fP | \fB\-\-max\fP) \fIMAX\fP] [\fB\-n\fP | \fB\-\-no\-empty\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fB\-r\fP | \fB\-\-right\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring split\fP splits each \fISTRING\fP on the separator \fISEP\fP, which can be an empty string. If \fB\-m\fP or \fB\-\-max\fP is specified, at most MAX splits are done on each \fISTRING\fP\&. If \fB\-r\fP or \fB\-\-right\fP is given, splitting is performed right\-to\-left. This is only useful in combination with \fB\-m\fP or \fB\-\-max\fP\&. With \fB\-n\fP or \fB\-\-no\-empty\fP, empty results are excluded from consideration (e.g. \fBhello\en\enworld\fP would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise.
.sp
Use \fB\-f\fP or \fB\-\-fields\fP to print out specific fields. FIELDS is a comma\-separated string of field numbers and/or spans. Each field is one\-indexed, and will be printed on separate lines. If a given field does not exist, then the command exits with status 1 and does not print anything, unless \fB\-\-allow\-empty\fP is used.
.sp
See also the \fB\-\-delimiter\fP option of the read \%<> command.
.sp
\fBstring split0\fP splits each \fISTRING\fP on the zero byte (NUL). Options are the same as \fBstring split\fP except that no separator is given.
.sp
\fBsplit0\fP has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as \fBfind \-print0\fP or \fBsort \-z\fP\&. See split0 examples below.
.sp
Be aware that commandline arguments cannot include NULs, so you likely want to pass to \fBstring split0\fP via a pipe, not a command substitution.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string split . example.com
example
com
>_ string split \-r \-m1 / /usr/local/bin/fish
/usr/local/bin
fish
>_ string split \(aq\(aq abc
a
b
c
>_ string split \-\-allow\-empty \-f1,3\-4,5 \(aq\(aq abcd
a
c
d
.EE
.UNINDENT
.UNINDENT
.SS NUL Delimited Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ # Count files in a directory, without being confused by newlines.
>_ # Note: Don\(aqt use \(gastring split0 (find . \-print0)\(ga, because arguments cannot include NUL.
>_ count (find . \-print0 | string split0)
42
>_ # Sort a list of elements which may contain newlines
>_ set foo beta alpha\engamma
>_ set foo (string join0 $foo | sort \-z | string split0)
>_ string escape $foo[1]
alpha\engamma
.EE
.UNINDENT
.UNINDENT
.SS string\-sub \- extract substrings
.SS Synopsis
.nf
\fBstring\fP \fBsub\fP [(\fB\-s\fP | \fB\-\-start\fP) \fISTART\fP] [(\fB\-e\fP | \fB\-\-end\fP) \fIEND\fP] [(\fB\-l\fP | \fB\-\-length\fP) \fILENGTH\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring sub\fP prints a substring of each string argument. The start/end of the substring can be specified with \fB\-s\fP/\fB\-e\fP or \fB\-\-start\fP/\fB\-\-end\fP followed by a 1\-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with \fB\-l\fP or \fB\-\-length\fP\&. If the length or end is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. \fB\-\-length\fP is mutually exclusive with \fB\-\-end\fP\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string sub \-\-length 2 abcde
ab
>_ string sub \-s 2 \-l 2 abcde
bc
>_ string sub \-\-start=\-2 abcde
de
>_ string sub \-\-end=3 abcde
abc
>_ string sub \-e \-1 abcde
abcd
>_ string sub \-s 2 \-e \-1 abcde
bcd
>_ string sub \-s \-3 \-e \-2 abcde
c
.EE
.UNINDENT
.UNINDENT
.SS string\-trim \- remove trailing whitespace
.SS Synopsis
.nf
\fBstring\fP \fBtrim\fP [\fB\-l\fP | \fB\-\-left\fP] [\fB\-r\fP | \fB\-\-right\fP] [(\fB\-c\fP | \fB\-\-chars\fP) \fICHARS\fP]
[\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring trim\fP removes leading and trailing whitespace from each \fISTRING\fP\&. If \fB\-l\fP or \fB\-\-left\fP is given, only leading whitespace is removed. If \fB\-r\fP or \fB\-\-right\fP is given, only trailing whitespace is trimmed.
.sp
The \fB\-c\fP or \fB\-\-chars\fP switch causes the set of characters in \fICHARS\fP to be removed instead of whitespace. This is a set of characters, not a string \- if you pass \fB\-c foo\fP, it will remove any \(dqf\(dq or \(dqo\(dq, not just \(dqfoo\(dq as a whole.
.sp
Exit status: 0 if at least one character was trimmed, or 1 otherwise.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ string trim \(aq abc \(aq
abc
>_ string trim \-\-right \-\-chars=yz xyzzy zany
x
zan
.EE
.UNINDENT
.UNINDENT
.SS string\-unescape \- expand escape sequences
.SS Synopsis
.nf
\fBstring\fP \fBescape\fP [\fB\-n\fP | \fB\-\-no\-quoted\fP] [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
\fBstring\fP \fBunescape\fP [\fB\-\-style\fP\fB=\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring escape\fP escapes each \fISTRING\fP in one of several ways.
.sp
\fB\-\-style=script\fP (default) alters the string such that it can be passed back to \fBeval\fP to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If \fB\-n\fP or \fB\-\-no\-quoted\fP is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise.
.sp
\fB\-\-style=var\fP ensures the string can be used as a variable name by hex encoding any non\-alphanumeric characters. The string is first converted to UTF\-8 before being encoded.
.sp
\fB\-\-style=url\fP ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF\-8 before being encoded.
.sp
\fB\-\-style=regex\fP escapes an input string for literal matching within a regex expression. The string is first converted to UTF\-8 before being encoded.
.sp
\fBstring unescape\fP performs the inverse of the \fBstring escape\fP command. If the string to be unescaped is not properly formatted it is ignored. For example, doing \fBstring unescape \-\-style=var (string escape \-\-style=var $str)\fP will return the original string. There is no support for unescaping \fB\-\-style=regex\fP\&.
.SS Examples
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ echo \ex07 | string escape
\ecg
>_ string escape \-\-style=var \(aqa1 b2\(aq\eu6161
a1_20_b2_E6_85_A1_
.EE
.UNINDENT
.UNINDENT
.SS string\-upper \- convert strings to uppercase
.SS Synopsis
.nf
\fBstring\fP \fBupper\fP [\fB\-q\fP | \fB\-\-quiet\fP] [\fISTRING\fP \&...]
.fi
.sp
.SS Description
.sp
\fBstring upper\fP converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the \fB\-q\fP flag you can readily test whether a string is already uppercase.
.SS suspend \- suspend the current shell
.SS Synopsis
.nf
\fBsuspend\fP [\fB\-\-force\fP]
.fi
.sp
.SS Description
.sp
\fBsuspend\fP suspends execution of the current shell by sending it a SIGTSTP signal, returning to the controlling process. It can be resumed later by sending it a SIGCONT. In order to prevent suspending a shell that doesn\(aqt have a controlling process, it will not suspend the shell if it is a login shell. This requirement is bypassed if the \fB\-\-force\fP option is given or the shell is not interactive.
.SS switch \- conditionally execute a block of commands
.SS Synopsis
.nf
\fBswitch\fP \fIVALUE\fP\fB;\fP [\fBcase\fP [\fIGLOB\fP \&...]\fB;\fP [\fICOMMANDS\fP \&...]\fB;\fP \&...] \fBend\fP
.fi
.sp
.SS Description
.sp
\fBswitch\fP performs one of several blocks of commands, depending on whether a specified value equals one of several globbed values. \fBcase\fP is used together with the \fBswitch\fP statement in order to determine which block should be executed.
.sp
Each \fBcase\fP command is given one or more parameters. The first \fBcase\fP command with a parameter that matches the string specified in the switch command will be evaluated. \fBcase\fP parameters may contain globs. These need to be escaped or quoted in order to avoid regular glob expansion using filenames.
.sp
Note that fish does not fall through on case statements. Only the first matching case is executed.
.sp
Note that break \%<> cannot be used to exit a case/switch block early like in other languages. It can only be used in loops.
.sp
Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter.
.SS Example
.sp
If the variable \fB$animal\fP contains the name of an animal, the following code would attempt to classify it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
case \(aq*\(aq
echo I have no idea what a $animal is
end
.EE
.UNINDENT
.UNINDENT
.sp
If the above code was run with \fB$animal\fP set to \fBwhale\fP, the output
would be \fBmammal\fP\&.
.SS test \- perform tests on files and text
.SS Synopsis
.nf
\fBtest\fP [\fIEXPRESSION\fP]
\fB[ \fP[\fIEXPRESSION\fP]\fB ]\fP
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBtest\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man test\fP\&.
.sp
\fBtest\fP checks the given conditions and sets the exit status to 0 if they are true, 1 if they are false.
.sp
The first form (\fBtest\fP) is preferred. For compatibility with other shells, the second form is available: a matching pair of square brackets (\fB[ [EXPRESSION] ]\fP).
.sp
When using a variable or command substitution as an argument with \fBtest\fP you should almost always enclose it in double\-quotes, as variables expanding to zero or more than one argument will most likely interact badly with \fBtest\fP\&.
.sp
\fBWarning:\fP
.INDENT 0.0
.INDENT 3.5
For historical reasons, \fBtest\fP supports the one\-argument form (\fBtest foo\fP), and this will also be triggered by e.g. \fBtest \-n $foo\fP if $foo is unset. We recommend you don\(aqt use the one\-argument form and quote all variables or command substitutions used with \fBtest\fP\&.
.sp
This confusing misfeature will be removed in future. \fBtest \-n\fP without any additional argument will be false, \fBtest \-z\fP will be true and any other invocation with exactly one or zero arguments, including \fBtest \-d\fP and \fBtest \(dqfoo\(dq\fP will be an error.
.sp
The same goes for \fB[\fP, e.g. \fB[ \(dqfoo\(dq ]\fP and \fB[ \-d ]\fP will be errors.
.sp
This can be turned on already via the \fBtest\-require\-arg\fP feature flag \%<#\:featureflags>, and will eventually become the default and then only option.
.UNINDENT
.UNINDENT
.SS Operators for files and directories
.INDENT 0.0
.TP
\fB\-b\fP \fIFILE\fP
Returns true if \fIFILE\fP is a block device.
.TP
\fB\-c\fP \fIFILE\fP
Returns true if \fIFILE\fP is a character device.
.TP
\fB\-d\fP \fIFILE\fP
Returns true if \fIFILE\fP is a directory.
.TP
\fB\-e\fP \fIFILE\fP
Returns true if \fIFILE\fP exists.
.TP
\fB\-f\fP \fIFILE\fP
Returns true if \fIFILE\fP is a regular file.
.TP
\fB\-g\fP \fIFILE\fP
Returns true if \fIFILE\fP has the set\-group\-ID bit set.
.TP
\fB\-G\fP \fIFILE\fP
Returns true if \fIFILE\fP exists and has the same group ID as the current user.
.TP
\fB\-k\fP \fIFILE\fP
Returns true if \fIFILE\fP has the sticky bit set. If the OS does not support the concept it returns false. See \%\&.
.TP
\fB\-L\fP \fIFILE\fP
Returns true if \fIFILE\fP is a symbolic link.
.TP
\fB\-O\fP \fIFILE\fP
Returns true if \fIFILE\fP exists and is owned by the current user.
.TP
\fB\-p\fP \fIFILE\fP
Returns true if \fIFILE\fP is a named pipe.
.TP
\fB\-r\fP \fIFILE\fP
Returns true if \fIFILE\fP is marked as readable.
.TP
\fB\-s\fP \fIFILE\fP
Returns true if the size of \fIFILE\fP is greater than zero.
.TP
\fB\-S\fP \fIFILE\fP
Returns true if \fIFILE\fP is a socket.
.TP
\fB\-t\fP \fIFD\fP
Returns true if the file descriptor \fIFD\fP is a terminal (TTY).
.TP
\fB\-u\fP \fIFILE\fP
Returns true if \fIFILE\fP has the set\-user\-ID bit set.
.TP
\fB\-w\fP \fIFILE\fP
Returns true if \fIFILE\fP is marked as writable; note that this does not check if the filesystem is read\-only.
.TP
\fB\-x\fP \fIFILE\fP
Returns true if \fIFILE\fP is marked as executable.
.UNINDENT
.SS Operators to compare files and directories
.INDENT 0.0
.TP
\fIFILE1\fP \fB\-nt\fP \fIFILE2\fP
Returns true if \fIFILE1\fP is newer than \fIFILE2\fP, or \fIFILE1\fP exists and \fIFILE2\fP does not.
.TP
\fIFILE1\fP \fB\-ot\fP \fIFILE2\fP
Returns true if \fIFILE1\fP is older than \fIFILE2\fP, or \fIFILE2\fP exists and \fIFILE1\fP does not.
.TP
\fIFILE1\fP \fB\-ef\fP \fIFILE1\fP
Returns true if \fIFILE1\fP and \fIFILE2\fP refer to the same file.
.UNINDENT
.SS Operators for text strings
.INDENT 0.0
.TP
\fISTRING1\fP \fB=\fP \fISTRING2\fP
Returns true if the strings \fISTRING1\fP and \fISTRING2\fP are identical.
.TP
\fISTRING1\fP \fB!=\fP \fISTRING2\fP
Returns true if the strings \fISTRING1\fP and \fISTRING2\fP are not identical.
.TP
\fB\-n\fP \fISTRING\fP
Returns true if the length of \fISTRING\fP is non\-zero.
.TP
\fB\-z\fP \fISTRING\fP
Returns true if the length of \fISTRING\fP is zero.
.UNINDENT
.SS Operators to compare and examine numbers
.INDENT 0.0
.TP
\fINUM1\fP \fB\-eq\fP \fINUM2\fP
Returns true if \fINUM1\fP and \fINUM2\fP are numerically equal.
.TP
\fINUM1\fP \fB\-ne\fP \fINUM2\fP
Returns true if \fINUM1\fP and \fINUM2\fP are not numerically equal.
.TP
\fINUM1\fP \fB\-gt\fP \fINUM2\fP
Returns true if \fINUM1\fP is greater than \fINUM2\fP\&.
.TP
\fINUM1\fP \fB\-ge\fP \fINUM2\fP
Returns true if \fINUM1\fP is greater than or equal to \fINUM2\fP\&.
.TP
\fINUM1\fP \fB\-lt\fP \fINUM2\fP
Returns true if \fINUM1\fP is less than \fINUM2\fP\&.
.TP
\fINUM1\fP \fB\-le\fP \fINUM2\fP
Returns true if \fINUM1\fP is less than or equal to \fINUM2\fP\&.
.UNINDENT
.sp
Both integers and floating point numbers are supported.
.SS Operators to combine expressions
.INDENT 0.0
.TP
\fICOND1\fP \fB\-a\fP \fICOND2\fP
Returns true if both \fICOND1\fP and \fICOND2\fP are true.
.TP
\fICOND1\fP \fB\-o\fP \fICOND2\fP
Returns true if either \fICOND1\fP or \fICOND2\fP are true.
.UNINDENT
.sp
Expressions can be inverted using the \fB!\fP operator:
.INDENT 0.0
.TP
\fB!\fP \fIEXPRESSION\fP
Returns true if \fIEXPRESSION\fP is false, and false if \fIEXPRESSION\fP is true.
.UNINDENT
.sp
Expressions can be grouped using parentheses.
.INDENT 0.0
.TP
\fB(\fP \fIEXPRESSION\fP \fB)\fP
Returns the value of \fIEXPRESSION\fP\&.
.UNINDENT
.sp
Note that parentheses will usually require escaping with \fB\e\fP (so they appear as \fB\e(\fP and \fB\e)\fP) to avoid being interpreted as a command substitution.
.SS Examples
.sp
If the \fB/tmp\fP directory exists, copy the \fB/etc/motd\fP file to it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-d /tmp
cp /etc/motd /tmp/motd
end
.EE
.UNINDENT
.UNINDENT
.sp
If the variable \fBMANPATH\fP is defined and not empty, print the contents. (If \fBMANPATH\fP is not defined, then it will expand to zero arguments, unless quoted.)
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-n \(dq$MANPATH\(dq
echo $MANPATH
end
.EE
.UNINDENT
.UNINDENT
.sp
Be careful with unquoted variables:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \-n $MANPATH
# This will also be reached if $MANPATH is unset,
# because in that case we have \(gatest \-n\(ga, so it checks if \(dq\-n\(dq is non\-empty, and it is.
echo $MANPATH
end
.EE
.UNINDENT
.UNINDENT
.sp
This will change in a future release of fish, or already with the \fBtest\-require\-arg\fP feature flag \%<#\:featureflags> \- if $MANPATH is unset, \fBif test \-n $MANPATH\fP will be false.
.sp
Parentheses and the \fB\-o\fP and \fB\-a\fP operators can be combined to produce more complicated expressions. In this example, success is printed if there is a \fB/foo\fP or \fB/bar\fP file as well as a \fB/baz\fP or \fB/bat\fP file.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \e( \-f /foo \-o \-f /bar \e) \-a \e( \-f /baz \-o \-f /bat \e)
echo Success.
end
.EE
.UNINDENT
.UNINDENT
.sp
Numerical comparisons will fail if one of the operands is not a number:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test 42 \-eq \(dqThe answer to life, the universe and everything\(dq
echo So long and thanks for all the fish # will not be executed
end
.EE
.UNINDENT
.UNINDENT
.sp
A common comparison is with \fBstatus\fP \%<#\:envvar-status>:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test $status \-eq 0
echo \(dqPrevious command succeeded\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
The previous test can likewise be inverted:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test ! $status \-eq 0
echo \(dqPrevious command failed\(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
which is logically equivalent to the following:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test $status \-ne 0
echo \(dqPrevious command failed\(dq
end
.EE
.UNINDENT
.UNINDENT
.SS Standards
.sp
Unlike many things in fish, \fBtest\fP implements a subset of the IEEE Std 1003.1\-2008 (POSIX.1) standard \%\&. The following exceptions apply:
.INDENT 0.0
.IP \(bu 2
The \fB<\fP and \fB>\fP operators for comparing strings are not implemented.
.IP \(bu 2
With \fBtest\-require\-arg\fP, the zero\- and one\-argument modes will behave differently.
.UNINDENT
.INDENT 0.0
.INDENT 3.5
In cases such as this, one can use \fBcommand\fP \fBtest\fP to explicitly use the system\(aqs standalone \fBtest\fP rather than this \fBbuiltin\fP \fBtest\fP\&.
.UNINDENT
.UNINDENT
.SS See also
.sp
Other commands that may be useful as a condition, and are often easier to use:
.INDENT 0.0
.IP \(bu 2
string \- manipulate strings \%<>, which can do string operations including wildcard and regular expression matching
.IP \(bu 2
path \- manipulate and check paths \%<>, which can do file checks and operations, including filters on multiple paths at once
.UNINDENT
.SS time \- measure how long a command or block takes
.SS Synopsis
.nf
\fBtime\fP \fICOMMAND\fP
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish keyword \fBtime\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man time\fP\&.
.sp
\fBtime\fP causes fish to measure how long a command takes and print the results afterwards. The command can be a simple fish command or a block. The results can not currently be redirected.
.sp
For checking timing after a command has completed, check $CMD_DURATION \%<#\:variables-special>\&.
.sp
Your system most likely also has a \fBtime\fP command. To use that use something like \fBcommand time\fP, as in \fBcommand time sleep 10\fP\&. Because it\(aqs not inside fish, it won\(aqt have access to fish functions and won\(aqt be able to time blocks and such.
.SS How to interpret the output
.sp
Time outputs a few different values. Let\(aqs look at an example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> time string repeat \-n 10000000 y\en | command grep y >/dev/null
________________________________________________________
Executed in 805.98 millis fish external
usr time 798.88 millis 763.88 millis 34.99 millis
sys time 141.22 millis 40.20 millis 101.02 millis
.EE
.UNINDENT
.UNINDENT
.sp
The time after \(dqExecuted in\(dq is what is known as the \(dqwall\-clock time\(dq. It is simply a measure of how long it took from the start of the command until it finished. Typically it is reasonably close to \fBCMD_DURATION\fP \%<#\:envvar-CMD_DURATION>, except for a slight skew because the two are taken at slightly different times.
.sp
The other times are all measures of CPU time. That means they measure how long the CPU was used in this part, and they count multiple cores separately. So a program with four threads using all CPU for a second will have a time of 4 seconds.
.sp
The \(dqusr\(dq time is how much CPU time was spent inside the program itself, the \(dqsys\(dq time is how long was spent in the kernel on behalf of that program.
.sp
The \(dqfish\(dq time is how much CPU was spent in fish, the \(dqexternal\(dq time how much was spent in external commands.
.sp
So in this example, since \fBstring\fP is a builtin, everything that \fBstring repeat\fP did is accounted to fish. Any time it spends doing syscalls like \fBwrite()\fP is accounted for in the fish/sys time.
.sp
And \fBgrep\fP here is explicitly invoked as an external command, so its times will be counted in the \(dqexternal\(dq column.
.sp
Note that, as in this example, the CPU times can add up to more than the execution time. This is because things can be done in parallel \- \fBgrep\fP can match while \fBstring repeat\fP writes.
.SS Example
.sp
(for obvious reasons exact results will vary on your system)
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ time sleep 1s
________________________________________________________
Executed in 1,01 secs fish external
usr time 2,32 millis 0,00 micros 2,32 millis
sys time 0,88 millis 877,00 micros 0,00 millis
>_ time for i in 1 2 3; sleep 1s; end
________________________________________________________
Executed in 3,01 secs fish external
usr time 9,16 millis 2,94 millis 6,23 millis
sys time 0,23 millis 0,00 millis 0,23 millis
.EE
.UNINDENT
.UNINDENT
.sp
Inline variable assignments need to follow the \fBtime\fP keyword:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ time a_moment=1.5m sleep $a_moment
________________________________________________________
Executed in 90.00 secs fish external
usr time 4.62 millis 4.62 millis 0.00 millis
sys time 2.35 millis 0.41 millis 1.95 millis
.EE
.UNINDENT
.UNINDENT
.SS trap \- perform an action when the shell receives a signal
.SS Synopsis
.nf
\fBtrap\fP [\fIOPTIONS\fP] [[\fIARG\fP] \fIREASON\fP \&...\fB ]\fP
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBtrap\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man trap\fP\&.
.sp
\fBtrap\fP is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an event handler \%<#\:event>\&.
.sp
The following parameters are available:
.INDENT 0.0
.TP
.B \fIARG\fP
Command to be executed on signal delivery.
.TP
.B \fIREASON\fP
Name of the event to trap. For example, a signal like \fBINT\fP or \fBSIGINT\fP, or the special symbol \fBEXIT\fP\&.
.TP
\fB\-l\fP or \fB\-\-list\-signals\fP
Prints a list of signal names.
.TP
\fB\-p\fP or \fB\-\-print\fP
Prints all defined signal handlers.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
If \fIARG\fP and \fIREASON\fP are both specified, \fIARG\fP is the command to be executed when the event specified by \fIREASON\fP occurs (e.g., the signal is delivered).
.sp
If \fIARG\fP is absent (and there is a single \fIREASON\fP) or \fB\-\fP, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If \fIARG\fP is the null string the signal specified by each \fIREASON\fP is ignored by the shell and by the commands it invokes.
.sp
If \fIARG\fP is not present and \fB\-p\fP has been supplied, then the trap commands associated with each \fIREASON\fP are displayed. If no arguments are supplied or if only \fB\-p\fP is given, \fBtrap\fP prints the list of commands associated with each signal.
.sp
Signal names are case insensitive and the \fBSIG\fP prefix is optional. Trapping a signal will prevent fish from exiting in response to that signal.
.sp
The exit status is 1 if any \fIREASON\fP is invalid; otherwise trap returns 0.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
trap \(dqstatus \-\-print\-stack\-trace\(dq SIGUSR1
# Prints a stack trace each time the SIGUSR1 signal is sent to the shell.
.EE
.UNINDENT
.UNINDENT
.SS true \- return a successful result
.SS Synopsis
.nf
\fBtrue\fP
.fi
.sp
.SS Description
.sp
\fBtrue\fP sets the exit status to 0.
.sp
\fB:\fP (a single colon) is an alias for the \fBtrue\fP command.
.SS See Also
.INDENT 0.0
.IP \(bu 2
false \%<> command
.IP \(bu 2
$status \%<#\:variables-status> variable
.UNINDENT
.SS type \- locate a command and describe its type
.SS Synopsis
.nf
\fBtype\fP [\fIOPTIONS\fP] \fINAME\fP [\&...]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBtype\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man type\fP\&.
.sp
With no options, \fBtype\fP indicates how each \fINAME\fP would be interpreted if used as a command name.
.sp
The following options are available:
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-all\fP
Prints all of possible definitions of the specified names.
.TP
\fB\-s\fP or \fB\-\-short\fP
Don\(aqt print function definitions when used with no options or with \fB\-a\fP/\fB\-\-all\fP\&.
.TP
\fB\-f\fP or \fB\-\-no\-functions\fP
Suppresses function lookup.
.TP
\fB\-t\fP or \fB\-\-type\fP
Prints \fBfunction\fP, \fBbuiltin\fP, or \fBfile\fP if \fINAME\fP is a shell function, builtin, or disk file, respectively.
.TP
\fB\-p\fP or \fB\-\-path\fP
Prints the path to \fINAME\fP if \fINAME\fP resolves to an executable file in \fBPATH\fP \%<#\:envvar-PATH>, the path to the script containing the definition of the function \fINAME\fP if \fINAME\fP resolves to a function loaded from a file on disk (i.e. not interactively defined at the prompt), or nothing otherwise.
.TP
\fB\-P\fP or \fB\-\-force\-path\fP
Returns the path to the executable file \fINAME\fP, presuming \fINAME\fP is found in the \fBPATH\fP \%<#\:envvar-PATH> environment variable, or nothing otherwise. \fB\-\-force\-path\fP explicitly resolves only the path to executable files in \fBPATH\fP \%<#\:envvar-PATH>, regardless of whether \fINAME\fP is shadowed by a function or builtin with the same name.
.TP
\fB\-q\fP or \fB\-\-query\fP
Suppresses all output; this is useful when testing the exit status. For compatibility with old fish versions this is also \fB\-\-quiet\fP\&.
.TP
\fB\-\-color\fP \fIWHEN\fP
Controls when to use syntax highlighting colors when printing function definitions.
\fIWHEN\fP can be \fBauto\fP (the default, colorize if the output is a terminal \%<>), \fBalways\fP, or \fBnever\fP\&.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
The \fB\-q\fP, \fB\-p\fP, \fB\-t\fP and \fB\-P\fP flags (and their long flag aliases) are mutually exclusive. Only one can be specified at a time.
.sp
\fBtype\fP returns 0 if at least one entry was found, 1 otherwise, and 2 for invalid options or option combinations.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
>_ type fg
fg is a builtin
.EE
.UNINDENT
.UNINDENT
.SS ulimit \- set or get resource usage limits
.SS Synopsis
.nf
\fBulimit\fP [\fIOPTIONS\fP] [\fILIMIT\fP]
.fi
.sp
.SS Description
.sp
\fBulimit\fP sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value.
.sp
Use one of the following switches to specify which resource limit to set or report:
.INDENT 0.0
.TP
\fB\-b\fP or \fB\-\-socket\-buffers\fP
The maximum size of socket buffers.
.TP
\fB\-c\fP or \fB\-\-core\-size\fP
The maximum size of core files created. By setting this limit to zero, core dumps can be disabled.
.TP
\fB\-d\fP or \fB\-\-data\-size\fP
The maximum size of a process\(aq data segment.
.TP
\fB\-e\fP or \fB\-\-nice\fP
Controls the maximum nice value; on Linux, this value is subtracted from 20 to give the effective value.
.TP
\fB\-f\fP or \fB\-\-file\-size\fP
The maximum size of files created by a process.
.TP
\fB\-i\fP or \fB\-\-pending\-signals\fP
The maximum number of signals that may be queued.
.TP
\fB\-l\fP or \fB\-\-lock\-size\fP
The maximum size that may be locked into memory.
.TP
\fB\-m\fP or \fB\-\-resident\-set\-size\fP
The maximum resident set size.
.TP
\fB\-n\fP or \fB\-\-file\-descriptor\-count\fP
The maximum number of open file descriptors.
.TP
\fB\-q\fP or \fB\-\-queue\-size\fP
The maximum size of data in POSIX message queues.
.TP
\fB\-r\fP or \fB\-\-realtime\-priority\fP
The maximum realtime scheduling priority.
.TP
\fB\-s\fP or \fB\-\-stack\-size\fP
The maximum stack size.
.TP
\fB\-t\fP or \fB\-\-cpu\-time\fP
The maximum amount of CPU time in seconds.
.TP
\fB\-u\fP or \fB\-\-process\-count\fP
The maximum number of processes available to the current user.
.TP
\fB\-w\fP or \fB\-\-swap\-size\fP
The maximum swap space available to the current user.
.TP
\fB\-v\fP or \fB\-\-virtual\-memory\-size\fP
The maximum amount of virtual memory available to the shell.
.TP
\fB\-y\fP or \fB\-\-realtime\-maxtime\fP
The maximum contiguous realtime CPU time in microseconds.
.TP
\fB\-K\fP or \fB\-\-kernel\-queues\fP
The maximum number of kqueues (kernel queues) for the current user.
.TP
\fB\-P\fP or \fB\-\-ptys\fP
The maximum number of pseudo\-terminals for the current user.
.TP
\fB\-T\fP or \fB\-\-threads\fP
The maximum number of simultaneous threads for the current user.
.UNINDENT
.sp
Note that not all these limits are available in all operating systems; consult the documentation for \fBsetrlimit\fP in your operating system.
.sp
The value of limit can be a number in the unit specified for the resource or one of the special values \fBhard\fP, \fBsoft\fP, or \fBunlimited\fP, which stand for the current hard limit, the current soft limit, and no limit, respectively.
.sp
If limit is given, it is the new value of the specified resource. If no option is given, then \fB\-f\fP is assumed. Values are in kilobytes, except for \fB\-t\fP, which is in seconds and \fB\-n\fP and \fB\-u\fP, which are unscaled values. The exit status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit.
.sp
\fBulimit\fP also accepts the following options that determine what type of limit to set:
.INDENT 0.0
.TP
\fB\-H\fP or \fB\-\-hard\fP
Sets hard resource limit.
.TP
\fB\-S\fP or \fB\-\-soft\fP
Sets soft resource limit.
.UNINDENT
.sp
A hard limit can only be decreased. Once it is set it cannot be increased; a soft limit may be increased up to the value of the hard limit. If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard limits are updated when assigning a new limit value, and the soft limit is used when reporting the current value.
.sp
The following additional options are also understood by \fBulimit\fP:
.INDENT 0.0
.TP
\fB\-a\fP or \fB\-\-all\fP
Prints all current limits.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
The \fBfish\fP implementation of \fBulimit\fP should behave identically to the implementation in bash, except for these differences:
.INDENT 0.0
.IP \(bu 2
fish \fBulimit\fP supports GNU\-style long options for all switches.
.IP \(bu 2
fish \fBulimit\fP does not support the \fB\-p\fP option for getting the pipe size. The bash implementation consists of a compile\-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. fish does not do this because this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.
.IP \(bu 2
fish \fBulimit\fP does not support getting or setting multiple limits in one command, except reporting all values using the \fB\-a\fP switch.
.UNINDENT
.SS Example
.sp
\fBulimit \-Hs 64\fP sets the hard stack size limit to 64 kB.
.SS umask \- set or get the file creation mode mask
.SS Synopsis
.nf
\fBumask\fP [\fIOPTIONS\fP] [\fIMASK\fP]
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBumask\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man umask\fP\&.
.sp
\fBumask\fP displays and manipulates the \(dqumask\(dq, or file creation mode mask, which is used to restrict the default access to files.
.sp
The umask may be expressed either as an octal number, which represents the rights that will be removed by default, or symbolically, which represents the only rights that will be granted by default.
.sp
Access rights are explained in the manual page for the \fBchmod(1)\fP program.
.sp
With no parameters, the current file creation mode mask is printed as an octal number.
.INDENT 0.0
.TP
\fB\-S\fP or \fB\-\-symbolic\fP
Prints the umask in symbolic form instead of octal form.
.TP
\fB\-p\fP or \fB\-\-as\-command\fP
Outputs the umask in a form that may be reused as input.
.TP
\fB\-h\fP or \fB\-\-help\fP
Displays help about using this command.
.UNINDENT
.sp
If a numeric mask is specified as a parameter, the current shell\(aqs umask will be set to that value, and the rights specified by that mask will be removed from new files and directories by default.
.sp
If a symbolic mask is specified, the desired permission bits, and not the inverse, should be specified. A symbolic mask is a comma separated list of rights. Each right consists of three parts:
.INDENT 0.0
.IP \(bu 2
The first part specifies to whom this set of right applies, and can be one of \fBu\fP, \fBg\fP, \fBo\fP or \fBa\fP, where \fBu\fP specifies the user who owns the file, \fBg\fP specifies the group owner of the file, \fBo\fP specific other users rights and \fBa\fP specifies all three should be changed.
.IP \(bu 2
The second part of a right specifies the mode, and can be one of \fB=\fP, \fB+\fP or \fB\-\fP, where \fB=\fP specifies that the rights should be set to the new value, \fB+\fP specifies that the specified right should be added to those previously specified and \fB\-\fP specifies that the specified rights should be removed from those previously specified.
.IP \(bu 2
The third part of a right specifies what rights should be changed and can be any combination of \fBr\fP, \fBw\fP and \fBx\fP, representing read, write and execute rights.
.UNINDENT
.sp
If the first and second parts are skipped, they are assumed to be \fBa\fP and \fB=\fP, respectively. As an example, \fBr,u+w\fP means all users should have read access and the file owner should also have write access.
.sp
Note that symbolic masks currently do not work as intended.
.SS Example
.sp
\fBumask 177\fP or \fBumask u=rw\fP sets the file creation mask to read and write for the owner and no permissions at all for any other users.
.SS vared \- interactively edit the value of an environment variable
.SS Synopsis
.nf
\fBvared\fP \fIVARIABLE_NAME\fP
.fi
.sp
.SS Description
.sp
\fBvared\fP is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using \fBvared\fP, but individual list elements can.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.sp
\fBvared PATH[3]\fP edits the third element of the PATH list
.SS wait \- wait for jobs to complete
.SS Synopsis
.nf
\fBwait\fP [\fB\-n\fP | \fB\-\-any\fP] [\fIPID\fP | \fIPROCESS_NAME\fP] \&...
.fi
.sp
.SS Description
.sp
NOTE: This page documents the fish builtin \fBwait\fP\&.
To see the documentation on any non\-fish versions, use \fBcommand man wait\fP\&.
.sp
\fBwait\fP waits for child jobs to complete.
.sp
If a \fIPID\fP is specified, the command waits for the job that the process with that process ID belongs to.
.sp
If a \fIPROCESS_NAME\fP is specified, the command waits for the jobs that the matched processes belong to.
.sp
If neither a pid nor a process name is specified, the command waits for all background jobs.
.sp
If the \fB\-n\fP or \fB\-\-any\fP flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
sleep 10 &
wait $last_pid
.EE
.UNINDENT
.UNINDENT
.sp
spawns \fBsleep\fP in the background, and then waits until it finishes.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in (seq 1 5); sleep 10 &; end
wait
.EE
.UNINDENT
.UNINDENT
.sp
spawns five jobs in the background, and then waits until all of them finish.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in (seq 1 5); sleep 10 &; end
hoge &
wait sleep
.EE
.UNINDENT
.UNINDENT
.sp
spawns five \fBsleep\fP jobs and \fBhoge\fP in the background, and then waits until all \fBsleep\fPs finish, and doesn\(aqt wait for \fBhoge\fP\&.
.SS while \- perform a set of commands multiple times
.SS Synopsis
.nf
\fBwhile\fP \fICONDITION\fP\fB;\fP \fICOMMANDS\fP\fB;\fP \fBend\fP
.fi
.sp
.SS Description
.sp
\fBwhile\fP repeatedly executes \fBCONDITION\fP, and if the exit status is 0, then executes \fBCOMMANDS\fP\&.
.sp
The exit status of the \fBwhile\fP loop is the exit status of the last iteration of the \fBCOMMANDS\fP executed, or 0 if none were executed. (This matches other shells and is POSIX\-compatible.)
.sp
You can use and \%<> or or \%<> for complex conditions. Even more complex control can be achieved with \fBwhile true\fP containing a break \%<>\&.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SS Example
.INDENT 0.0
.INDENT 3.5
.sp
.EX
while test \-f foo.txt; or test \-f bar.txt ; echo file exists; sleep 10; end
# outputs \(aqfile exists\(aq at 10 second intervals,
# as long as the file foo.txt or bar.txt exists.
.EE
.UNINDENT
.UNINDENT
.SS fish for Bash users
.sp
This is to give you a quick overview if you come from bash (or to a lesser extent other shells like zsh or ksh) and want to know how fish differs. fish is intentionally not POSIX\-compatible and as such some of the things you are used to work differently.
.sp
Many things are similar \- they both fundamentally expand commandlines to execute commands, have pipes, redirections, variables, globs, use command output in various ways. This document is there to quickly show you the differences.
.SS Command substitutions
.sp
fish spells command substitutions as \fB$(command)\fP or \fB(command)\fP, but not \fB\(gacommand\(ga\fP\&.
.sp
In addition, it only splits them on newlines instead of $IFS. If you want to split on something else, use string split \%<>, string split0 \%<> or string collect \%<>\&. If those are used as the last command in a command substitution the splits they create are carried over. So:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in (find . \-print0 | string split0)
.EE
.UNINDENT
.UNINDENT
.sp
will correctly handle all possible filenames.
.SS Variables
.sp
fish sets and erases variables with set \%<> instead of \fBVAR=VAL\fP and a variety of separate builtins like \fBdeclare\fP and \fBunset\fP and \fBexport\fP\&. \fBset\fP takes options to determine the scope and exportedness of a variable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Define $PAGER *g*lobal and e*x*ported,
# so this is like \(ga\(gaexport PAGER=less\(ga\(ga
set \-gx PAGER less
# Define $alocalvariable only locally,
# like \(ga\(galocal alocalvariable=foo\(ga\(ga
set \-l alocalvariable foo
.EE
.UNINDENT
.UNINDENT
.sp
or to erase variables:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-e PAGER
.EE
.UNINDENT
.UNINDENT
.sp
\fBVAR=VAL\fP statements are available as environment overrides:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
PAGER=cat git log
.EE
.UNINDENT
.UNINDENT
.sp
fish does not perform word splitting. Once a variable has been set to a value, that value stays as it is, so double\-quoting variable expansions isn\(aqt the necessity it is in bash. [1]
.sp
For instance, here\(aqs bash
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> foo=\(dqbar baz\(dq
> printf \(aq\(dq%s\(dq\en\(aq $foo
# will print two lines, because we didn\(aqt double\-quote
# this is word splitting
\(dqbar\(dq
\(dqbaz\(dq
.EE
.UNINDENT
.UNINDENT
.sp
And here is fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set foo \(dqbar baz\(dq
> printf \(aq\(dq%s\(dq\en\(aq $foo
# foo was set as one element,
# so it will be passed as one element, so this is one line
\(dqbar baz\(dq
.EE
.UNINDENT
.UNINDENT
.sp
All variables are \(dqarrays\(dq (we use the term \(dqlists\(dq), and expanding a variable expands to all its elements, with each element as its own argument (like bash\(aqs \fB\(dq${var[@]}\(dq\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set var \(dqfoo bar\(dq banana
> printf %s\en $var
foo bar
banana
.EE
.UNINDENT
.UNINDENT
.sp
Specific elements of a list can be selected:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo $list[5..7]
.EE
.UNINDENT
.UNINDENT
.sp
The arguments to \fBset\fP are ordinary, so you can also set a variable to the output of a command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Set lines to all the lines in file, one element per line
set lines (cat file)
.EE
.UNINDENT
.UNINDENT
.sp
or a mixture of literal values and output:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set numbers 1 2 3 (seq 5 8) 9
> printf \(aq%s\en\(aq $numbers
1
2
3
5
6
7
8
9
.EE
.UNINDENT
.UNINDENT
.sp
A \fB=\fP is unnecessary and unhelpful with \fBset\fP \- \fBset foo = bar\fP will set the variable \(dqfoo\(dq to two values: \(dq=\(dq and \(dqbar\(dq. \fBset foo=bar\fP will print an error.
.sp
See Shell variables \%<#\:variables> for more.
.IP [1] 5
zsh also does not perform word splitting by default (the SH_WORD_SPLIT option controls this)
.SS Variable defaults (\fB${my_variable:\-\(dqdefault value\(dq}\fP)
.sp
fish doesn\(aqt have \fB${my_variable:\-fallback}\fP for providing default values to unset variables. Instead, you can set default values by checking whether the variable has been set yet:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Ensure XDG_CONFIG_HOME is set or use a default value
set \-q XDG_CONFIG_HOME || set XDG_CONFIG_HOME $HOME/.config
# now use XDG_CONFIG_HOME as normal
.EE
.UNINDENT
.UNINDENT
.SS Wildcards (globs)
.sp
fish only supports the \fB*\fP and \fB**\fP glob (and the deprecated \fB?\fP glob) as syntax. If a glob doesn\(aqt match it fails the command (like with bash\(aqs \fBfailglob\fP) unless the command is \fBfor\fP, \fBset\fP or \fBcount\fP or the glob is used with an environment override (\fBVAR=* command\fP), in which case it expands to nothing (like with bash\(aqs \fBnullglob\fP option).
.sp
Globbing doesn\(aqt happen on expanded variables, so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set foo \(dq*\(dq
echo $foo
.EE
.UNINDENT
.UNINDENT
.sp
will not match any files.
.sp
There are no options to control globbing so it always behaves like that.
.sp
The \fB**\fP glob will match in subdirectories as well. In other shells this often needs to be turned on with an option, like \fBsetopt globstar\fP in bash.
.sp
Unlike bash, fish will also follow symlinks, and will sort the results in a natural sort, with included numbers compared as numbers. That means it will sort e.g. music tracks correctly even if they have numbers like \fB1\fP instead of \fB01\fP\&.
.sp
See Wildcards \%<#\:expand-wildcard> for more.
.SS Quoting
.sp
fish has two quoting styles: \fB\(dq\(dq\fP and \fB\(aq\(aq\fP\&. Variables are expanded in double\-quotes, nothing is expanded in single\-quotes.
.sp
There is no \fB$\(aq\(aq\fP, instead the sequences that would transform are transformed \fIwhen unquoted\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo a\enb
a
b
.EE
.UNINDENT
.UNINDENT
.sp
See Quotes \%<#\:quotes> for more.
.SS String manipulation
.sp
fish does not have \fB${foo%bar}\fP, \fB${foo#bar}\fP and \fB${foo/bar/baz}\fP\&. Instead string manipulation is done by the string \%<> builtin.
.sp
For example, to replace \(dqbar\(dq with \(dqbaz\(dq:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> string replace bar baz \(dqbar luhrmann\(dq
baz luhrmann
.EE
.UNINDENT
.UNINDENT
.sp
It can also split strings:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> string split \(dq,\(dq \(dqfoo,bar\(dq
foo
bar
.EE
.UNINDENT
.UNINDENT
.sp
Match regular expressions as a replacement for \fBgrep\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo bababa | string match \-r \(aqaba$\(aq
aba
.EE
.UNINDENT
.UNINDENT
.sp
Pad strings to a given width, with arbitrary characters:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> string pad \-c x \-w 20 \(dqfoo\(dq
xxxxxxxxxxxxxxxxxfoo
.EE
.UNINDENT
.UNINDENT
.sp
Make strings lower/uppercase:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> string lower Foo
foo
> string upper Foo
FOO
.EE
.UNINDENT
.UNINDENT
.sp
repeat strings, trim strings, escape strings or print a string\(aqs length or width (in terminal cells).
.SS Special variables
.sp
Some bash variables and their closest fish equivalent:
.INDENT 0.0
.IP \(bu 2
\fB$*\fP, \fB$@\fP, \fB$1\fP and so on: \fB$argv\fP
.IP \(bu 2
\fB$?\fP: \fB$status\fP
.IP \(bu 2
\fB$$\fP: \fB$fish_pid\fP
.IP \(bu 2
\fB$#\fP: No variable, instead use \fBcount $argv\fP
.IP \(bu 2
\fB$!\fP: \fB$last_pid\fP
.IP \(bu 2
\fB$0\fP: \fBstatus filename\fP
.IP \(bu 2
\fB$\-\fP: Mostly \fBstatus is\-interactive\fP and \fBstatus is\-login\fP
.UNINDENT
.SS Process substitution
.sp
Instead of \fB<(command)\fP fish uses \fB(command | psub)\fP\&. There is no equivalent to \fB>(command)\fP\&.
.sp
Note that both of these are bashisms, and most things can easily be expressed without. E.g. instead of:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
source (command | psub)
.EE
.UNINDENT
.UNINDENT
.sp
Use:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
command | source
.EE
.UNINDENT
.UNINDENT
.sp
as fish\(aqs source \%<> can read from stdin.
.SS Heredocs
.sp
fish does not have \fB<:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
math $i + 1
.EE
.UNINDENT
.UNINDENT
.sp
Unlike bash\(aqs arithmetic, it can handle floating point numbers:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> math 5 / 2
2.5
.EE
.UNINDENT
.UNINDENT
.sp
And also has some functions, like for trigonometry:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> math cos 2 x pi
1
.EE
.UNINDENT
.UNINDENT
.sp
You can pass arguments to \fBmath\fP separately like above or in quotes. Because fish uses \fB()\fP parentheses for command substitutions, quoting is needed if you want to use them in your expression:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> math \(aq(5 + 2) * 4\(aq
.EE
.UNINDENT
.UNINDENT
.sp
Both \fB*\fP and \fBx\fP are valid ways to spell multiplication, but \fB*\fP needs to be quoted because it looks like a glob\&.
.SS Prompts
.sp
fish does not use the \fB$PS1\fP, \fB$PS2\fP and so on variables. Instead the prompt is the output of the fish_prompt \%<> function, plus the fish_mode_prompt \%<> function if vi mode \%<#\:vi-mode> is enabled. The output of the fish_right_prompt \%<> function is used for the right\-sided prompt.
.sp
As an example, here\(aqs a relatively simple bash prompt:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# <$HOSTNAME> <$PWD in blue>
PS1=\(aq\eh\e[\ee[1;34m\e]\ew\e[\ee[m\e] \e[\ee[1;32m\e]\e$\e[\ee[m\e] \(aq
.EE
.UNINDENT
.UNINDENT
.sp
and a rough fish equivalent:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
set \-l prompt_symbol \(aq$\(aq
fish_is_root_user; and set prompt_symbol \(aq#\(aq
echo \-s (prompt_hostname) \e
(set_color blue) (prompt_pwd) \e
(set_color yellow) $prompt_symbol (set_color \-\-reset)
end
.EE
.UNINDENT
.UNINDENT
.sp
This shows a few differences:
.INDENT 0.0
.IP \(bu 2
fish provides set_color \%<> to color text. It can use the 16 named colors and also RGB sequences (so you could also use \fBset_color 5555FF\fP)
.IP \(bu 2
Instead of introducing specific escapes like \fB\eh\fP for the hostname, the prompt is a function. To achieve the effect of \fB\eh\fP, fish provides helper functions like prompt_hostname \%<>, which prints a shortened version of the hostname.
.IP \(bu 2
fish offers other helper functions for adding things to the prompt, like fish_vcs_prompt \%<> for adding a display for common version control systems (git, mercurial, svn), and prompt_pwd \%<> for showing a shortened \fB$PWD\fP (the user\(aqs home directory becomes \fB~\fP and any path component is shortened).
.UNINDENT
.sp
The default prompt is reasonably full\-featured and its code can be read via \fBtype fish_prompt\fP\&.
.sp
fish does not have \fB$PS2\fP for continuation lines, instead it leaves the lines indented to show that the commandline isn\(aqt complete yet.
.SS Blocks and loops
.sp
fish\(aqs blocking constructs look a little different. They all start with a word, end in \fBend\fP and don\(aqt have a second starting word:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for i in 1 2 3; do
echo $i
done
# becomes
for i in 1 2 3
echo $i
end
while true; do
echo Weeee
done
# becomes
while true
echo Weeeeeee
end
{
echo Hello
}
# becomes
begin
echo Hello
end
if true; then
echo Yes I am true
else
echo \(dqHow is true not true?\(dq
fi
# becomes
if true
echo Yes I am true
else
echo \(dqHow is true not true?\(dq
end
foo() {
echo foo
}
# becomes
function foo
echo foo
end
# (bash allows the word \(dqfunction\(dq,
# but this is an extension)
.EE
.UNINDENT
.UNINDENT
.sp
fish does not have an \fBuntil\fP\&. Use \fBwhile not\fP or \fBwhile !\fP\&.
.SS Subshells
.sp
Bash has a feature called \(dqsubshells\(dq, where it will start another shell process for certain things. That shell will then be independent and e.g. any changes it makes to variables won\(aqt be visible in the main shell.
.sp
This includes things like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# A list of commands in \(ga()\(ga parentheses
(foo; bar) | baz
# Both sides of a pipe
foo | while read \-r bar; do
# This will not be visible outside of the loop.
VAR=VAL
# This background process will not be, either
baz &
done
.EE
.UNINDENT
.UNINDENT
.sp
fish does not currently have subshells. You will have to find a different solution. The isolation can usually be achieved by scoping variables (with \fBset \-l\fP), but if you really do need to run your code in a new shell environment you can use \fBfish \-c \(aqyour code here\(aq\fP to do so explicitly.
.sp
\fB()\fP subshells are often confused with \fB{}\fP grouping, which does \fInot\fP use a subshell. When you just need to group, you can use \fBbegin; end\fP in fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
(foo; bar) | baz
# when it should really have been:
{ foo; bar; } | baz
# becomes
begin; foo; bar; end | baz
.EE
.UNINDENT
.UNINDENT
.sp
The pipe will be run in the same process, so \fBwhile read\fP loops can set variables outside:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
foo | while read bar
set \-g VAR VAL
baz &
end
echo $VAR # will print VAL
jobs # will show \(dqbaz\(dq
.EE
.UNINDENT
.UNINDENT
.sp
Subshells are also frequently confused with command substitutions, which bash writes as \fB\(gacommand\(ga\fP or \fB$(command)\fP and fish writes as \fB$(command)\fP or \fB(command)\fP\&. Bash also \fIuses\fP subshells to implement them.
.SS Builtins and other commands
.sp
By now it has become apparent that fish puts much more of a focus on its builtins and external commands rather than its syntax. So here are some helpful builtins and their rough equivalent in bash:
.INDENT 0.0
.IP \(bu 2
string \%<> \- this replaces most of the string transformation (\fB${i%foo}\fP et al) and can also be used instead of \fBgrep\fP and \fBsed\fP and such.
.IP \(bu 2
math \%<> \- this replaces \fB$((i + 1))\fP arithmetic and can also do floats and some simple functions (sine and friends).
.IP \(bu 2
argparse \%<> \- this can handle a script\(aqs option parsing, for which bash would probably use \fBgetopt\fP (zsh provides \fBzparseopts\fP).
.IP \(bu 2
count \%<> can be used to count things and therefore replaces \fB$#\fP and can be used instead of \fBwc\fP\&.
.IP \(bu 2
status \%<> provides information about the shell status, e.g. if it\(aqs interactive or what the current linenumber is. This replaces \fB$\-\fP and \fB$BASH_LINENO\fP and other variables.
.IP \(bu 2
\fBseq(1)\fP can be used as a replacement for \fB{1..10}\fP range expansion. If your OS doesn\(aqt ship a \fBseq\fP fish includes a replacement function.
.UNINDENT
.SS Other facilities
.sp
Bash has \fBset \-x\fP or \fBset \-o xtrace\fP to print all commands that are being executed. In fish, this would be enabled by setting \fBfish_trace\fP \%<#\:envvar-fish_trace>\&.
.sp
Or, if your intention is to \fIprofile\fP how long each line of a script takes, you can use \fBfish \-\-profile\fP \- see the page for the fish command \%<>\&.
.SS Tutorial
.SS Why fish?
.sp
fish is a fully\-equipped command line shell (like bash or zsh) that is smart and user\-friendly. fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.
.sp
If you want to make your command line more productive, more useful, and more fun, without learning a bunch of arcane syntax and configuration options, then fish might be just what you\(aqre looking for!
.SS Getting started
.sp
Once installed, just type in \fBfish\fP into your current shell to try it out!
.sp
You will be greeted by the standard fish prompt,
which means you are all set up and can start using fish:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
you@hostname ~>
.EE
.UNINDENT
.UNINDENT
.sp
This prompt that you see above is the fish default prompt: it shows your username, hostname, and working directory. You can customize it, see how to change your prompt \%<#\:prompt>\&.
.sp
From now on, we\(aqll pretend your prompt is just a \fB>\fP to save space.
.SS Learning fish
.sp
This tutorial assumes a basic understanding of command line shells and Unix commands, and that you have a working copy of fish.
.sp
If you have a strong understanding of other shells, and want to know what fish does differently, search for the magic phrase \fIunlike other shells\fP, which is used to call out important differences.
.sp
Or, if you want a quick overview over the differences to other shells like Bash, see Fish For Bash Users \%<>\&.
.sp
For the full, detailed description of how to use fish interactively, see Interactive Use \%<>\&.
.sp
For a comprehensive description of fish\(aqs scripting language, see The Fish Language \%<>\&.
.SS Running Commands
.sp
fish runs commands like other shells: you type a command, followed by its arguments. Spaces are separators:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo hello world
hello world
.EE
.UNINDENT
.UNINDENT
.sp
This runs the command \fBecho\fP with the arguments \fBhello\fP and \fBworld\fP\&. In this case that\(aqs the same as one argument \fBhello world\fP, but in many cases it\(aqs not. If you need to pass an argument that includes a space, you can escape \%<#\:escapes> with a backslash, or quote \%<#\:quotes> it using single or double quotes:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> mkdir My\e Files
# Makes a directory called \(dqMy Files\(dq, with a space in the name
> cp ~/Some\e File \(aqMy Files\(aq
# Copies a file called \(dqSome File\(dq in the home directory to \(dqMy Files\(dq
> ls \(dqMy Files\(dq
Some File
.EE
.UNINDENT
.UNINDENT
.SS Getting Help
.sp
Run \fBhelp\fP to open fish\(aqs help in a web browser, and \fBman\fP with the page (like \fBfish\-language\fP) to open it in a man page. You can also ask for help with a specific command, for example, \fBhelp set\fP to open in a web browser, or \fBman set\fP to see it in the terminal.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> man set
set \- handle shell variables
Synopsis...
.EE
.UNINDENT
.UNINDENT
.sp
To open this section, use \fBhelp getting\-help\fP\&.
.sp
This only works for fish\(aqs own documentation for itself and its built\-in commands (the \(dqbuiltins\(dq). For any other commands on your system, they should provide their own documentation, often in the man system. For example \fBman ls\fP should tell you about your computer\(aqs \fBls\fP command.
.SS Syntax Highlighting
.sp
You\(aqll quickly notice that fish performs syntax highlighting as you type. Invalid commands are colored red by default:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> /bin/mkd
.EE
.UNINDENT
.UNINDENT
.sp
A command may be invalid because it does not exist, or refers to a file that you cannot execute. When the command becomes valid, it is shown in a different color:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> /bin/mkdir
.EE
.UNINDENT
.UNINDENT
.sp
Valid file paths are underlined as you type them:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> cat ~/somefi
.EE
.UNINDENT
.UNINDENT
.sp
This tells you that there exists a file that starts with \fBsomefi\fP, which is useful feedback as you type.
.sp
These colors, and many more, can be changed by running \fBfish_config\fP, or by modifying color variables \%<#\:variables-color> directly.
.sp
For example, if you want to disable (almost) all coloring:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_config theme choose none
.EE
.UNINDENT
.UNINDENT
.sp
This picks the \(dqnone\(dq theme. To see all themes:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_config theme show
.EE
.UNINDENT
.UNINDENT
.sp
Just running \fBfish_config\fP will open up a browser interface that allows you to pick from the available themes.
.SS Autosuggestions
.sp
As you type fish will suggest commands to the right of the cursor, in gray. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> /bin/hostname
.EE
.UNINDENT
.UNINDENT
.sp
It knows about paths and options:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> grep \-\-ignore\-case
.EE
.UNINDENT
.UNINDENT
.sp
And history too. Type a command once, and you can re\-summon it by just typing a few letters:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> rsync \-avze ssh . myname@somelonghost.com:/some/long/path/doo/dee/doo/dee/doo
.EE
.UNINDENT
.UNINDENT
.sp
To accept the autosuggestion, hit \fBright\fP (\fB→\fP) or \fBctrl\fP\-\fBf\fP\&. To accept a single word of the autosuggestion, \fBalt\fP\-\fBright\fP (\fB→\fP). If the autosuggestion is not what you want, just ignore it.
.sp
If you don\(aqt like autosuggestions, you can disable them by setting \fB$fish_autosuggestion_enabled\fP to 0:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_autosuggestion_enabled 0
.EE
.UNINDENT
.UNINDENT
.SS Tab Completions
.sp
A rich set of tab completions work \(dqout of the box\(dq.
.sp
Press \fBtab\fP and fish will attempt to complete the command, argument, or path:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> /pri\fBtab\fP => /private/
.EE
.UNINDENT
.UNINDENT
.sp
If there\(aqs more than one possibility, it will list them:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> ~/stuff/s\fBtab\fP
~/stuff/script.sh (command) ~/stuff/sources/ (directory)
.EE
.UNINDENT
.UNINDENT
.sp
Hit tab again to cycle through the possibilities. The part in parentheses there (that \(dqcommand\(dq and \(dqdirectory\(dq) is the completion description. It\(aqs just a short hint to explain what kind of argument it is.
.sp
fish can also complete many commands, like git branches:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> git merge pr\fBtab\fP => git merge prompt_designer
> git checkout b\fBtab\fP
builtin_list_io_merge (Branch) builtin_set_color (Branch) busted_events (Tag)
.EE
.UNINDENT
.UNINDENT
.sp
Try hitting tab and see what fish can do!
.SS Variables
.sp
Like other shells, a dollar sign followed by a variable name is replaced with the value of that variable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo My home directory is $HOME
My home directory is /home/tutorial
.EE
.UNINDENT
.UNINDENT
.sp
This is known as variable substitution, and it also happens in double quotes, but not single quotes:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo \(dqMy current directory is $PWD\(dq
My current directory is /home/tutorial
> echo \(aqMy current directory is $PWD\(aq
My current directory is $PWD
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells, fish has an ordinary command to set variables: \fBset\fP, which takes a variable name, and then its value.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set name \(aqMister Noodle\(aq
> echo $name
Mister Noodle
.EE
.UNINDENT
.UNINDENT
.sp
(Notice the quotes: without them, \fBMister\fP and \fBNoodle\fP would have been separate arguments, and \fB$name\fP would have been made into a list of two elements.)
.sp
Unlike other shells, variables are not further split after substitution:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> mkdir $name
> ls
Mister Noodle
.EE
.UNINDENT
.UNINDENT
.sp
In bash, this would have created two directories \(dqMister\(dq and \(dqNoodle\(dq. In fish, it created only one: the variable had the value \(dqMister Noodle\(dq, so that is the argument that was passed to \fBmkdir\fP, spaces and all.
.sp
You can erase (or \(dqdelete\(dq) a variable with \fB\-e\fP or \fB\-\-erase\fP
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-e MyVariable
> env | grep MyVariable
(no output)
.EE
.UNINDENT
.UNINDENT
.sp
For more, see Variable expansion \%<#\:expand-variable>\&.
.SS Exports (Shell Variables)
.sp
Sometimes you need to have a variable available to an external command, often as a setting. For example many programs like \fBgit\fP or \fBman\fP read the \fB$PAGER\fP variable to figure out your preferred pager (the program that lets you scroll text). Other variables used like this include \fB$BROWSER\fP, \fB$LANG\fP (to configure your language) and \fB$PATH\fP\&. You\(aqll note these are written in ALLCAPS, but that\(aqs just a convention.
.sp
To give a variable to an external command, it needs to be \(dqexported\(dq. This is done with a flag to \fBset\fP, either \fB\-\-export\fP or just \fB\-x\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-x MyVariable SomeValue
> env | grep MyVariable
MyVariable=SomeValue
.EE
.UNINDENT
.UNINDENT
.sp
It can also be unexported with \fB\-\-unexport\fP or \fB\-u\fP\&.
.sp
This works the other way around as well! If fish is started by something else, it inherits that parents exported variables. So if your terminal emulator starts fish, and it exports \fB$LANG\fP set to \fBen_US.UTF\-8\fP, fish will receive that setting. And whatever started your terminal emulator also gave \fIit\fP some variables that it will then pass on unless it specifically decides not to. This is how fish usually receives the values for things like \fB$LANG\fP, \fB$PATH\fP and \fB$TERM\fP, without you having to specify them again.
.sp
Exported variables can be local or global or universal \- \(dqexported\(dq is not a scope \%<#\:variables-scope>! Usually you\(aqd make them global via \fBset \-gx MyVariable SomeValue\fP\&.
.sp
For more, see Exporting variables \%<#\:variables-export>\&.
.SS Lists
.sp
The \fBset\fP command above used quotes to ensure that \fBMister Noodle\fP was one argument. If it had been two arguments, then \fBname\fP would have been a list of length 2. In fact, all variables in fish are really lists, that can contain any number of values, or none at all.
.sp
Some variables, like \fB$PWD\fP, only have one value. By convention, we talk about that variable\(aqs value, but we really mean its first (and only) value.
.sp
Other variables, like \fB$PATH\fP, really do have multiple values. During variable expansion, the variable expands to become multiple arguments:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo $PATH
/usr/bin /bin /usr/sbin /sbin /usr/local/bin
.EE
.UNINDENT
.UNINDENT
.sp
Variables whose name ends in \(dqPATH\(dq are automatically split on colons to become lists. They are joined using colons when exported to subcommands. This is for compatibility with other tools, which expect $PATH to use colons. You can also explicitly add this quirk to a variable with \fBset \-\-path\fP, or remove it with \fBset \-\-unpath\fP\&.
.sp
Lists cannot contain other lists: there is no recursion. A variable is a list of strings, full stop.
.sp
Get the length of a list with \fBcount\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> count $PATH
5
.EE
.UNINDENT
.UNINDENT
.sp
You can append (or prepend) to a list by setting the list to itself, with some additional arguments. Here we append /usr/local/bin to $PATH:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set PATH $PATH /usr/local/bin
.EE
.UNINDENT
.UNINDENT
.sp
You can access individual elements with square brackets. Indexing starts at 1 from the beginning, and \-1 from the end:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo $PATH
/usr/bin /bin /usr/sbin /sbin /usr/local/bin
> echo $PATH[1]
/usr/bin
> echo $PATH[\-1]
/usr/local/bin
.EE
.UNINDENT
.UNINDENT
.sp
You can also access ranges of elements, known as \(dqslices\(dq:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo $PATH[1..2]
/usr/bin /bin
> echo $PATH[\-1..2]
/usr/local/bin /sbin /usr/sbin /bin
.EE
.UNINDENT
.UNINDENT
.sp
You can iterate over a list (or a slice) with a for loop:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for val in $PATH
echo \(dqentry: $val\(dq
end
# Will print:
# entry: /usr/bin/
# entry: /bin
# entry: /usr/sbin
# entry: /sbin
# entry: /usr/local/bin
.EE
.UNINDENT
.UNINDENT
.sp
One particular bit is that you can use lists like Brace expansion \%<#\:expand-brace>\&. If you attach another string to a list, it\(aqll combine every element of the list with the string:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set mydirs /usr/bin /bin
> echo $mydirs/fish # this is just like {/usr/bin,/bin}/fish
/usr/bin/fish /bin/fish
.EE
.UNINDENT
.UNINDENT
.sp
This also means that, if the list is empty, there will be no argument:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set empty # no argument
> echo $empty/this_is_gone # prints an empty line
.EE
.UNINDENT
.UNINDENT
.sp
If you quote the list, it will be used as one string and so you\(aqll get one argument even if it is empty.
.sp
For more, see Lists \%<#\:variables-lists>\&.
For more on combining lists with strings (or even other lists), see cartesian products \%<#\:cartesian-product> and Variable expansion \%<#\:expand-variable>\&.
.SS Wildcards
.sp
fish supports the familiar wildcard \fB*\fP\&. To list all JPEG files:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> ls *.jpg
lena.jpg
meena.jpg
santa maria.jpg
.EE
.UNINDENT
.UNINDENT
.sp
You can include multiple wildcards:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> ls l*.p*
lena.png
lesson.pdf
.EE
.UNINDENT
.UNINDENT
.sp
The recursive wildcard \fB**\fP searches directories recursively:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> ls /var/**.log
/var/log/system.log
/var/run/sntp.log
.EE
.UNINDENT
.UNINDENT
.sp
If that directory traversal is taking a long time, you can \fBctrl\fP\-\fBc\fP out of it.
.sp
For more, see Wildcards \%<#\:expand-wildcard>\&.
.SS Pipes and Redirections
.sp
You can pipe between commands with the usual vertical bar:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo hello world | wc
1 2 12
.EE
.UNINDENT
.UNINDENT
.sp
stdin and stdout can be redirected via the familiar \fB<\fP and \fB>\fP\&. stderr is redirected with a \fB2>\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> grep fish < /etc/shells > ~/output.txt 2> ~/errors.txt
.EE
.UNINDENT
.UNINDENT
.sp
To redirect stdout and stderr into one file, you can use \fB&>\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> make &> make_output.txt
.EE
.UNINDENT
.UNINDENT
.sp
For more, see Input and output redirections \%<#\:redirects> and Pipes \%<#\:pipes>\&.
.SS Command Substitutions
.sp
Command substitutions use the output of one command as an argument to another. Unlike other shells, fish does not use backticks \(ga\(ga for command substitutions. Instead, it uses parentheses with or without a dollar:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo In (pwd), running $(uname)
In /home/tutorial, running FreeBSD
.EE
.UNINDENT
.UNINDENT
.sp
A common idiom is to capture the output of a command in a variable:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set os (uname)
> echo $os
Linux
.EE
.UNINDENT
.UNINDENT
.sp
Command substitutions without a dollar are not expanded within quotes, so the version with a dollar is simpler:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> touch \(dqtesting_$(date +%s).txt\(dq
> ls *.txt
testing_1360099791.txt
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells, fish does not split command substitutions on any whitespace (like spaces or tabs), only newlines. Usually this is a big help because unix commands operate on a line\-by\-line basis. Sometimes it can be an issue with commands like \fBpkg\-config\fP that print what is meant to be multiple arguments on a single line. To split it on spaces too, use \fBstring split\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> printf \(aq%s\en\(aq (pkg\-config \-\-libs gio\-2.0)
\-lgio\-2.0 \-lgobject\-2.0 \-lglib\-2.0
> printf \(aq%s\en\(aq (pkg\-config \-\-libs gio\-2.0 | string split \-n \(dq \(dq)
\-lgio\-2.0
\-lgobject\-2.0
\-lglib\-2.0
.EE
.UNINDENT
.UNINDENT
.sp
If you need a command substitutions output as one argument, without any splits, use quoted command substitution:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo \(dqfirst line
second line\(dq > myfile
> set myfile \(dq$(cat myfile)\(dq
> printf \(aq|%s|\(aq $myfile
|first line
second line|
.EE
.UNINDENT
.UNINDENT
.sp
For more, see Command substitution \%<#\:expand-command-substitution>\&.
.SS Separating Commands (Semicolon)
.sp
Like other shells, fish allows multiple commands either on separate lines or the same line.
.sp
To write them on the same line, use the semicolon (\(dq;\(dq). That means the following two examples are equivalent:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo fish; echo chips
# or
echo fish
echo chips
.EE
.UNINDENT
.UNINDENT
.sp
This is useful interactively to enter multiple commands. In a script it\(aqs easier to read if the commands are on separate lines.
.SS Exit Status
.sp
When a command exits, it returns a status code as a non\-negative integer (that\(aqs a whole number >= 0).
.sp
Unlike other shells, fish stores the exit status of the last command in \fB$status\fP instead of \fB$?\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> false
> echo $status
1
.EE
.UNINDENT
.UNINDENT
.sp
This indicates how the command fared \- 0 usually means success, while the others signify kinds of failure. For instance fish\(aqs \fBset \-\-query\fP returns the number of variables it queried that weren\(aqt set \- \fBset \-\-query PATH\fP usually returns 0, \fBset \-\-query arglbargl boogagoogoo\fP usually returns 2.
.sp
There is also a \fB$pipestatus\fP list variable for the exit statuses [1] of processes in a pipe.
.sp
For more, see The status variable \%<#\:variables-status>\&.
.IP [1] 5
or \(dqstati\(dq if you prefer, or \(dqstatūs\(dq if you\(aqve time\-travelled from ancient Rome or work as a latin teacher
.SS Combiners (And, Or, Not)
.sp
fish supports the familiar \fB&&\fP and \fB||\fP to combine commands, and \fB!\fP to negate them:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> ./configure && make && sudo make install
.EE
.UNINDENT
.UNINDENT
.sp
Here, \fBmake\fP is only executed if \fB\&./configure\fP succeeds (returns 0), and \fBsudo make install\fP is only executed if both \fB\&./configure\fP and \fBmake\fP succeed.
.sp
fish also supports and \%<>, or \%<>, and not \%<>\&. The first two are job modifiers and have lower precedence. Example usage:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> cp file1 file1_bak && cp file2 file2_bak; and echo \(dqBackup successful\(dq; or echo \(dqBackup failed\(dq
Backup failed
.EE
.UNINDENT
.UNINDENT
.sp
As mentioned in the section on the semicolon, this can also be written in multiple lines, like so:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
cp file1 file1_bak && cp file2 file2_bak
and echo \(dqBackup successful\(dq
or echo \(dqBackup failed\(dq
.EE
.UNINDENT
.UNINDENT
.SS Conditionals (If, Else, Switch)
.sp
Use if \%<> and else \%<> to conditionally execute code, based on the exit status of a command.
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if grep fish /etc/shells
echo Found fish
else if grep bash /etc/shells
echo Found bash
else
echo Got nothing
end
.EE
.UNINDENT
.UNINDENT
.sp
To compare strings or numbers or check file properties (whether a file exists or is writeable and such), use test \%<>, like
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if test \(dq$fish\(dq = \(dqflounder\(dq
echo FLOUNDER
end
# or
if test \(dq$number\(dq \-gt 5
echo $number is greater than five
else
echo $number is five or less
end
# or
# This test is true if the path /etc/hosts exists
# \- it could be a file or directory or symlink (or possibly something else).
if test \-e /etc/hosts
echo We most likely have a hosts file
else
echo We do not have a hosts file
end
.EE
.UNINDENT
.UNINDENT
.sp
Combiners can also be used to make more complex conditions, like
.INDENT 0.0
.INDENT 3.5
.sp
.EX
if command \-sq fish; and grep fish /etc/shells
echo fish is installed and configured
end
.EE
.UNINDENT
.UNINDENT
.sp
For even more complex conditions, use begin \%<> and end \%<> to group parts of them.
.sp
There is also a switch \%<> command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
switch (uname)
case Linux
echo Hi Tux!
case Darwin
echo Hi Hexley!
case FreeBSD NetBSD DragonFly
echo Hi Beastie!
case \(aq*\(aq
echo Hi, stranger!
end
.EE
.UNINDENT
.UNINDENT
.sp
As you see, case \%<> does not fall through, and can accept multiple arguments or (quoted) wildcards.
.sp
For more, see Conditions \%<#\:syntax-conditional>\&.
.SS Functions
.sp
A fish function is a list of commands, which may optionally take arguments. Unlike other shells, arguments are not passed in \(dqnumbered variables\(dq like \fB$1\fP, but instead in a single list \fB$argv\fP\&. To create a function, use the function \%<> builtin:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function say_hello
echo Hello $argv
end
say_hello
# prints: Hello
say_hello everybody!
# prints: Hello everybody!
.EE
.UNINDENT
.UNINDENT
.sp
Unlike other shells, fish does not have aliases or special prompt syntax. Functions take their place. [2]
.sp
You can list the names of all functions with the functions \%<> builtin (note the plural!). fish starts out with a number of functions:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> functions
N_, abbr, alias, bg, cd, cdh, contains_seq, dirh, dirs, disown, down\-or\-search, edit_command_buffer, export, fg, fish_add_path, fish_breakpoint_prompt, fish_clipboard_copy, fish_clipboard_paste, fish_config, fish_default_key_bindings, fish_default_mode_prompt, fish_git_prompt, fish_hg_prompt, fish_hybrid_key_bindings, fish_indent, fish_is_root_user, fish_job_summary, fish_key_reader, fish_md5, fish_mode_prompt, fish_npm_helper, fish_opt, fish_print_git_action, fish_print_hg_root, fish_prompt, fish_sigtrap_handler, fish_svn_prompt, fish_title, fish_update_completions, fish_vcs_prompt, fish_vi_cursor, fish_vi_key_bindings, funced, funcsave, grep, help, history, hostname, isatty, kill, la, ll, ls, man, nextd, open, popd, prevd, prompt_hostname, prompt_pwd, psub, pushd, realpath, seq, setenv, suspend, trap, type, umask, up\-or\-search, vared, wait
.EE
.UNINDENT
.UNINDENT
.sp
You can see the source for any function by passing its name to \fBfunctions\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> functions ls
function ls \-\-description \(aqList contents of directory\(aq
command ls \-G $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
For more, see Functions \%<#\:syntax-function>\&.
.IP [2] 5
There is a function called alias \%<>, but it\(aqs just a shortcut to make functions. fish also provides abbreviations \%<#\:abbreviations>, through the abbr \%<> command.
.SS Loops
.sp
While loops:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
while true
echo \(dqLoop forever\(dq
end
# Prints:
# Loop forever
# Loop forever
# Loop forever
# yes, this really will loop forever. Unless you abort it with ctrl\-c.
.EE
.UNINDENT
.UNINDENT
.sp
For loops can be used to iterate over a list. For example, a list of files:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for file in *.txt
cp $file $file.bak
end
.EE
.UNINDENT
.UNINDENT
.sp
Iterating over a list of numbers can be done with \fBseq\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
for x in (seq 5)
touch file_$x.txt
end
.EE
.UNINDENT
.UNINDENT
.sp
For more, see Loops and blocks \%<#\:syntax-loops-and-blocks>\&.
.SS Prompt
.sp
Unlike other shells, there is no prompt variable like \fBPS1\fP\&. To display your prompt, fish executes the fish_prompt \%<> function and uses its output as the prompt. And if it exists, fish also executes the fish_right_prompt \%<> function and uses its output as the right prompt.
.sp
You can define your own prompt from the command line:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> function fish_prompt; echo \(dqNew Prompt % \(dq; end
New Prompt % _
.EE
.UNINDENT
.UNINDENT
.sp
Then, if you are happy with it, you can save it to disk by typing \fBfuncsave fish_prompt\fP\&. This saves the prompt in \fB~/.config/fish/functions/fish_prompt.fish\fP\&. (Or, if you want, you can create that file manually from the start.)
.sp
Multiple lines are OK. Colors can be set via set_color \%<> by passing it named ANSI colors, or hex RGB values:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
set_color purple
date \(dq+%m/%d/%y\(dq
set_color FF0000
echo (pwd) \(aq>\(aq (set_color \-\-reset)
end
.EE
.UNINDENT
.UNINDENT
.sp
This prompt would look like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
02/06/13
/home/tutorial > _
.EE
.UNINDENT
.UNINDENT
.sp
See also Writing your own prompt \%<>\&.
.sp
You can choose among sample prompts by running \fBfish_config\fP for a web UI or \fBfish_config prompt\fP for a simpler version inside your terminal.
.SS $PATH
.sp
\fB$PATH\fP is an environment variable containing the directories that fish searches for commands. Unlike other shells, $PATH is a list, not a colon\-delimited string.
.sp
fish takes care to set \fB$PATH\fP to a default, but typically it is just inherited from fish\(aqs parent process and is set to a value that makes sense for the system \- see Exports\&.
.sp
To prepend /usr/local/bin and /usr/sbin to \fB$PATH\fP, you can write:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set PATH /usr/local/bin /usr/sbin $PATH
.EE
.UNINDENT
.UNINDENT
.sp
To remove /usr/local/bin from \fB$PATH\fP, you can write:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set PATH (string match \-v /usr/local/bin $PATH)
.EE
.UNINDENT
.UNINDENT
.sp
For compatibility with other shells and external commands, $PATH is a path variable \%<#\:variables-path>, and so will be joined with colons (not spaces) when you quote it:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo \(dq$PATH\(dq
/usr/local/sbin:/usr/local/bin:/usr/bin
.EE
.UNINDENT
.UNINDENT
.sp
and it will be exported like that, and when fish starts it splits the $PATH it receives into a list on colon.
.sp
You can do so directly in \fBconfig.fish\fP, like you might do in other shells with \fB\&.profile\fP\&. See this example\&.
.sp
A faster way is to use the fish_add_path \%<> function, which adds given directories to the path if they aren\(aqt already included. It does this by modifying the \fB$fish_user_paths\fP universal variable, which is automatically prepended to \fB$PATH\fP\&. For example, to permanently add \fB/usr/local/bin\fP to your \fB$PATH\fP, you could write:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> fish_add_path /usr/local/bin
.EE
.UNINDENT
.UNINDENT
.sp
The advantage is that you don\(aqt have to go mucking around in files: just run this once at the command line, and it will affect the current session and all future instances too. You can also add this line to config.fish, as it only adds the component if necessary.
.sp
Or you can modify $fish_user_paths yourself, but you should be careful \fInot\fP to append to it unconditionally in config.fish, or it will grow longer and longer.
.SS Startup (Where\(aqs .bashrc?)
.sp
fish starts by executing commands in \fB~/.config/fish/config.fish\fP\&. You can create it if it does not exist.
.sp
It is possible to directly create functions and variables in \fBconfig.fish\fP file, using the commands shown above. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> cat ~/.config/fish/config.fish
set \-x PATH $PATH /sbin/
function ll
ls \-lh $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
However, it is more common and efficient to use autoloading functions and universal variables.
.sp
If you want to organize your configuration, fish also reads commands in .fish files in \fB~/.config/fish/conf.d/\fP\&. See Configuration Files \%<#\:configuration> for the details.
.SS Autoloading Functions
.sp
When fish encounters a command, it attempts to autoload a function for that command, by looking for a file with the name of that command in \fB~/.config/fish/functions/\fP\&.
.sp
For example, if you wanted to have a function \fBll\fP, you would add a text file \fBll.fish\fP to \fB~/.config/fish/functions\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> cat ~/.config/fish/functions/ll.fish
function ll
ls \-lh $argv
end
.EE
.UNINDENT
.UNINDENT
.sp
This is the preferred way to define your prompt as well:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> cat ~/.config/fish/functions/fish_prompt.fish
function fish_prompt
echo (pwd) \(dq> \(dq
end
.EE
.UNINDENT
.UNINDENT
.sp
See the documentation for funced \%<> and funcsave \%<> for ways to create these files automatically, and $fish_function_path \%<#\:syntax-function-autoloading> to control their location.
.SS Universal Variables
.sp
A universal variable is a variable whose value is shared across all instances of fish, now and in the future \- even after a reboot. You can make a variable universal with \fBset \-U\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> set \-U EDITOR vim
.EE
.UNINDENT
.UNINDENT
.sp
Now in another shell:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> echo $EDITOR
vim
.EE
.UNINDENT
.UNINDENT
.sp
You only need to set universal variables once interactively. There is no need to add them to your config files \%<#\:configuration>\&. For more details, see Universal Variables \%<#\:variables-universal>\&.
.SS Ready for more?
.sp
If you want to learn more about fish, there is lots of detailed documentation \%<#\:intro>, the official gitter channel \%, an official mailing list \%, and the github page \%\&.
.SS Writing your own completions
.sp
To specify a completion, use the \fBcomplete\fP command. \fBcomplete\fP takes as a parameter the name of the command to specify a completion for. For example, to add a completion for the program \fBmyprog\fP (or \fBmyprog.exe\fP on Cygwin/MSYS2 \%<#\:completions-cygwin>), start the completion command with \fBcomplete \-c myprog ...\fP
.sp
For a complete description of the various switches accepted by the \fBcomplete\fP command, see the documentation for the complete \%<> builtin, or write \fBcomplete \-\-help\fP inside the \fBfish\fP shell.
.sp
To provide a list of possible completions for myprog, use the \fB\-a\fP switch. If \fBmyprog\fP accepts the arguments start and stop, this can be specified as \fBcomplete \-c myprog \-a \(aqstart stop\(aq\fP\&. The argument to the \fB\-a\fP switch is always a single string. At completion time, it will be tokenized on spaces and tabs, and variable expansion, command substitution and other forms of parameter expansion will take place:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# If myprog can list the valid outputs with the list\-outputs subcommand:
complete \-c myprog \-l output \-a \(aq(myprog list\-outputs)\(aq
.EE
.UNINDENT
.UNINDENT
.sp
\fBfish\fP has a special syntax to support specifying switches accepted by a command. The switches \fB\-s\fP, \fB\-l\fP and \fB\-o\fP are used to specify a short switch (single character, such as \fB\-l\fP), a gnu style long switch (such as \fB\-\-color\fP) and an old\-style long switch (with one \fB\-\fP, like \fB\-shuffle\fP), respectively. If the command \(aqmyprog\(aq has an option that can be written as \fB\-o\fP or \fB\-\-output\fP, that is:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog \-s o \-l output
.EE
.UNINDENT
.UNINDENT
.sp
If this option takes an optional argument, you would also add \fB\-\-argument\fP or \fB\-a\fP, and give that the possible arguments:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog \-s o \-l output \-a \(dqyes no\(dq
.EE
.UNINDENT
.UNINDENT
.sp
This offers the arguments \(dqyes\(dq and \(dqno\(dq for:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> myprog \-o
> myprog \-\-output=
.EE
.UNINDENT
.UNINDENT
.sp
By default, option arguments are \fIoptional\fP, so the candidates are only offered directly attached like that, so they aren\(aqt given in this case:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> myprog \-o
.EE
.UNINDENT
.UNINDENT
.sp
Usually options \fIrequire\fP a parameter, so you would give \fB\-\-require\-parameter\fP / \fB\-r\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog \-s o \-l output \-ra \(dqyes no\(dq
.EE
.UNINDENT
.UNINDENT
.sp
which offers yes/no in these cases:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
> myprog \-o
> myprog \-\-output=
> myprog \-o
> myprog \-\-output
.EE
.UNINDENT
.UNINDENT
.sp
fish will also offer files by default, in addition to the arguments you specified. You would either inhibit file completion for a single option:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog \-s o \-l output \-\-no\-files \-ra \(dqyes no\(dq
.EE
.UNINDENT
.UNINDENT
.sp
or with a specific condition:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog \-f \-\-condition \(aq__fish_seen_subcommand_from somesubcommand\(aq
.EE
.UNINDENT
.UNINDENT
.sp
or you can disable file completions globally for the command:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
complete \-c myprog \-f
.EE
.UNINDENT
.UNINDENT
.sp
If you have disabled them globally, you can enable them just for a specific condition or option with the \fB\-\-force\-files\fP / \fB\-F\fP option:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Disable files by default
complete \-c myprog \-f
# but reenable them for \-\-config\-file
complete \-c myprog \-l config\-file \-\-force\-files \-r
.EE
.UNINDENT
.UNINDENT
.sp
As a more comprehensive example, here\(aqs a commented excerpt of the completions for systemd\(aqs \fBtimedatectl\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# All subcommands that timedatectl knows \- this is useful for later.
set \-l commands status set\-time set\-timezone list\-timezones set\-local\-rtc set\-ntp
# Disable file completions for the entire command
# because it does not take files anywhere
# Note that this can be undone by using \(dq\-F\(dq.
#
# File completions also need to be disabled
# if you want to have more control over what files are offered
# (e.g. just directories, or just files ending in \(dq.mp3\(dq).
complete \-c timedatectl \-f
# This line offers the subcommands
# \-\(dqstatus\(dq,
# \-\(dqset\-timezone\(dq,
# \-\(dqset\-time\(dq
# \-\(dqlist\-timezones\(dq
# if no subcommand has been given so far.
#
# The \(ga\-n\(ga/\(ga\-\-condition\(ga option takes script as a string, which it executes.
# If it returns true, the completion is offered.
# Here the condition is the \(ga__fish_seen_subcommand_from\(ga helper function.
# It returns true if any of the given commands is used on the commandline,
# as determined by a simple heuristic.
# For more complex uses, you can write your own function.
# See e.g. the git completions for an example.
#
complete \-c timedatectl \-n \(dqnot __fish_seen_subcommand_from $commands\(dq \e
\-a \(dqstatus set\-time set\-timezone list\-timezones\(dq
# If the \(dqset\-timezone\(dq subcommand is used,
# offer the output of \(gatimedatectl list\-timezones\(ga as completions.
# Each line of output is used as a separate candidate,
# and anything after a tab is taken as the description.
# It\(aqs often useful to transform command output with \(gastring\(ga into that form.
complete \-c timedatectl \-n \(dq__fish_seen_subcommand_from set\-timezone\(dq \e
\-a \(dq(timedatectl list\-timezones)\(dq
# Completion candidates can also be described via \(ga\-d\(ga,
# which is useful if the description is constant.
# Try to keep these short, because that means the user gets to see more at once.
complete \-c timedatectl \-n \(dqnot __fish_seen_subcommand_from $commands\(dq \e
\-a \(dqset\-local\-rtc\(dq \-d \(dqMaintain RTC in local time\(dq
# We can also limit options to certain subcommands by using conditions.
complete \-c timedatectl \-n \(dq__fish_seen_subcommand_from set\-local\-rtc\(dq \e
\-l adjust\-system\-clock \-d \(aqSynchronize system clock from the RTC\(aq
# These are simple options that can be used everywhere.
complete \-c timedatectl \-s h \-l help \-d \(aqPrint a short help text and exit\(aq
complete \-c timedatectl \-l version \-d \(aqPrint a short version string and exit\(aq
complete \-c timedatectl \-l no\-pager \-d \(aqDo not pipe output into a pager\(aq
.EE
.UNINDENT
.UNINDENT
.sp
For examples of how to write your own completions, study \fBshare/completions\fP in the fish\-shell source tree.
.SS Useful functions for writing completions
.sp
\fBfish\fP ships with several functions that may be useful when writing command\-specific completions. Most of these function names begin with the string \fB__fish_\fP\&. Such functions are internal to \fBfish\fP and their name and interface may change in future fish versions. A few of these functions are described here.
.sp
Functions beginning with the string \fB__fish_print_\fP print a newline separated list of strings. For example, \fB__fish_print_filesystems\fP prints a list of all known file systems. Functions beginning with \fB__fish_complete_\fP print out a newline separated list of completions with descriptions. The description is separated from the completion by a tab character.
.INDENT 0.0
.IP \(bu 2
\fB__fish_complete_directories STRING DESCRIPTION\fP performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
.IP \(bu 2
\fB__fish_complete_path STRING DESCRIPTION\fP performs path completion on STRING, giving them the description DESCRIPTION.
.IP \(bu 2
\fB__fish_complete_groups\fP prints a list of all user groups with the groups members as description.
.IP \(bu 2
\fB__fish_complete_pids\fP prints a list of all processes IDs with the command name as description.
.IP \(bu 2
\fB__fish_complete_suffix SUFFIX\fP performs file completion but sorts files ending in SUFFIX first. This is useful in conjunction with \fBcomplete \-\-keep\-order\fP\&.
.IP \(bu 2
\fB__fish_complete_users\fP prints a list of all users with their full name as description.
.IP \(bu 2
\fB__fish_print_filesystems\fP prints a list of all known file systems. Currently, this is a static list, and not dependent on what file systems the host operating system actually understands.
.IP \(bu 2
\fB__fish_print_hostnames\fP prints a list of all known hostnames. This function searches the fstab for nfs servers, ssh for known hosts and checks the \fB/etc/hosts\fP file.
.IP \(bu 2
\fB__fish_print_interfaces\fP prints a list of all known network interfaces.
.UNINDENT
.SS Where to put completions
.sp
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 \fB$fish_complete_path\fP, 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 \fB\&.fish\fP\&.
.sp
By default, fish searches the following for completions, using the first available file that it finds:
.INDENT 0.0
.IP \(bu 2
A directory for end\-users to keep their own completions, usually \fB~/.config/fish/completions\fP (controlled by the \fBXDG_CONFIG_HOME\fP environment variable);
.IP \(bu 2
A directory for systems administrators to install completions for all users on the system, usually \fB/etc/fish/completions\fP;
.IP \(bu 2
A user\-specified directory for third\-party vendor completions, usually \fB~/.local/share/fish/vendor_completions.d\fP (controlled by the \fBXDG_DATA_HOME\fP environment variable);
.IP \(bu 2
A directory for third\-party software vendors to ship their own completions for their software, usually \fB/usr/share/fish/vendor_completions.d\fP;
.IP \(bu 2
The completions shipped with fish, which are stored in the fish program and can be seen with \fBstatus list\-files\fP; and
.IP \(bu 2
Completions automatically generated from the operating system\(aqs manual, usually stored in \fB~/.cache/fish/generated_completions\fP (controlled by \fBXDG_CACHE_HOME\fP environment variable).
.UNINDENT
.sp
These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above.
.sp
This wide search may be confusing. If you are unsure, your completions probably belong in \fB~/.config/fish/completions\fP\&.
.sp
If you have written new completions for a common Unix command, please consider sharing your work by submitting it via the instructions in Further help and development \%<#\:more-help>\&.
.sp
If you are developing another program and would like to ship completions with your program, install them to the \(dqvendor\(dq completions directory. As this path may vary from system to system, the \fBpkgconfig\fP framework should be used to discover this path with the output of \fBpkg\-config \-\-variable completionsdir fish\fP\&.
.SS Writing your own prompt
.sp
\fBWarning:\fP
.INDENT 0.0
.INDENT 3.5
This document uses formatting to show what a prompt would look like. If you are viewing this in the man page,
you probably want to switch to looking at the html version instead. Run \fBhelp custom\-prompt\fP to view it in a web browser.
.UNINDENT
.UNINDENT
.sp
fish ships a number of prompts that you can view with the fish_config \%<> command, and many users have shared their prompts online.
.sp
However, you can also write your own, or adjust an existing prompt. This is a good way to get used to fish\(aqs scripting language \%<>\&.
.sp
Unlike other shells, fish\(aqs prompt is built by running a function \- fish_prompt \%<>\&. Or, more specifically, three functions:
.INDENT 0.0
.IP \(bu 2
fish_prompt \%<>, which is the main prompt function
.IP \(bu 2
fish_right_prompt \%<>, which is shown on the right side of the terminal.
.IP \(bu 2
fish_mode_prompt \%<>, which is shown if vi mode \%<#\:vi-mode> is used.
.UNINDENT
.sp
These functions are run, and whatever they print is displayed as the prompt (minus one trailing newline).
.sp
If the \fBSHELL_PROMPT_PREFIX\fP \%<#\:envvar-SHELL_PROMPT_PREFIX> or \fBSHELL_PROMPT_SUFFIX\fP \%<#\:envvar-SHELL_PROMPT_SUFFIX> environment variables are set, they are automatically prepended and appended to the left prompt.
.sp
Here, we will just be writing a simple fish_prompt.
.SS Our first prompt
.sp
Let\(aqs look at a very simple example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
echo $PWD \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
This prints the current working directory (\fBPWD\fP \%<#\:envvar-PWD>) and a \fB>\fP symbol to show where the prompt ends. The \fB>\fP is quoted \%<#\:quotes> because otherwise it would signify a redirection \%<#\:redirects>\&.
.sp
Because we\(aqve used echo \%<>, it adds spaces between the two so it ends up looking like (assuming \fB_\fP is your cursor):
.INDENT 0.0
.INDENT 3.5
.sp
.EX
/home/tutorial >_
.EE
.UNINDENT
.UNINDENT
.SS Formatting
.sp
\fBecho\fP adds spaces between its arguments. If you don\(aqt want those, you can use string join \%<> like this:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
string join \(aq\(aq \-\- $PWD \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
The \fB\-\-\fP indicates to \fBstring\fP that no options can come after it, in case we extend this with something that can start with a \fB\-\fP\&.
.sp
There are other ways to remove the space, including \fBecho \-s\fP and printf \%<>\&.
.SS Adding color
.sp
This prompt is functional, but a bit boring. We could add some color.
.sp
Fortunately, fish offers the set_color \%<> command, so you can do:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo (set_color red)foo
.EE
.UNINDENT
.UNINDENT
.sp
\fBset_color\fP can also handle RGB colors like \fBset_color 23b455\fP, and other formatting options including bold and italics.
.sp
So, taking our previous prompt and adding some color:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
string join \(aq\(aq \-\- (set_color green) $PWD (set_color \-\-reset) \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
\(dq\-\-reset\(dq tells the terminal to go back to its default formatting options.
.sp
\fBset_color\fP works by producing an escape sequence, which is a special piece of text that terminals
interpret as instructions \- for example, to change color. So \fBset_color red\fP produces the same
effect as:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
echo \ee\e[31m
.EE
.UNINDENT
.UNINDENT
.sp
Although you can write your own escape sequences by hand, it\(aqs much easier to use \fBset_color\fP\&.
.SS Shortening the working directory
.sp
This is fine, but our \fBPWD\fP \%<#\:envvar-PWD> can be a bit long, and we are typically only interested in the last few directories. We can shorten this with the prompt_pwd \%<> helper that will give us a shortened working directory:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
string join \(aq\(aq \-\- (set_color green) (prompt_pwd) (set_color \-\-reset) \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
\fBprompt_pwd\fP takes options to control how much to shorten. For instance, if we want to display the last two directories, we\(aqd use \fBprompt_pwd \-\-full\-length\-dirs 2\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
string join \(aq\(aq \-\- (set_color green) (prompt_pwd \-\-full\-length\-dirs 2) (set_color \-\-reset) \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
With a current directory of \(dq/home/tutorial/Music/Lena Raine/Oneknowing\(dq, this would print
.INDENT 0.0
.INDENT 3.5
.sp
.EX
~/M/Lena Raine/Oneknowing>_
.EE
.UNINDENT
.UNINDENT
.SS Status
.sp
One important bit of information that every command returns is the status \%<#\:variables-status>\&. This is a whole number from 0 to 255, and usually it is used as an error code \- 0 if the command returned successfully, or a number from 1 to 255 if not.
.sp
It\(aqs useful to display this in your prompt, but showing it when it\(aqs 0 seems kind of wasteful.
.sp
First of all, since every command (except for set \%<>) changes the status, you need to store it for later use as the first thing in your prompt. Use a local variable \%<#\:variables-scope> so it will be confined to your prompt function:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-l last_status $status
.EE
.UNINDENT
.UNINDENT
.sp
And after that, you can set a string if it is not zero:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
# Prompt status only if it\(aqs not 0
set \-l stat
if test $last_status \-ne 0
set stat (set_color red)\(dq[$last_status]\(dq(set_color \-\-reset)
end
.EE
.UNINDENT
.UNINDENT
.sp
And to print it, we add it to our \fBstring join\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
string join \(aq\(aq \-\- (set_color green) (prompt_pwd) (set_color \-\-reset) $stat \(aq>\(aq
.EE
.UNINDENT
.UNINDENT
.sp
If \fB$last_status\fP was 0, \fB$stat\fP is empty, and so it will simply disappear.
.sp
So our entire prompt is now:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
set \-l last_status $status
# Prompt status only if it\(aqs not 0
set \-l stat
if test $last_status \-ne 0
set stat (set_color red)\(dq[$last_status]\(dq(set_color \-\-reset)
end
string join \(aq\(aq \-\- (set_color green) (prompt_pwd) (set_color \-\-reset) $stat \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
And it looks like:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
~/M/L/Oneknowing>false
~/M/L/Oneknowing[1]>_
.EE
.UNINDENT
.UNINDENT
.sp
after we run \fBfalse\fP (which returns 1).
.SS Transient prompt
.sp
To enable transient prompt functionality, set the \fBfish_transient_prompt\fP \%<#\:envvar-fish_transient_prompt> variable to 1:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
set \-g fish_transient_prompt 1
.EE
.UNINDENT
.UNINDENT
.sp
With this set, fish re\-runs prompt functions with a \fB\-\-final\-rendering\fP argument before running a commandline.
So you can use it to declutter your old prompts. For example if you want to see only the current directory name when you scroll up:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
function fish_prompt
set \-l last_status $status
set \-l stat
set \-l pwd
# Check if it\(aqs a transient or final prompt
if contains \-\- \-\-final\-rendering $argv
set pwd (path basename $PWD)
else
set pwd (prompt_pwd)
# Prompt status only if it\(aqs not 0
if test $last_status \-ne 0
set stat (set_color red)\(dq[$last_status]\(dq(set_color \-\-reset)
end
end
string join \(aq\(aq \-\- (set_color green) $pwd (set_color \-\-reset) $stat \(aq>\(aq
end
.EE
.UNINDENT
.UNINDENT
.sp
Now running two commands in the same directory could result in this screen:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
Oneknowing>false
~/M/L/Oneknowing[1]>_
.EE
.UNINDENT
.UNINDENT
.SS Save the prompt
.sp
Once you are happy with your prompt, you can save it with \fBfuncsave fish_prompt\fP (see funcsave \- save the definition of a function to the user\(aqs autoload directory \%<>) or write it to ~/.config/fish/functions/fish_prompt.fish yourself.
.sp
If you want to edit it again, open that file or use \fBfunced fish_prompt\fP (see funced \- edit a function interactively \%<>).
.SS Where to go from here?
.sp
We have now built a simple but working and usable prompt, but of course more can be done.
.INDENT 0.0
.IP \(bu 2
.INDENT 2.0
.TP
.B fish offers more helper functions:
.INDENT 7.0
.IP \(bu 2
\fBprompt_login\fP to describe the user/hostname/container or \fBprompt_hostname\fP to describe just the host
.IP \(bu 2
\fBfish_is_root_user\fP to help with changing the symbol for root.
.IP \(bu 2
\fBfish_vcs_prompt\fP to show version control information (or \fBfish_git_prompt\fP / \fBfish_hg_prompt\fP / \fBfish_svn_prompt\fP to limit it to specific systems)
.UNINDENT
.UNINDENT
.IP \(bu 2
You can add a right prompt by changing fish_right_prompt \%<> or a vi mode prompt by changing fish_mode_prompt \%<>\&.
.IP \(bu 2
.INDENT 2.0
.TP
.B Some prompts have interesting or advanced features
.INDENT 7.0
.IP \(bu 2
Add the time when the prompt was printed
.IP \(bu 2
Show various integrations like python\(aqs venv
.IP \(bu 2
Color the parts differently.
.UNINDENT
.UNINDENT
.UNINDENT
.sp
You can look at fish\(aqs sample prompts for inspiration. Open up fish_config \%<>, find one you like and pick it. For example:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
fish_config prompt show # <\- shows all the sample prompts
fish_config prompt choose disco # <\- this picks the \(dqdisco\(dq prompt for this session
funced fish_prompt # <\- opens fish_prompt in your editor, and reloads it once the editor exits
.EE
.UNINDENT
.UNINDENT
.SS Design
.sp
This is a description of the design principles that have been used to design fish. The fish design has three high level goals. These are:
.INDENT 0.0
.IP 1. 3
Everything that can be done in other shell languages should be possible to do in fish, though fish may rely on external commands in doing so.
.IP 2. 3
fish should be user\-friendly, but not at the expense of expressiveness. Most tradeoffs between power and ease of use can be avoided with careful design.
.IP 3. 3
Whenever possible without breaking the above goals, fish should follow POSIX.
.UNINDENT
.sp
To achieve these high\-level goals, the fish design relies on a number of more specific design principles. These are presented below, together with a rationale and a few examples for each.
.SS The law of orthogonality
.sp
The shell language should have a small set of orthogonal features. Any situation where two features are related but not identical, one of them should be removed, and the other should be made powerful and general enough to handle all common use cases of either feature.
.sp
Rationale:
Related features make the language larger, which makes it harder to learn. It also increases the size of the source code, making the program harder to maintain and update.
.sp
Examples:
.INDENT 0.0
.IP \(bu 2
Here documents are too similar to using echo inside of a pipeline.
.IP \(bu 2
Subshells, command substitution and process substitution are strongly related. \fBfish\fP only supports command substitution, the others can be achieved either using a block or the psub shellscript function.
.IP \(bu 2
Having both aliases and functions is confusing, especially since both of them have limitations and problems. \fBfish\fP functions have none of the drawbacks of either syntax.
.IP \(bu 2
The many Posix quoting styles are silly, especially \fB$\fP\&.
.UNINDENT
.SS The law of responsiveness
.sp
The shell should attempt to remain responsive to the user at all times, even in the face of contended or unresponsive filesystems. It is only acceptable to block in response to a user initiated action, such as running a command.
.sp
Rationale:
Bad performance increases user\-facing complexity, because it trains users to recognize and route around slow use cases. It is also incredibly frustrating.
.sp
Examples:
.INDENT 0.0
.IP \(bu 2
Features like syntax highlighting and autosuggestions must perform all of their disk I/O asynchronously.
.IP \(bu 2
Startup should minimize forks and disk I/O, so that fish can be started even if the system is under load.
.UNINDENT
.SS Configurability is the root of all evil
.sp
Every configuration option in a program is a place where the program is too stupid to figure out for itself what the user really wants, and should be considered a failure of both the program and the programmer who implemented it.
.sp
Rationale:
Different configuration options are a nightmare to maintain, since the number of potential bugs caused by specific configuration combinations quickly becomes an issue. Configuration options often imply assumptions about the code which change when reimplementing the code, causing issues with backwards compatibility. But mostly, configuration options should be avoided since they simply should not exist, as the program should be smart enough to do what is best, or at least a good enough approximation of it.
.sp
Examples:
.INDENT 0.0
.IP \(bu 2
fish allows the user to set various syntax highlighting colors. This is needed because fish does not know what colors the terminal uses by default, which might make some things unreadable. The proper solution would be for text color preferences to be defined centrally by the user for all programs, and for the terminal emulator to send these color properties to fish.
.IP \(bu 2
fish does not allow you to set the number of history entries, different language substyles or any number of other common shell configuration options.
.UNINDENT
.sp
A special note on the evils of configurability is the long list of very useful features found in some shells, that are not turned on by default. Both zsh and bash support command\-specific completions, but no such completions are shipped with bash by default, and they are turned off by default in zsh. Other features that zsh supports that are disabled by default include tab\-completion of strings containing wildcards, a sane completion pager and a history file.
.SS The law of user focus
.sp
When designing a program, one should first think about how to make an intuitive and powerful program. Implementation issues should only be considered once a user interface has been designed.
.sp
Rationale:
This design rule is different than the others, since it describes how one should go about designing new features, not what the features should be. The problem with focusing on what can be done, and what is easy to do, is that too much of the implementation is exposed. This means that the user must know a great deal about the underlying system to be able to guess how the shell works, it also means that the language will often be rather low\-level.
.sp
Examples:
.INDENT 0.0
.IP \(bu 2
There should only be one type of input to the shell, lists of commands. Loops, conditionals and variable assignments are all performed through regular commands.
.IP \(bu 2
The differences between built\-in commands and shellscript functions should be made as small as possible. Built\-ins and shellscript functions should have exactly the same types of argument expansion as other commands, should be possible to use in any position in a pipeline, and should support any I/O redirection.
.IP \(bu 2
Instead of forking when performing command substitution to provide a fake variable scope, all fish commands are performed from the same process, and fish instead supports true scoping.
.IP \(bu 2
All blocks end with the \fBend\fP built\-in.
.UNINDENT
.SS The law of discoverability
.sp
A program should be designed to make its features as easy as possible to discover for the user.
.sp
Rationale:
A program whose features are discoverable turns a new user into an expert in a shorter span of time, since the user will become an expert on the program simply by using it.
.sp
The main benefit of a graphical program over a command\-line\-based program is discoverability. In a graphical program, one can discover all the common features by simply looking at the user interface and guessing what the different buttons, menus and other widgets do. The traditional way to discover features in command\-line programs is through manual pages. This requires both that the user starts to use a different program, and then they remember the new information until the next time they use the same program.
.sp
Examples:
.INDENT 0.0
.IP \(bu 2
Everything should be tab\-completable, and every tab completion should have a description.
.IP \(bu 2
Every syntax error and error in a built\-in command should contain an error message describing what went wrong and a relevant help page. Whenever possible, errors should be flagged red by the syntax highlighter.
.IP \(bu 2
The help manual should be easy to read, easily available from the shell, complete and contain many examples
.IP \(bu 2
The language should be uniform, so that once the user understands the command/argument syntax, they will know the whole language, and be able to use tab\-completion to discover new features.
.UNINDENT
.SS Release notes
.SS fish 4.9.2 (released September 05, 2026)
.sp
This release corrects the fix for macOS terminals from 4.9.1 (#12973 \%)
.SS fish 4.9.1 (released September 04, 2026)
.sp
This release fixes the following problems identified in fish 4.9.0:
.INDENT 0.0
.IP \(bu 2
On non\-default keyboard layouts, fish executed bindings for physical keys instead of only bindings for the layout\(aqs key.
For example, on the Dvorak layout, typing \fBs\fP would insert \fB;\fP because there is a default binding for \fB;\fP (#12968 \%).
.IP \(bu 2
When typing \fBspace\fP to accept a character entered via certain IMEs, fish would insert a space instead of the desired character, which has been fixed (#12974 \%).
.IP \(bu 2
On macOS terminals, keys like \fBoption\fP\-\fBl\fP would execute bindings for \fBalt\fP\-\fBl\fP instead of the historical behavior of inserting a character (like \fB@\fP on a German layout) (#12973 \%).
.UNINDENT
.SS fish 4.9.0 (released September 03, 2026)
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
To mitigate issues in Konsole version v26.07.80\(aqs implementation of the kitty keyboard protocol, fish no longer requests that protocol on Konsole.
The \fBomit\-term\-workarounds\fP feature flag \%<#\:featureflags> can be turned on to enable the kitty keyboard protocol on Konsole again (#12948 \%).
.IP \(bu 2
On some terminals like kitty, keys like \fBshift\fP\-\fBspace\fP and \fBspace\fP can now be mapped independently (#12898 \%).
.IP \(bu 2
Fixed slow tab completion in directories that contain slow\-to\-resolve symlinks (e.g. links to network\-mounted files) (#12905 \%).
.IP \(bu 2
Abbreviations can now be given a description, which will be displayed in the completion pager (#11291 \%).
.IP \(bu 2
Vi mode commands like \fBcF\fP and \fBcT\fP now work correctly (#12947 \%).
.UNINDENT
.SS Scripting improvements
.INDENT 0.0
.IP \(bu 2
List indexing can now be nested in more cases; for example \fB$foo[$bar[1] 2]\fP is now allowed (#12903 \%).
.IP \(bu 2
Escaped square brackets (e.g. \fB\e133\fP for \fB[\fP) are no longer considered a slicing operator (#7969 \%).
.IP \(bu 2
Variables containing a closing square brackets and used to index into another variable will no longer close the slice early (#12819 \%).
.IP \(bu 2
Builtin help pages now respect an override of the \fBman\fP function (#12886 \%).
.IP \(bu 2
Commands like \fBstatus=123 echo $status\fP now throw an error instead of silently ignore the variable override (#7790 \%).
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(From 4.6.0) Chinese and Japanese translation of error messages owned by the C library were broken (#12895 \%).
.IP \(bu 2
(From 4.3.2) Erasing read\-only variables with \fBset \-\-erase\fP was accidentally allowed.
.IP \(bu 2
(From 4.0.0) Builtin \fBfg\fP was not working on NetBSD (#12929 \%).
.UNINDENT
.SS fish 4.8.1 (released July 14, 2026)
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
On non\-macOS platforms, \fBalt\fP\-\fBbackspace\fP, \fBalt\fP\-\fBdelete\fP, \fBalt\fP\-\fBleft\fP and \fBalt\fP\-\fBright\fP operate on words again instead of tokens (#12122 \%) eliminating cross\-platform differences in input handling.
.IP \(bu 2
Builtin and function commands can now be colored separately via new variables \fBfish_color_builtin\fP \%<#\:envvar-fish_color_builtin> and \fBfish_color_function\fP \%<#\:envvar-fish_color_function> (#12837 \%).
.IP \(bu 2
Add fish_darcs_prompt \%<> for Darcs \% repository status.
.IP \(bu 2
Fixed a crash in \fBcommandline \-\-current\-process\fP when the cursor is inside a \fB&|\fP pipe (#12868 \%).
.IP \(bu 2
Since prompt marking (via OSC 133 \%<#\:term-compat-osc-133>) causes an issue in Konsole\(aqs \% default configuration, prompt marking had been disabled for Konsole in 4.8.0.
Now the \fBomit\-term\-workarounds\fP feature flag \%<#\:featureflags> can be enabled to enable prompt marking on Konsole again (#12859 \%).
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(From 4.8.0) \fBabbr \-\-position=anywhere\fP completions are no longer offered in argument position, to avoid cluttering the completion pager (#12838 \%).
.IP \(bu 2
(From 4.8.0) \fBpacman \-Q\fP short option completions (#12857 \%).
.UNINDENT
.SS fish 4.8.0 (released June 24, 2026)
.SS Notable improvements and fixes
.INDENT 0.0
.IP \(bu 2
Translatable messages defined in Rust source code can and should now be translated using Fluent \% instead of GNU gettext.
For now, GNU gettext continues to be used for translating messages defined in fish scripts.
To make Fluent easy to work with, we have added tooling based on the new fluent\-ftl\-tools \% library.
See Contributing Translations \%<#\:localization> (#11928 \%).
.UNINDENT
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
Builtin complete\(aqs \%<> \fB\-\-command\fP and \fB\-\-path\fP options no longer unescape their argument.
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
History search would sometimes forget about commands after those were re\-run in concurrent sessions. This has been fixed (#10300 \%).
.IP \(bu 2
\fBfish_hg_prompt\fP, \fBfish_git_prompt\fP and \fBfish_fossil_prompt\fP now strip control characters from VCS state read off disk, matching \fBprompt_pwd\fP\&.
.IP \(bu 2
Abbreviations with \fB\-\-position=anywhere\fP can now be completed in argument position, not just in command position (#12630 \%).
.IP \(bu 2
Path component movement (\fBctrl\fP\-\fBw\fP) skips escaped characters.
.IP \(bu 2
Completion of short option groups will now handle \fB\-\-condition\fP correctly (#12821 \%).
.IP \(bu 2
Fixed an issue where \fBctrl\fP\-\fBc\fP might fail to cancel certain functions (#12802 \%).
.IP \(bu 2
On the first run after upgrading from an older version, fish will try harder to check if the current theme matches a historical default.
If it does match, fish won\(aqt create \fB~/.config/fish/conf.d/fish_frozen_theme.fish\fP when upgrading from fish < 4.3.
In particular, on systems where fish version 3.x was installed originally, fish will now avoid creating that file on upgrade (#12725 \%).
.UNINDENT
.SS Scripting improvements
.INDENT 0.0
.IP \(bu 2
\fBcd\fP supports the \fB\-L\fP and \fB\-P\fP options, like other shells, to allow specifying whether symbolic links (symlinks) are resolved when changing directories (#7206 \%).
.IP \(bu 2
\fBcd\fP with a relative path will now retry using the real current directory, if \fB$PWD\fP has been moved (#12700 \%).
.IP \(bu 2
Nested brace expansions now strip unquoted leading and trailing spaces from entries consistently (#12794 \%).
.IP \(bu 2
bind \%<> shows the files where bindings were defined (#12504 \%).
.UNINDENT
.SS Other improvements
.INDENT 0.0
.IP \(bu 2
fish no longer creates the \fB__fish_initialized\fP universal variable on startup.
If you don\(aqt expect to need to downgrade to earlier versions, you can remove it with \fBset \-\-erase __fish_initialized\fP\&.
This means that fish now only creates universal variables if instructed by the user.
.UNINDENT
.SS For distributors and developers
.INDENT 0.0
.IP \(bu 2
With the exception of the \fB$CMAKE_INSTALL_PREFIX/share/fish/man\fP directory, fish no longer installs files to \fB$CMAKE_INSTALL_PREFIX/share/fish\fP\&.
In particular, this means that both
\fB$CMAKE_INSTALL_PREFIX/share/fish/completions\fP and
\fB$CMAKE_INSTALL_PREFIX/share/fish/functions\fP
should no longer exist.
These directories have been ignored since fish 4.2.
If another package installs fish scripts there, they should be corrected to install to
\fBextra_completionsdir\fP (typically \fB$CMAKE_INSTALL_PREFIX/share/fish/vendor_completions.d\fP),
\fBextra_functionsdir\fP (typically \fB$CMAKE_INSTALL_PREFIX/share/fish/vendor_functions.d\fP) or
\fBextra_confdir\fP (typically \fB$CMAKE_INSTALL_PREFIX/share/fish/vendor_functions.d\fP) instead.
See also the output of \fBfor var in completions functions conf; pkgconf fish \-\-variable=\(dq$var\(dqdir; end\fP\&.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.4.0) Vi mode \fBc,W\fP key binding wrongly deleted trailing spaces (#12790 \%).
.IP \(bu 2
(from 4.4.0) Vi mode \fBx\fP in builtin read \%<> (#12724 \%).
.IP \(bu 2
(from 4.3.3) Repeated tab would sometimes insert smartcase completions redundantly.
.IP \(bu 2
(from 4.3.0) Pressing escape during command execution could insert garbage text into the command line (#12379 \%).
.UNINDENT
.SS fish 4.7.1 (released May 08, 2026)
.sp
This release fixes a regression in 4.7.0 that caused the web config (\fBfish_config\fP) to fail to start (#12717 \%).
.SS fish 4.7.0 (released May 05, 2026)
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
The default theme (i.e. the \fBfish_color_*\fP variables) is no longer set in non\-interactive shells.
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
prompt_pwd \%<> now strips control characters.
.IP \(bu 2
Repaint events (as triggered by changes to color variables or by event handlers running \fBcommandline \-f repaint\fP) no longer reset the completion pager and other transient UI states (#12683 \%).
.IP \(bu 2
\fBfish_color_valid_path\fP \%<#\:envvar-fish_color_valid_path> now respects background and underline colors (#12622 \%).
.IP \(bu 2
funced \%<> will no longer lose work if there are parse errors multiple times without new changes to the file.
.IP \(bu 2
Fixed a case where directory completions were sorted in a surprising order (#12695 \%).
.IP \(bu 2
When at the command token, the \fBalt\fP\-\fBo\fP binding will now open read\-only files too (#12671 \%).
.IP \(bu 2
Private mode in\-memory history (\fBset fish_history\fP) is no longer shared with builtin read \%<> (#12662 \%).
.UNINDENT
.SS Other improvements
.INDENT 0.0
.IP \(bu 2
History is no longer corrupted with NUL bytes when fish receives SIGTERM or SIGHUP (#10300 \%).
.IP \(bu 2
fish_update_completions \%<> now handles groff \fB\eX\(aq...\(aq\fP device control escapes, fixing completion generation for man pages produced by help2man 1.50 and later (such as coreutils 9.10).
.IP \(bu 2
Removing history entries via the web\-based config \%<> is more intuitive.
.IP \(bu 2
If \fBXDG_DATA_DIRS\fP is empty, the default value is assumed, which means that fish will now also use configuration from paths like \fB$PREFIX/share/fish/vendor_completions.d\fP (#11349 \%).
.IP \(bu 2
Some internal file descriptors were moved to number 10 or higher, to reduce risk of clashes with those used by the user in scripts.
.IP \(bu 2
The wording of error messages has been made consistent, especially for builtin subcommands (#12556 \%).
.UNINDENT
.SS For distributors and developers
.INDENT 0.0
.IP \(bu 2
When the default global config directory (\fB$PREFIX/etc/fish\fP) exists but has been overridden via \fB\-DCMAKE_INSTALL_SYSCONFDIR\fP, fish will now respect that override (#10748 \%).
.IP \(bu 2
\fBbuild_tools/update_translations.fish\fP has been replaced by \fBcargo xtask gettext {check,new,update}\fP (#12676 \%).
.IP \(bu 2
\fBcargo xtask shellcheck\fP to lint shell\-scripts.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.6) Vi mode \fBdl\fP (#12461 \%).
.IP \(bu 2
(from 4.6) Backspace after newline (#12583 \%).
.IP \(bu 2
(from 4.3.3) Long options were spuriously completed after typing short options (85e76ba3561).
.IP \(bu 2
(from 3.2) \fBnosuchcommand || echo hello\fP executes the right hand side again (#12654 \%).
.UNINDENT
.SS fish 4.6.0 (released March 28, 2026)
.SS Notable improvements and fixes
.INDENT 0.0
.IP \(bu 2
New Spanish translations (#12489 \%).
.IP \(bu 2
New Japanese translations (#12499 \%).
.UNINDENT
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
The default width for emoji is switched from 1 to 2, improving the experience for users connecting to old systems from modern desktops. Users of old desktops who notice that lines containing emoji are misaligned can set \fB$fish_emoji_width\fP back to 1 (#12562 \%).
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
The tab completion pager now left\-justifies the description of each column (#12546 \%).
.IP \(bu 2
fish now supports the \fBSHELL_PROMPT_PREFIX\fP, \fBSHELL_PROMPT_SUFFIX\fP, and \fBSHELL_WELCOME\fP environment variables. The prefix and suffix are automatically prepended and appended to the left prompt, and the welcome message is displayed on startup after the greeting.
These variables are set by systemd\(aqs \fBrun0\fP for example (#10924 \%).
.UNINDENT
.SS Improved terminal support
.INDENT 0.0
.IP \(bu 2
\fBset_color\fP is able to turn off italics, reverse mode, strikethrough and underline individually (e.g. \fB\-\-italics=off\fP).
.IP \(bu 2
\fBset_color\fP learned the foreground (\fB\-\-foreground\fP or \fB\-f\fP) and reset (\fB\-\-reset\fP) options.
.IP \(bu 2
An error caused by slow terminal responses at macOS startup has been addressed (#12571 \%).
.UNINDENT
.SS Other improvements
.INDENT 0.0
.IP \(bu 2
Signals like \fBSIGWINCH\fP (as sent on terminal resize) no longer interrupt builtin output (#12496 \%).
.IP \(bu 2
For compatibility with Bash, fish now accepts \fB|&\fP as alternate spelling of \fB&|\fP, for piping both standard output and standard error (#11516 \%).
.IP \(bu 2
\fBfish_indent\fP now preserves comments and newlines immediately preceding a brace block (\fB{ }\fP) (#12505 \%).
.IP \(bu 2
A crash when suspending certain pipelines with \fBctrl\fP\-\fBz\fP has been fixed (#12301 \%).
.UNINDENT
.SS For distributors and developers
.INDENT 0.0
.IP \(bu 2
\fBcargo xtask\fP subcommands no longer panic on test failures.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.5.0) Intermediate \fB⏎\fP artifact when redrawing prompt (#12476 \%).
.IP \(bu 2
(from 4.4.0) \fBhistory\fP honors explicitly specified \fB\-\-color=\fP again (#12512 \%).
.IP \(bu 2
(from 4.4.0) Vi mode \fBdl\fP and \fBdh\fP (#12461 \%).
.IP \(bu 2
(from 4.3.0) Error completing of commands starting with \fB\-\fP (#12522 \%).
.UNINDENT
.SS fish 4.5.0 (released February 17, 2026)
.sp
This is mostly a patch release for Vi mode regressions in 4.4.0 but other minor behavior changes are included as well.
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
\fBctrl\fP\-\fBl\fP no longer cancels history search (#12436 \%).
.IP \(bu 2
History search cursor positioning now works correctly with characters of arbitrary width.
.UNINDENT
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
fish no longer reads the terminfo database to alter behaviour based on the \fBTERM\fP environment variable, and does not depend on ncurses or terminfo. The \fBignore\-terminfo\fP feature flag, introduced and enabled by default in fish 4.1, is now permanently enabled. fish may no longer work correctly on Data General Dasher D220 and Wyse WY\-350 terminals, but should continue to work on all known terminal emulators released in the 21st century.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.4.0) Vi mode \fBd,f\fP key binding did not work (#12417 \%).
.IP \(bu 2
(from 4.4.0) Vi mode \fBc,w\fP key binding wrongly deleted trailing spaces (#12443 \%).
.IP \(bu 2
(from 4.4.0) Vi mode crash on \fBc,i,w\fP after accepting autosuggestion (#12430 \%).
.IP \(bu 2
(from 4.4.0) \fBfish_vi_key_bindings\fP called with a mode argument produced an error (#12413 \%).
.IP \(bu 2
(from 4.0.0) Build on Illumos (#12410 \%).
.UNINDENT
.SS fish 4.4.0 (released February 03, 2026)
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
The default fossil prompt has been disabled (#12342 \%).
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
The \fBbind\fP builtin lists mappings from all modes if \fB\-\-mode\fP is not provided (#12214 \%).
.IP \(bu 2
Line\-wise autosuggestions that don\(aqt start a command are no longer shown (739b82c34db, 58e7a50de8a).
.IP \(bu 2
Builtin \fBhistory\fP now assumes that \fBPAGER\fP supports ANSI color sequences.
.IP \(bu 2
fish now clears the terminal\(aqs \fBFLUSHO\fP flag when acquiring control of the terminal, to fix an issue caused by pressing \fBctrl\fP\-\fBo\fP on macOS (#12304 \%).
.UNINDENT
.SS New or improved bindings
.INDENT 0.0
.IP \(bu 2
Vi mode word movements (\fBw\fP, \fBW\fP, \fBe\fP, and \fBE\fP) are now largely in line with Vim. The only exception is that underscores are treated as word separators (#12269 \%).
.IP \(bu 2
New special input functions to support these movements: \fBforward\-word\-vi\fP, \fBkill\-word\-vi\fP, \fBforward\-bigword\-vi\fP, \fBkill\-bigword\-vi\fP, \fBforward\-word\-end\fP, \fBbackward\-word\-end\fP, \fBforward\-bigword\-end\fP, \fBbackward\-bigword\-end\fP, \fBkill\-a\-word\fP, \fBkill\-inner\-word\fP, \fBkill\-a\-bigword\fP, and \fBkill\-inner\-bigword\fP\&.
.IP \(bu 2
Vi mode key bindings now support counts for movement and deletion commands (e.g. \fId3w\fP or \fI3l\fP), via a new operator mode (#2192 \%).
.IP \(bu 2
New \fBcatppuccin\-*\fP color themes.
.UNINDENT
.SS Improved terminal support
.INDENT 0.0
.IP \(bu 2
\fBset_color\fP learned the strikethrough (\fB\-\-strikethrough\fP or \fB\-s\fP) modifier.
.UNINDENT
.SS For distributors and developers
.INDENT 0.0
.IP \(bu 2
The CMake option \fBWITH_GETTEXT\fP has been renamed to \fBWITH_MESSAGE_LOCALIZATION\fP, to reflect that it toggles localization independently of the backend used in the implementation.
.IP \(bu 2
New \fBcargo xtask\fP commands can replace some CMake workflows.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.1.0) Crash when autosuggesting Unicode characters with nontrivial lowercase mapping (#12326 \%, 78f4541116e).
.IP \(bu 2
(from 4.3.0) Glitch on \fBread \-\-prompt\-str \(dq\(dq\fP (#12296 \%).
.UNINDENT
.SS fish 4.3.3 (released January 07, 2026)
.sp
This release fixes the following problems identified in fish 4.3.0:
.INDENT 0.0
.IP \(bu 2
Selecting a completion could insert only part of the token (#12249 \%).
.IP \(bu 2
Glitch with soft\-wrapped autosuggestions and fish_right_prompt \%<> (#12255 \%).
.IP \(bu 2
Spurious echo in tmux when typing a command really fast (#12261 \%).
.IP \(bu 2
\fBtomorrow\fP theme always using the light variant (#12266 \%).
.IP \(bu 2
\fBfish_config theme choose\fP sometimes not shadowing themes set by e.g. webconfig (#12278 \%).
.IP \(bu 2
The sample prompts and themes are correctly installed (#12241 \%).
.IP \(bu 2
Last line of command output could be hidden when missing newline (#12246 \%).
.UNINDENT
.sp
Other improvements include:
.INDENT 0.0
.IP \(bu 2
The \fBabbr\fP, \fBbind\fP, \fBcomplete\fP, \fBfunctions\fP, \fBhistory\fP and \fBtype\fP commands now support a \fB\-\-color\fP option to control syntax highlighting in their output. Valid values are \fBauto\fP (default), \fBalways\fP, or \fBnever\fP\&.
.IP \(bu 2
Existing file paths in redirection targets such as \fB> file.txt\fP are now highlighted using \fBfish_color_valid_path\fP \%<#\:envvar-fish_color_valid_path>, indicating that \fBfile.txt\fP will be clobbered (#12260 \%).
.UNINDENT
.SS fish 4.3.2 (released December 30, 2025)
.sp
This release fixes the following problems identified in 4.3.0:
.INDENT 0.0
.IP \(bu 2
Pre\-built macOS packages failed to start due to a \fBMalformed Mach\-O file\fP error (#12224 \%).
.IP \(bu 2
\fBextra_functionsdir\fP (usually \fBvendor_functions.d\fP) and friends were not used (#12226 \%).
.IP \(bu 2
Sample config file \fB~/.config/fish/config.fish/\fP and config directories \fB~/.config/fish/conf.d/\fP, \fB~/.config/fish/completions/\fP and \fB~/.config/fish/functions/\fP were recreated on every startup instead of only the first time fish runs on a system (#12230 \%).
.IP \(bu 2
Spurious echo of \fB^[[I\fP in some scenarios (#12232 \%).
.IP \(bu 2
Infinite prompt redraw loop on some prompts (#12233 \%).
.IP \(bu 2
The removal of pre\-built HTML docs from tarballs revealed that cross compilation is broken because we use \fB${CMAKE_BINARY_DIR}/fish_indent\fP for building HTML docs.
As a workaround, the new CMake build option \fBFISH_INDENT_FOR_BUILDING_DOCS\fP can be set to the path of a runnable \fBfish_indent\fP binary.
.UNINDENT
.SS fish 4.3.1 (released December 28, 2025)
.sp
This release fixes the following problem identified in 4.3.0:
.INDENT 0.0
.IP \(bu 2
Possible crash after expanding an abbreviation (#12223 \%).
.UNINDENT
.SS fish 4.3.0 (released December 28, 2025)
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
fish no longer sets user\-facing universal variables \%<#\:variables-universal> by default, making the configuration easier to understand.
Specifically, the \fBfish_color_*\fP, \fBfish_pager_color_*\fP and \fBfish_key_bindings\fP variables are now set in the global scope by default.
After upgrading to 4.3.0, fish will (once and never again) migrate these universals to globals set at startup in the
\fB~/.config/fish/conf.d/fish_frozen_theme.fish\fP and
\fB~/.config/fish/conf.d/fish_frozen_key_bindings.fish\fP files.
We suggest that you delete those files and set your theme \%<#\:syntax-highlighting> in \fB~/.config/fish/config.fish\fP\&.
.INDENT 2.0
.IP \(bu 2
You can still configure fish to propagate theme changes instantly; see here \%<#\:syntax-highlighting-instant-update> for an example.
.IP \(bu 2
You can still opt into storing color variables in the universal scope
via \fBfish_config theme save\fP though unlike \fBfish_config theme choose\fP,
it does not support dynamic theme switching based on the terminal\(aqs color theme (see below).
.UNINDENT
.IP \(bu 2
In addition to setting the variables which are explicitly defined in the given theme,
\fBfish_config theme choose\fP now clears only color variables that were set by earlier invocations of a \fBfish_config theme choose\fP command
(which is how fish\(aqs default theme is set).
.UNINDENT
.SS Scripting improvements
.INDENT 0.0
.IP \(bu 2
New status language \%<#\:status-language> command allows showing and modifying language settings for fish messages without having to modify environment variables.
.IP \(bu 2
When using a noninteractive fish instance to compute completions, \fBcommandline \-\-cursor\fP works as expected instead of throwing an error (#11993 \%).
.IP \(bu 2
\fBfish_trace\fP \%<#\:envvar-fish_trace> can now be set to \fBall\fP to also trace execution of key bindings, event handlers as well as prompt and title functions.
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
When typing immediately after starting fish, the first prompt is now rendered correctly.
.IP \(bu 2
Completion accuracy was improved for file paths containing \fB=\fP or \fB:\fP (#5363 \%).
.IP \(bu 2
Prefix\-matching completions are now shown even if they don\(aqt match the case typed by the user (#7944 \%).
.IP \(bu 2
On Cygwin/MSYS, command name completion will favor the non\-exe name (\fBfoo\fP) unless the user started typing the extension.
.IP \(bu 2
When using the exe name (\fBfoo.exe\fP), fish will use the description and completions for \fBfoo\fP if there are none for \fBfoo.exe\fP\&.
.IP \(bu 2
Autosuggestions now also show soft\-wrapped portions (#12045 \%).
.UNINDENT
.SS New or improved bindings
.INDENT 0.0
.IP \(bu 2
\fBctrl\fP\-\fBw\fP (\fBbackward\-kill\-path\-component\fP) also deletes escaped spaces (#2016 \%).
.IP \(bu 2
New special input functions \fBbackward\-path\-component\fP, \fBforward\-path\-component\fP and \fBkill\-path\-component\fP (#12127 \%).
.UNINDENT
.SS Improved terminal support
.INDENT 0.0
.IP \(bu 2
Themes can now be made color\-theme\-aware by including both \fB[light]\fP and \fB[dark]\fP sections in the theme file \%<#\:fish-config-theme-files>\&.
Some default themes have been made color\-theme\-aware, meaning they dynamically adjust as your terminal\(aqs background color switches between light and dark colors (#11580 \%).
.IP \(bu 2
The working directory is now reported on every fresh prompt (via OSC 7), fixing scenarios where a child process (like \fBssh\fP) left behind a stale working directory (#12191 \%).
.IP \(bu 2
OSC 133 prompt markers now also mark the prompt end, which improves shell integration with terminals like iTerm2 (#11837 \%).
.IP \(bu 2
Operating\-system\-specific key bindings are now decided based on the terminal\(aqs host OS \%<#\:status-terminal-os>\&.
.IP \(bu 2
New feature flag \%<#\:featureflags> \fBomit\-term\-workarounds\fP can be turned on to prevent fish from trying to work around some incompatible terminals.
.UNINDENT
.SS For distributors and developers
.INDENT 0.0
.IP \(bu 2
Tarballs no longer contain prebuilt documentation,
so building and installing documentation requires Sphinx.
To avoid users accidentally losing docs, the \fBBUILD_DOCS\fP and \fBINSTALL_DOCS\fP configuration options have been replaced with a new \fBWITH_DOCS\fP option.
.IP \(bu 2
\fBfish_key_reader\fP and \fBfish_indent\fP are now installed as hardlinks to \fBfish\fP, to save some space.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.1.0) Crash on incorrectly\-set color variables (#12078 \%).
.IP \(bu 2
(from 4.1.0) Crash when autosuggesting Unicode characters with nontrivial lowercase mapping.
.IP \(bu 2
(from 4.2.0) Incorrect emoji width computation on macOS.
.IP \(bu 2
(from 4.2.0) Mouse clicks and \fBctrl\fP\-\fBl\fP edge cases in multiline command lines (#12121 \%).
.IP \(bu 2
(from 4.2.0) Completions for Git remote names on some non\-glibc systems.
.IP \(bu 2
(from 4.2.0) Expansion of \fB~$USER\fP\&.
.UNINDENT
.SS fish 4.2.1 (released November 13, 2025)
.sp
This release fixes the following problems identified in 4.2.0:
.INDENT 0.0
.IP \(bu 2
When building from a tarball without Sphinx (that is, with \fB\-DBUILD_DOCS=OFF\fP or when \fBsphinx\-build\fP is not found),
builtin man pages and help files were missing, which has been fixed (#12052 \%).
.IP \(bu 2
\fBfish_config\fP\(aqs theme selector (the \(dqcolors\(dq tab) was broken, which has been fixed (#12053 \%).
.UNINDENT
.SS fish 4.2.0 (released November 10, 2025)
.SS Notable improvements and fixes
.INDENT 0.0
.IP \(bu 2
History\-based autosuggestions now include multi\-line commands.
.IP \(bu 2
A transient prompt \%<#\:transient-prompt> containing more lines than the final prompt will now be cleared properly (#11875 \%).
.IP \(bu 2
Taiwanese Chinese translations have been added.
.IP \(bu 2
French translations have been supplemented (#11842 \%).
.UNINDENT
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
fish now assumes UTF\-8 for character encoding even if the system does not have a UTF\-8 locale.
Input bytes which are not valid UTF\-8 are still round\-tripped correctly.
For example, file paths using legacy encodings can still be used,
but may be rendered differently on the command line.
.IP \(bu 2
On systems where no multi\-byte locale is available,
fish will no longer fall back to using ASCII replacements for Unicode characters \%<#\:term-compat-unicode-codepoints> such as \(dq…\(dq.
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
The title of the terminal tab can now be set separately from the window title by defining the fish_tab_title \%<> function (#2692 \%).
.IP \(bu 2
fish now hides the portion of a multiline prompt that is scrolled out of view due to a huge command line. This prevents duplicate lines after repainting with partially visible prompt (#11911 \%).
.IP \(bu 2
fish_config prompt \%<>\(aqs \fBchoose\fP and \fBsave\fP subcommands have been taught to reset fish_mode_prompt \%<> in addition to the other prompt functions (#11937 \%).
.IP \(bu 2
fish no longer force\-disables mouse capture (DECSET/DECRST 1000),
so you can use those commands
to let mouse clicks move the cursor or select completions items (#4918 \%).
.IP \(bu 2
The \fBalt\fP\-\fBp\fP binding no longer adds a redundant space to the command line.
.IP \(bu 2
When run as a login shell on macOS, fish now sets \fBMANPATH\fP correctly when that variable was already present in the environment (#10684 \%).
.IP \(bu 2
A Windows\-specific case of the web\-based config \%<> failing to launch has been fixed (#11805 \%).
.IP \(bu 2
A MSYS2\-specific workaround for Konsole and WezTerm has been added,
to prevent them from using the wrong working directory when opening new tabs (#11981 \%).
.UNINDENT
.SS For distributors and developers
.INDENT 0.0
.IP \(bu 2
Release tags and source code tarballs are GPG\-signed again (#11996 \%).
.IP \(bu 2
Documentation in release tarballs is now built with the latest version of Sphinx,
which means that pre\-built man pages include OSC 8 hyperlinks \%<#\:term-compat-osc-8>\&.
.IP \(bu 2
The Sphinx dependency is now specified in \fBpyproject.toml\fP,
which allows you to use uv \% to provide Sphinx for building documentation (e.g. \fBuv run cargo install \-\-path .\fP).
.IP \(bu 2
The minimum supported Rust version (MSRV) has been updated to 1.85.
.IP \(bu 2
The standalone build mode has been made the default.
This means that the files in \fB$CMAKE_INSTALL_PREFIX/share/fish\fP will not be used anymore, except for HTML docs.
As a result, future upgrades will no longer break running shells
if one of fish\(aqs internal helper functions has been changed in the updated version.
For now, the data files are still installed redundantly,
to prevent upgrades from breaking already\-running shells (#11921 \%).
To reverse this change (which should not be necessary),
patch out the \fBembed\-data\fP feature from \fBcmake/Rust.cmake\fP\&.
This option will be removed in future.
.IP \(bu 2
OpenBSD 7.8 revealed an issue with fish\(aqs approach for displaying builtin man pages, which has been fixed.
.UNINDENT
.SS Regression fixes:
.INDENT 0.0
.IP \(bu 2
(from 4.1.0) Fix the web\-based config \%<> for Python 3.9 and older (#12039 \%).
.IP \(bu 2
(from 4.1.0) Correct wrong terminal modes set by \fBfish \-c \(aqread; cat\fP (#12024 \%).
.IP \(bu 2
(from 4.1.0) On VTE\-based terminals, stop redrawing the prompt on resize again, to avoid glitches.
.IP \(bu 2
(from 4.1.0) On MSYS2, fix saving/loading of universal variables (#11948 \%).
.IP \(bu 2
(from 4.1.0) Fix error using \fBman\fP for the commands \fB!\fP \fB\&.\fP \fB:\fP \fB[\fP \fB{\fP (#11955 \%).
.IP \(bu 2
(from 4.1.0) Fix build issues on illumos systems (#11982 \%).
.IP \(bu 2
(from 4.1.0) Fix crash on invalid function \%<> command (#11912 \%).
.IP \(bu 2
(from 4.0.0) Fix build on SPARC and MIPS Linux by disabling \fBSIGSTKFLT\fP\&.
.IP \(bu 2
(from 4.0.0) Fix crash when passing negative PIDs to builtin wait \%<> (#11929 \%).
.IP \(bu 2
(from 4.0.0) On Linux, fix status fish\-path \%<> output when fish has been reinstalled since it was started.
.UNINDENT
.SS fish 4.1.2 (released October 7, 2025)
.sp
This release fixes the following regressions identified in 4.1.0:
.INDENT 0.0
.IP \(bu 2
Fixed spurious error output when completing remote file paths for \fBscp\fP (#11860 \%).
.IP \(bu 2
Fixed the \fBalt\fP\-\fBl\fP binding not formatting \fBls\fP output correctly (one entry per line, no colors) (#11888 \%).
.IP \(bu 2
Fixed an issue where focus events (currently only enabled in \fBtmux\fP) would cause multiline prompts to be redrawn in the wrong line (#11870 \%).
.IP \(bu 2
Stopped printing output that would cause a glitch on old versions of Midnight Commander (#11869 \%).
.IP \(bu 2
Added a fix for some configurations of Zellij where \fBescape\fP key processing was delayed (#11868 \%).
.IP \(bu 2
Fixed a case where the web\-based configuration tool \%<> would generate invalid configuration (#11861 \%).
.IP \(bu 2
Fixed a case where pasting into \fBfish \-c read\fP would fail with a noisy error (#11836 \%).
.IP \(bu 2
Fixed a case where upgrading fish would break old versions of fish that were still running.
.sp
In general, fish still needs to be restarted after it is upgraded,
except for standalone builds \%\&.
.UNINDENT
.SS fish 4.1.1 (released September 30, 2025)
.sp
This release fixes the following regressions identified in 4.1.0:
.INDENT 0.0
.IP \(bu 2
Many of our new Chinese translations were more confusing than helpful; they have been fixed or removed (#11833 \%).
.sp
Note that you can work around this type of issue by configuring fish\(aqs message localization \%<>:
if your environment contains something like \fBLANG=zh_CN.UTF\-8\fP,
you can use \fBset \-g LC_MESSAGES en\fP to use English messages inside fish.
This will not affect fish\(aqs child processes unless \fBLC_MESSAGES\fP was already exported.
.IP \(bu 2
Some fish_config \%<> subcommands for showing prompts and themes had been broken in standalone Linux builds (those using the \fBembed\-data\fP cargo feature), which has been fixed (#11832 \%).
.IP \(bu 2
On Windows Terminal, we observed an issue where fish would fail to read the terminal\(aqs response to our new startup queries, causing noticeable lags and a misleading error message. A workaround has been added (#11841 \%).
.IP \(bu 2
A WezTerm issue breaking shifted key input \% has resurfaced on some versions of WezTerm; our workaround has been extended to cover all versions for now (#11204 \%).
.IP \(bu 2
Fixed a crash in the web\-based configuration tool \%<> when using the new underline styles (#11840 \%).
.UNINDENT
.SS fish 4.1.0 (released September 27, 2025)
.SS Notable improvements and fixes
.INDENT 0.0
.IP \(bu 2
Compound commands (\fBbegin; echo 1; echo 2; end\fP) can now be written using braces (\fB{ echo1; echo 2 }\fP), like in other shells.
.IP \(bu 2
fish now supports transient prompts: if \fBfish_transient_prompt\fP \%<#\:envvar-fish_transient_prompt> is set to 1, fish will reexecute prompt functions with the \fB\-\-final\-rendering\fP argument before running a commandline (#11153 \%).
.IP \(bu 2
Tab completion results are truncated up to the common directory path, instead of somewhere inside that path. E.g. if you complete \(dqshare/functions\(dq, and it includes the files \(dqfoo.fish\(dq and \(dqbar.fish\(dq,
the completion pager will now show \(dq…/foo.fish\(dq and \(dq…/bar.fish\(dq (#11250 \%).
.IP \(bu 2
Self\-installing builds as created by e.g. \fBcargo install\fP no longer install other files, see below\&.
.IP \(bu 2
Our gettext\-based message\-localization has been reworked,
adding translations to self\-installing builds; see below\&.
.UNINDENT
.SS Deprecations and removed features
.INDENT 0.0
.IP \(bu 2
\fBset_color \-\-background=COLOR\fP no longer implicitly activates bold mode.
If your theme is stored in universal variables (the historical default), some bold formatting might be lost.
To fix this, we suggest updating to the latest version of our theme, to explicitly activate bold mode,
for example use \fBfish_config theme save \(dqfish default\(dq\fP\&.
.IP \(bu 2
\fB{echo,echo}\fP or \fB{ echo, echo }\fP are no longer interpreted as brace expansion tokens but as compound commands \%<>\&.
.IP \(bu 2
Terminfo\-style key names (\fBbind \-k nul\fP) are no longer supported. They had been superseded by fish\(aqs own key names \%<> since 4.0 (#11342 \%).
.IP \(bu 2
fish no longer reads the terminfo database, so its behavior is generally no longer affected by the \fBTERM\fP environment variable (#11344 \%).
For the time being, this change can be reversed via the \fBignore\-terminfo\fP feature flag \%<#\:featureflags>\&.
To do so, run the following once and restart fish:
.INDENT 2.0
.INDENT 3.5
.sp
.EX
set \-Ua fish_features no\-ignore\-terminfo
.EE
.UNINDENT
.UNINDENT
.IP \(bu 2
The \fB\-\-install\fP option when fish is built as self\-installing is removed, see below\&.
.IP \(bu 2
\fBset_color ff0000\fP now outputs 24\-bit RGB true\-color even if \fBCOLORTERM\fP is unset.
One can override this by setting \fBfish_term24bit\fP \%<#\:envvar-fish_term24bit> to 0 (#11372 \%).
.IP \(bu 2
fish now requires the terminal to respond to queries for the Primary Device Attribute \%<#\:term-compat-primary-da>\&.
For now, this can be reversed via a feature flag \%<#\:featureflags>,
by running (once) \fBset \-Ua fish_features no\-query\-term\fP and restarting fish.
.IP \(bu 2
Users of GNU screen may experience minor glitches \%<#\:term-compat-dcs-gnu-screen> when starting fish.
.UNINDENT
.SS Scripting improvements
.INDENT 0.0
.IP \(bu 2
The argparse \%<> builtin has seen many improvements, see below\&.
.IP \(bu 2
The string pad \%<> command now has a \fB\-C/\-\-center\fP option.
.IP \(bu 2
The psub \%<> command now allows combining \fB\-\-suffix\fP with \fB\-\-fifo\fP (#11729 \%).
.IP \(bu 2
The read \%<> builtin has learned the \fB\-\-tokenize\-raw\fP option to tokenize without quote removal (#11084 \%).
.UNINDENT
.SS Interactive improvements
.INDENT 0.0
.IP \(bu 2
Autosuggestions are now also provided in multi\-line command lines. Like \fBctrl\fP\-\fBr\fP, these operate only on the current line.
.IP \(bu 2
Autosuggestions used to not suggest multi\-line command\-lines from history; now autosuggestions include individual lines from multi\-line command\-lines.
.IP \(bu 2
The history pager search now preserves ordering between \fBctrl\fP\-\fBs\fP forward and \fBctrl\fP\-\fBr\fP backward searches.
.IP \(bu 2
Instead of highlighting events by flashing \fIall text to the left of the cursor\fP,
failing history token search (\fBalt\fP\-\fB\&.\fP) flashes the associated token,
failing tab\-completion flashes the to\-be\-completed token (#11050 \%),
deleting an autosuggestion (\fBshift\fP\-\fBdelete\fP) flashes the suggestion,
and all other scenarios flash the full command line.
.IP \(bu 2
Pasted commands are now stripped of any \fB$\ \fP command prefixes, to help pasting code snippets.
.IP \(bu 2
Builtin help options (e.g. \fBabbr \-\-help\fP) now use \fBman\fP directly, meaning that variables like \fBMANWIDTH\fP are respected (#11786 \%).
.IP \(bu 2
\fBfunced\fP will now edit copied functions directly, instead of the file where \fBfunction \-\-copy\fP was invoked. (#11614 \%)
.IP \(bu 2
Added a simple \fBfish_jj_prompt\fP which reduces visual noise in the prompt inside Jujutsu \% repositories that are colocated with Git.
.UNINDENT
.SS New or improved bindings
.INDENT 0.0
.IP \(bu 2
On non\-macOS systems, \fBalt\fP\-\fBleft\fP, \fBalt\fP\-\fBright\fP, \fBalt\fP\-\fBbackspace\fP and \fBalt\fP\-\fBdelete\fP no longer operate on punctuation\-delimited words but on whole arguments, possibly including special characters like \fB/\fP and quoted spaces.
On macOS, the corresponding \fBctrl\-\fP prefixed keys operate on whole arguments.
Word operations are still available via the other respective modifier, just like in most web browsers.
.IP \(bu 2
\fBctrl\fP\-\fBz\fP (undo) after executing a command will restore the previous cursor position instead of placing the cursor at the end of the command line.
.IP \(bu 2
The \fBalt\fP\-\fBs\fP binding will now also use \fBrun0\fP if available.
.IP \(bu 2
Some mouse support has been added: the OSC 133 prompt marking feature has learned about kitty\(aqs \fBclick_events=1\fP flag, which allows moving fish\(aqs cursor by clicking in the command line,
and selecting pager items (#10932 \%).
.IP \(bu 2
Before clearing the screen and redrawing, \fBctrl\fP\-\fBl\fP now pushes all text located above the prompt to the terminal\(aqs scrollback,
via a new special input function scrollback\-push \%<#\:special-input-functions-scrollback-push>\&.
For compatibility with terminals that do not implement ECMA\-48\(aqs SCROLL UP \%<#\:term-compat-indn> command,
this function is only used if the terminal advertises support for that via XTGETTCAP \%<#\:term-compat-xtgettcap>\&.
.IP \(bu 2
Vi mode has learned \fBctrl\fP\-\fBa\fP (increment) and \fBctrl\fP\-\fBx\fP (decrement) (#11570 \%).
.UNINDENT
.SS Completions
.INDENT 0.0
.IP \(bu 2
\fBgit\fP completions now show the remote URL as description when completing remotes.
.IP \(bu 2
\fBsystemctl\fP completions no longer print escape codes if \fBSYSTEMD_COLORS\fP happens to be set (#11465 \%).
.IP \(bu 2
Added and improved many completion scripts, notably \fBtmux\fP\&.
.UNINDENT
.SS Improved terminal support
.INDENT 0.0
.IP \(bu 2
Support for double, curly, dotted and dashed underlines, for use in \fBfish_color_*\fP variables and the set_color builtin \%<> (#10957 \%).
.IP \(bu 2
Underlines can now be colored independent of text (#7619 \%).
.IP \(bu 2
New documentation page Terminal Compatibility \%<> (also accessible via \fBman fish\-terminal\-compatibility\fP) lists the terminal control sequences used by fish.
.UNINDENT
.SS Other improvements
.INDENT 0.0
.IP \(bu 2
Updated Chinese and German translations.
.IP \(bu 2
\fBfish_indent \-\-dump\-parse\-tree\fP now emits simple metrics about the tree including its memory consumption.
.IP \(bu 2
We added some tools to improve development workflows, for example \fBbuild_tools/{check,update_translations,release}.sh\fP and \fBtests/test_driver.py\fP\&.
In conjunction with \fBcargo\fP, these enable almost all day\-to\-day development tasks without using CMake.
.UNINDENT
.SS For distributors
.INDENT 0.0
.IP \(bu 2
Builtin commands that support the \fB\-\-help\fP option now require the \fBman\fP program.
The direct dependency on \fBmandoc\fP and \fBnroff\fP has been removed.
.IP \(bu 2
fish no longer uses gettext MO files, see below\&.
If you have use cases which are incompatible with our new approach, please let us know.
.IP \(bu 2
The fish_indent \%<> and fish_key_reader \%<> programs are now also available as builtins.
If fish is invoked via e.g. a symlink with one of these names,
it will act like the given tool (i.e. it\(aqs a multi\-call binary).
This allows truly distributing fish as a single file (#10876 \%).
.IP \(bu 2
The CMake build configuration has been simplified and no longer second\-guesses rustup.
It will run rustc and cargo via \fBPATH\fP \%<#\:envvar-PATH> or in ~/.cargo/bin/.
If that doesn\(aqt match your setup, set the Rust_COMPILER and Rust_CARGO CMake variables (#11328 \%).
.IP \(bu 2
Cygwin support has been reintroduced, since Rust gained a Cygwin target \% (#11238 \%).
.IP \(bu 2
CMake 3.15 is now required.
.UNINDENT
.SS Changes to self\-installing builds
.sp
The self\-installing build type introduced in fish 4.0 has been changed (#11143 \%).
Now fish built with embedded data will just read the data straight from its own binary or write it out to temporary files when necessary, instead of requiring an installation step on start.
That means it is now possible to build fish as a single file and copy it to any system with a compatible CPU architecture, including as a different user, without extracting any files.
As before, this is the default when building via \fBcargo\fP, and disabled when building via CMake.
For packagers we continue to recommend CMake.
.sp
Note: When fish is built like this, the \fB__fish_data_dir\fP variable will be empty because that directory no longer has meaning.
You should generally not need these files.
For example, if you want to make sure that completions for \(dqfoo\(dq are loaded, use \fBcomplete \-C\(dqfoo \(dq >/dev/null\fP instead).
The raw files are still exposed via status subcommands \%<#\:status-get-file>, mainly for fish\(aqs internal use, but you can also use them as a last resort.
.sp
Remaining benefits of a full installation (as currently done by CMake) are:
.INDENT 0.0
.IP \(bu 2
man pages like \fBfish(1)\fP in standard locations, easily accessible from outside fish.
.IP \(bu 2
a local copy of the HTML documentation, typically accessed via the help \%<> function.
In builds with embedded data, \fBhelp\fP will redirect to e.g. \%
.IP \(bu 2
\fBfish_indent\fP and \fBfish_key_reader\fP as separate files, making them easily accessible outside fish
.IP \(bu 2
an (empty) \fB/etc/fish/config.fish\fP as well as empty directories \fB/etc/fish/{functions,completions,conf.d}\fP
.IP \(bu 2
\fB$PREFIX/share/pkgconfig/fish.pc\fP, which defines directories for configuration\-snippets, like \fBvendor_completions.d\fP
.UNINDENT
.SS Changes to gettext localization
.sp
We replaced several parts of the gettext functionality with custom implementations (#11726 \%).
Most notably, message extraction, which should now work reliably, and the runtime implementation, where we no longer dynamically link to gettext, but instead use our own implementation, whose behavior is similar to GNU gettext, with some minor deviations \%<>\&.
Our implementation now fully respects fish variables, so locale variables do not have to be exported for fish localizations to work.
They still have to be exported to inform other programs about language preferences.
The \fBLANGUAGE\fP \%<#\:envvar-LANGUAGE> environment variable is now treated as a path variable, meaning it is an implicitly colon\-separated list.
While we no longer have any runtime dependency on gettext, we still need gettext tools for building, most notably \fBmsgfmt\fP\&.
When building without \fBmsgfmt\fP available, localization will not work with the resulting executable.
Localization data is no longer sourced at runtime from MO files on the file system, but instead built into the executable.
This is always done, independently of the other data embedding, so all fish executables will have access to all message catalogs, regardless of the state of the file system.
Disabling our new \fBlocalize\-messages\fP cargo feature will cause fish to be built without localization support.
CMake builds can continue to use the \fBWITH_GETTEXT\fP option, with the same semantics as the \fBlocalize\-messages\fP feature.
The current implementation does not provide any configuration options for controlling which language catalogs are built into the executable (other than disabling them all).
As a workaround, you can delete files in the \fBpo\fP directory before building to exclude unwanted languages.
.SS Changes to the argparse \%<> builtin
.INDENT 0.0
.IP \(bu 2
\fBargparse\fP now saves recognised options, including option\-arguments in \fBargv_opts\fP \%<#\:envvar-argv_opts>, allowing them to be forwarded to other commands (#6466 \%).
.IP \(bu 2
\fBargparse\fP options can now be marked to be deleted from \fBargv_opts\fP \%<#\:envvar-argv_opts> (by adding a \fB&\fP at the end of the option spec, before a \fB!\fP if present). There is now also a corresponding \fB\-d\fP / \fB\-\-delete\fP option to \fBfish_opt\fP\&.
.IP \(bu 2
\fBargparse \-\-ignore\-unknown\fP now removes preceding known short options from groups containing unknown options (e.g. when parsing \fB\-abc\fP, if \fBa\fP is known but \fBb\fP is not, then \fBargv\fP \%<#\:envvar-argv> will contain \fB\-bc\fP).
.IP \(bu 2
\fBargparse\fP now has an \fB\-u\fP / \fB\-\-move\-unknown\fP option that works like \fB\-\-ignore\-unknown\fP but preserves unknown options in \fBargv\fP \%<#\:envvar-argv>\&.
.IP \(bu 2
\fBargparse\fP now has an \fB\-S\fP / \fB\-\-strict\-longopts\fP option that forbids abbreviating long options or passing them with a single dash (e.g. if there is a long option called \fBfoo\fP, \fB\-\-fo\fP and \fB\-\-foo\fP won\(aqt match it).
.IP \(bu 2
\fBargparse\fP now has a \fB\-U\fP / \fB\-\-unknown\-arguments\fP option to specify how to parse unknown option\(aqs arguments.
.IP \(bu 2
\fBargparse\fP now allows specifying options that take multiple optional values by using \fB=*\fP in the option spec (#8432 \%).
In addition, \fBfish_opt\fP has been modified to support such options by using the \fB\-\-multiple\-vals\fP together with \fB\-o\fP / \fB\-\-optional\-val\fP; \fB\-m\fP is also now acceptable as an abbreviation for \fB\-\-multiple\-vals\fP\&.
.IP \(bu 2
\fBfish_opt\fP no longer requires you give a short flag name when defining options, provided you give it a long flag name with more than one character.
.IP \(bu 2
\fBargparse\fP option specifiers for long\-only options can now start with \fB/\fP, allowing the definition of long options with a single letter. Due to this change, the \fB\-\-long\-only\fP option to \fBfish_opt\fP is now no longer necessary and is deprecated.
.IP \(bu 2
\fBfish_opt\fP now has a \fB\-v\fP / \fB\-\-validate\fP option you can use to give a fish script to validate values of the option.
.UNINDENT
.sp
.ce
----
.ce 0
.sp
.SS fish 4.0.9 (released September 27, 2025)
.sp
This release fixes:
.INDENT 0.0
.IP \(bu 2
a regression in 4.0.6 causing shifted keys to not be inserted on some terminals (#11813 \%).
.IP \(bu 2
a regression in 4.0.6 causing the build to fail on systems where \fBchar\fP is unsigned (#11804 \%).
.IP \(bu 2
a regression in 4.0.0 causing a crash on an invalid bg \%<> invocation.
.UNINDENT
.sp
.ce
----
.ce 0
.sp
.SS fish 4.0.8 (released September 18, 2025)
.sp
This release fixes a regression in 4.0.6 that caused user bindings to be shadowed by either fish\(aqs or a plugin\(aqs bindings (#11803 \%).
.sp
.ce
----
.ce 0
.sp
.SS fish 4.0.6 (released September 12, 2025)
.sp
This release of fish fixes a number of issues identified in fish 4.0.2:
.INDENT 0.0
.IP \(bu 2
fish now properly inherits $PATH under Windows WSL2 (#11354 \%).
.IP \(bu 2
Remote filesystems are detected properly again on non\-Linux systems.
.IP \(bu 2
the printf \%<> builtin no longer miscalculates width of multi\-byte characters (#11412 \%).
.IP \(bu 2
For many years, fish has been \(dqrelocatable\(dq \-\- it was possible to move the entire \fBCMAKE_INSTALL_PREFIX\fP and fish would use paths relative to its binary.
Only gettext locale paths were still determined purely at compile time, which has been fixed.
.IP \(bu 2
the commandline \%<> builtin failed to print the commandline set by a \fBcommandline \-C\fP invocation, which broke some completion scripts.
This has been corrected (#11423 \%).
.IP \(bu 2
To work around terminals that fail to parse Operating System Command (OSC) sequences, a temporary feature flag has been added.
It allows you to disable prompt marking (OSC 133) by running (once) \fBset \-Ua fish_features no\-mark\-prompt\fP and restarting fish (#11749 \%).
.IP \(bu 2
The routines to save history and universal variables have seen some robustness improvements.
.IP \(bu 2
builtin status current\-command \%<> no longer prints a trailing blank line.
.IP \(bu 2
A crash displaying multi\-line quoted command substitutions has been fixed (#11444 \%).
.IP \(bu 2
Commands like \fBset fish_complete_path ...\fP accidentally disabled completion autoloading, which has been corrected.
.IP \(bu 2
\fBnmcli\fP completions have been fixed to query network information dynamically instead of only when completing the first time.
.IP \(bu 2
Git completions no longer print an error when no \fIgit\-foo\fP executable is in \fBPATH\fP \%<#\:envvar-PATH>\&.
.IP \(bu 2
Custom completions like \fBcomplete foo \-l long \-xa ...\fP that use the output of \fBcommandline \-t\fP\&.
on a command\-line like \fBfoo \-\-long=\fP have been invalidated by a change in 4.0; the completion scripts have been adjusted accordingly (#11508 \%).
.IP \(bu 2
Some completions were misinterpreted, which caused garbage to be displayed in the completion list. This has been fixed.
.IP \(bu 2
fish no longer interprets invalid control sequences from the terminal as if they were \fBalt\fP\-\fB[\fP or \fBalt\fP\-\fBo\fP key strokes.
.IP \(bu 2
bind \%<> has been taught about the \fBprintscreen\fP and \fBmenu\fP keys.
.IP \(bu 2
\fBalt\fP\-\fBdelete\fP now deletes the word right of the cursor.
.IP \(bu 2
\fBctrl\fP\-\fBalt\fP\-\fBh\fP erases the last word again (#11548 \%).
.IP \(bu 2
\fBalt\fP\-\fBleft\fP \fBalt\fP\-\fBright\fP were misinterpreted because they send unexpected sequences on some terminals; a workaround has been added. (#11479 \%).
.IP \(bu 2
Key bindings like \fBbind shift\-A\fP are no longer accepted; use \fBbind shift\-a\fP or \fBbind A\fP\&.
.IP \(bu 2
Key bindings like \fBbind shift\-a\fP take precedence over \fBbind A\fP when the key event included the shift modifier.
.IP \(bu 2
Bindings using shift with non\-ASCII letters (such as \fBctrl\fP\-\fBshift\fP\-\fBä\fP) are now supported.
.IP \(bu 2
Bindings with modifiers such as \fBbind ctrl\-w\fP work again on non\-Latin keyboard layouts such as a Russian one.
This is implemented by allowing key events such as \fBctrl\fP\-\fBц\fP to match bindings of the corresponding Latin key, using the kitty keyboard protocol\(aqs base layout key (#11520 \%).
.IP \(bu 2
Vi mode: The cursor position after pasting via \fBp\fP has been corrected.
.IP \(bu 2
Vi mode: Trying to replace the last character via \fBr\fP no longer replaces the last\-but\-one character (#11484 \%).
.UNINDENT
.sp
.ce
----
.ce 0
.sp
.SS fish 4.0.2 (released April 20, 2025)
.sp
This release of fish fixes a number of issues identified in fish 4.0.1:
.INDENT 0.0
.IP \(bu 2
Completions are quoted, rather than backslash\-escaped, only if the completion is unambiguous. Continuing to edit the token is therefore easier (#11271 \%). This changes the behavior introduced in 4.0.0 where all completions were quoted.
.IP \(bu 2
The warning when the terminfo database can\(aqt be found has been downgraded to a log message. fish will act as if the terminal behaves like xterm\-256color, which is correct for the vast majority of cases (#11277 \%, #11290 \%).
.IP \(bu 2
Key combinations using the super (Windows/command) key can now (actually) be bound using the \fBsuper\-\fP prefix (#11217 \%). This was listed in the release notes for 4.0.1 but did not work correctly.
.IP \(bu 2
function \%<> is stricter about argument parsing, rather than allowing additional parameters to be silently ignored (#11295 \%).
.IP \(bu 2
Using parentheses in the test \%<> builtin works correctly, following a regression in 4.0.0 where they were not recognized (#11387 \%).
.IP \(bu 2
\fBdelete\fP in Vi mode when Num Lock is active will work correctly (#11303 \%).
.IP \(bu 2
Abbreviations cannot alter the command\-line contents, preventing a crash (#11324 \%).
.IP \(bu 2
Improvements to various completions, including new completions for \fBwl\-randr\fP (#11301 \%), performance improvements for \fBcargo\fP completions by avoiding network requests (#11347 \%), and other improvements for \fBbtrfs\fP (#11320 \%), \fBcryptsetup\fP (#11315 \%), \fBgit\fP (#11319 \%, #11322 \%, #11323 \%), \fBjj\fP (#11046 \%), and \fBsystemd\-analyze\fP (#11314 \%).
.IP \(bu 2
The Mercurial (\fBhg\fP) prompt can handle working directories that contain an embedded newline, rather than producing errors (#11348 \%).
.IP \(bu 2
A number of crashes have been fixed. Triggers include prompts containing backspace characters (#11280 \%), history pager search (#11355 \%), invalid UTF\-8 in read \%<> (#11383 \%), and the \fBkill\-selection\fP binding (#11367 \%).
.IP \(bu 2
A race condition in the test suite has been fixed (#11254 \%), and a test for fish versioning relaxed to support downstream distributors\(aq modifications (#11173 \%).
.IP \(bu 2
Small improvements to the documentation (#11264 \%, #11329 \%, #11361 \%).
.UNINDENT
.sp
.ce
----
.ce 0
.sp
.SS fish 4.0.1 (released March 12, 2025)
.sp
This release of fish includes the following improvements compared to fish 4.0.0:
.INDENT 0.0
.IP \(bu 2
Key combinations using the super (Windows/command) key can be bound using the \fBsuper\-\fP prefix (#11217 \%).
.IP \(bu 2
Konsole\(aqs menu shows the \(dqOpen folder with\(dq option again (#11198 \%).
.IP \(bu 2
.INDENT 2.0
.TP
.B \fB$fish_color_search_match\fP will now only be applied to the foreground color if it has an explicit foreground. For example, this allows setting::
set \-g fish_color_search_match \-\-reverse
.UNINDENT
.IP \(bu 2
Cursor shape commands (\fB\ee[2 q\fP) are no longer sent in non\-interactive shells or in redirections (#11255 \%).
.IP \(bu 2
status \%<> gained a \fBis\-interactive\-read\fP subcommand, to check whether the script is being called from an interactive read \%<> invocation.
.IP \(bu 2
fish\(aqs background tasks are now started in a way that avoids an error on macOS Terminal.app (#11181 \%).
.IP \(bu 2
Using key combinations within qemu should work correctly.
.IP \(bu 2
Prompts containing control characters no longer cause incorrect display of command lines (#11252 \%).
.IP \(bu 2
Cancelling the command\-line in Vi mode displays correctly again (#11261 \%).
.IP \(bu 2
The acidhub prompt properly displays the git branch again (#11179 \%