. FILENAME
fish < FILENAME
) since the commands will be evaluated by the current shell, which means that changes in environment variables, etc., will remain.. ~/.fish
causes fish to reread its initialization file.
COMMAND1; and COMMAND2
and
builtin is used to execute a command if the current exit status (as set by the last previous command) is zeroThe and command does not change the current exit status.
make
command to build a program, if the build succceds, the program is installed. If either step fails, make clean
is run, which removes the files created by the build process
make; and make install; or make clean
begin; [COMMAND;...] end
begin
builtin is used to create a new block of code. The block is unconditionally executed. Begin is equivalent to if true
. The begin command is used to group any number of commands into a block. The reason for this is usually either to introduce a new variable scope or to redirect the input to output of this set of commands as a group.
The begin
command does not change the current exit status.
begin set -x PIRATE Yarrr ... end # This will not output anything, since PIRATE went out of scope at the end of # the block and was killed echo $PIRATE
bg [PID...]
The PID of the desired process is usually found by using process globbing.
bg %0
will put the job with job id 0 in the background.bind [OPTIONS] [BINDINGS...]
The bind
builtin causes fish to add the readline style bindings specified by BINDINGS
to the list of key bindings. For more information on specifying keyboard bindings, use man readline
to access the readline documentation.
-M MODE
or --set-mode=MODE
sets the current input mode to MODE.bind -M vi
changes to the vi input mode
bind '"\M-j": jobs'
Binds the jobs command to the Alt-j keyboard shortcut
block [OPTIONS...]
-l
or --local
Release the block at the end of the currently innermost block scope-g
or --global
Never automatically release the lock-e
or --erase
Release global blockblock -g #Do something that should not be interrupted block -e
LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end
break
builtin is used to halt a currently running 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.
for i in *.c;
if grep smurf $i;
echo Smurfs are present in $i;
break;
end;
end;
builtin BUILTINNAME [OPTIONS...]
-n
or --names
List the names of all defined builtinsPrefixing a command with the word 'builtin' forces fish to ignore any aliases with the same name.
builtin jobs
causes fish to execute the jobs builtin, even if a function named jobs exists.
switch VALUE; [case [WILDCARD...]; [COMMANDS...];...] end
switch
statement is used to perform one of several blocks of commands depending on whether a specified value equals one of several wildcarded values. The case
statement is used together with the switch
statement in order to determine which block should be performed.
Each case
command is given one or more parameter. The first case
command with a parameter that matches the string specified in the switch command will be evaluated. case
parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the syntax may look a bit like C switch statements, it behaves more like the case stamantes of traditional shells.
Also note that command substitutions in a case statement will be evaluated even if it's body is not taken. This may seem counterintuitive at first, but it is unavoidable, since it would be impossible to know if a case command will evaluate to true before all forms of parameter expansion have been performed for the case command.
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 '*' echo I have no idea what a $animal is end
If the above code was run with $animal
set to whale
, the output would be mammal
.
cd [DIRECTORY]
DIRECTORY
is supplied it will become the new directory. If DIRECTORY
is a relative path, the paths found in the CDPATH environment variable array will be tried as prefixes for the specified path. If CDPATH is not set, it is assumed to be '.'. If DIRECTORY
is not specified, $HOME will be the new directory. command COMMANDNAME [OPTIONS...]
command ls
causes fish to execute the ls program, even if there exists a 'ls' alias.
commandline [OPTIONS] [CMD]
CMD
is the new value of the commandline. If unspecified, the current value of the commandline is written to standard output.
The following switches change the way commandline
updates the commandline
-a
or --append
do not remove the current commandline, append the specified string at the end of it-i
or --insert
do not remove the current commandline, insert the specified string at the current cursor position-r
or --replace
remove the current commandline and replace it with the specified string (default)The following switches change what part of the commandline is printed or updated
-b
or --current-buffer
select the entire buffer (default)-j
or --current-job
select the current job-p
or --current-process
select the current process-t
or --current_token
select the current token.
The following switch changes the way commandline
prints the current commandline
-c
or --cut-at-cursor
only print selection up until the current cursor position-o
or --tokenize
tokenize the selection and print one string-type token per lineOther switches
-f
or --function
inject readline functions into the reader. This option can not be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual keypresses are read.
If commandline is called during a call to complete a given string using complete -C STRING
, commandline will consider the specified string to be the current contents of the commandline.
commandline -j $history[3]
replaces the job under the cursor with the third item from the commandline history.
complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION]
COMMAND
is the name of the command for which to add a completionSHORT_OPTION
is a one character option for the commandLONG_OPTION
is a multi character option for the commandOPTION_ARGUMENTS
is parameter containing a space-separated list of possible option-arguments, which may contain subshellsDESCRIPTION
is a description of what the option and/or option arguments do-C STRING
or --do-complete=STRING
makes complete try to find all possible completions for the specified string-e
or --erase
implies that the specified completion should be deleted-f
or --no-files
specifies that the option specified by this completion may not be followed by a filename-n
or --condition
specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.-o
or --old-option
implies that the command uses old long style options with only one dash-p
or --path
implies that the string COMMAND is the full path of the command-r
or --require-parameter
specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option-u
or --unauthorative
implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors-x
or --exclusive
implies both -r
and -f
Command specific tab-completions in fish
are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '-h', '-help' or '--help'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are:
The options for specifying command name, command path, or command switches may all be used multiple times to specify multiple commands which have the same completion or multiple switches accepted by a command.
When erasing completions, it is possible to either erase all completions for a specific command by specifying complete -e -c COMMAND
, or by specifying a specific completion option to delete by specifying either a long, short or old style option.
-o
for the gcc
command requires that a file follows it. This can be done using writing complete -c gcc -s o -r
.
The short style option -d
for the grep
command requires that one of the strings 'read', 'skip' or 'recurse' is used. This can be specified writing complete -c grep -s d -x -a "read skip recurse"
.
The su
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: complete -x -c su -d "Username" -a "(cat /etc/passwd|cut -d : -f 1)"
.
The rpm
command has several different modes. If the -e
or --erase
flag has been specified, rpm
should delete one or more packages, in which case several switches related to deleting packages are valid, like the nodeps
switch.
This can be written as:
complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies"
where __fish_contains_opt
is a function that checks the commandline buffer for the presence of a specified set of options.
LOOP_CONSTRUCT; [COMMANDS...] continue; [COMMANDS...] end
continue
builtin is used to skip the current lap of the innermost currently running 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.
for i in *.tmp;
if grep smurf $i;
continue;
end;
rm $i;
end;
if CONDITION; COMMAND_TRUE [else; COMMAND_FALSE] end;
if
will execute the command CONDITION. If the commands exit status is zero, the command COMMAND_TRUE will execute. If it is not zero and COMMAND_FALSE is specified, COMMAND_FALSE will be executed.if test -f foo.txt; echo foo.txt exists; else; echo foo.txt does not exist; end
will print foo.txt exists
if the file foo.txt exists and is a regular file, otherwise it will print foo.txt does not exist
. for VARNAME in [VALUES...]; COMMANDS; end if CONDITION; COMMAND_TRUE [else; COMMAND_FALSE] end while CONDITION; COMMANDS; end switch VALUE; [case [WILDCARD...]; [COMMANDS...];...] end begin; [COMMANDS...] end
end
ends a block of commands. For more information, read the documentation for the block constructs, such as if
, for
and \ while.
The end
command does not change the current exit status.
eval [COMMANDS...]
eval
builtin causes fish to evaluate 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.set cmd ls eval $cmd
will call the ls command.
exec COMMAND [OPTIONS...]
exec
builtin is used to replace the currently running shells process image with a new command. On successful completion, exec never returns. exec can not be used inside a pipeline.exec emacs
starts up the emacs text editor. When emacs exits, the session will terminate. exit [STATUS]
exit
builtin causes fish to exit. If STATUS
is supplied, it will be converted to an integer and used as the exit code. Otherwise the exit code will be that of the last command executed.If exit is called while sourcing a file (using the . builtin) the rest of the file will be skipped, but the shell itself will not exit.
fg [PID]
The PID of the desired process is usually found by using process globbing.
fg %0
will put the job with job id 0 in the foreground.for VARNAME in [VALUES...]; [COMMANDS...]; end
for
is a loop construct. It will perform the commands specified by COMMANDS
multiple times. Each time the environment variable specified by VARNAME
is assigned a new value from VALUES
.
for i in foo bar baz; echo $i; end
would output:
foo bar baz
function [OPTIONS] NAME; BODY; end
-b
or --key-binding
specifies that the function is a key biding. Key binding functions work exactly like regular functions except that they can not be tab-completed, and may contain the '-' character.-d DESCRIPTION
or --description=DESCRIPTION
is a description of what the function does, suitable as a completion description-j PID
or --on-job-exit PID
tells fish to run this function when the job with group id PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.-p PID
or --on-process-exit PID
tells fish to run this function when the fish child process with process id PID exits-s
or --on-signal SIGSPEC
tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP)-v
or --on-variable VARIABLE_NAME
tells fish to run this function when the variable VARIABLE_NAME changes valueThis builtin command is used to create a new function. A Function is a list of commands that will be executed when the name of the function is entered. The function
function hi echo hello end
will write hello
whenever the user enters hi
.
If the user enters any additional arguments after the function, they are inserted into the environment variable array argv.
function ll ls -l $argv end
will run the ls
command, using the -l
option, while passing on any additional files and switches to ls
.
function mkdir -d "Create a directory and set CWD" mkdir $argv if test $status = 0 switch $argv[(count $argv)] case '-*'
case '*' cd $argv[(count $argv)] return end end end
will run the mkdir command, and if it is successful, change the current working directory to the one just created.
functions [-e] FUNCTIONS...
-a
or --all
list all functions, even those whose name start with an underscore.-d DESCRIPTION
or --description=DESCRIPTION
change the description of this function-e
or --erase
causes the specified functions to be erased.-h
or --help
display a help message and exit-n
or --names
list only the names of all defined functions-q
or --query
test if the specified functions exist. Does not output anything, but the builtins exit status is the number of functions specified that were not defined.
The default behavior of functions
when called with no arguments, is to print the names and definitions of all defined functions. If any non-switch parameters are given, only the definition of the specified functions are printed.
Automatically loaded functions can not be removed using functions -e. Either remove the definition file or change the $fish_function_path variable to remove autoloaded functions.
The exit status of the functions builtin is the number functions specified in the argument list that do not exist.
if CONDITION; COMMAND_TRUE [else; COMMAND_FALSE] end;
if
will execute the command CONDITION. If the commands exit status is zero, the command COMMAND_TRUE will execute. If it is not zero and COMMAND_FALSE is specified, COMMAND_FALSE will be executed.if test -f foo.txt echo foo.txt exists else echo foo.txt does not exist endwill print
foo.txt exists
if the file foo.txt exists and is a regular file, otherwise it will print foo.txt does not exist
. jobs [OPTIONS] [PID]
jobs
builtin causes fish to print a list of the currently running jobs and their status.jobs accepts the following switches:
-c
or --command
print the command name for each process in jobs-g
or --group
only print the group id of each job-h
or --help
display a help message and exit-l
or --last
only the last job to be started is printed-p
or --pid
print the process id for each process in all jobsOn systems that supports 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%.
not COMMAND [OPTIONS...]
not
builtin is used to negate the exit status of another command.if not test -f spoon echo There is no spoon exit 1 end
COMMAND1; or COMMAND2
or
builtin is used to execute a command if the current exit status (as set by the last previous command) is non-zeroThe or command does not change the current exit status.
make
command to build a program, if the build succceds, the program is installed. If either step fails, make clean
is run, which removes the files created by the build process
make; and make install; or make clean
random [SEED]
random
command is used to generate a random number in the interval 0<=N<32767. If an argument is given, it is used to seed the random number generator. This can be useful for debugging purposes, where it can be desirable to get the same random number sequence multiple times. If the random number generator is called without first seeding it, the current time will be used as the seed.
for i in (seq (random) -1 1) echo $i sleep end
function NAME; [COMMANDS...] return [STATUS]; [COMMANDS...] end
return
builtin is used to halt a currently running function. It is usually 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, but it can also be used to specify the exit status of a function.
STATUS
is the return status of the function. If unspecified, the status is unchanged.
function false return 1 end
read [OPTIONS] [VARIABLES...]
read
builtin causes fish to read one line from standard input and store the result in one or more environment variables.
-c CMD
or --command=CMD
specifies that the initial string in the interactive mode command buffer should be CMD.-e
or --export
specifies that the variables will be exported to subshells.-g
or --global
specifies that the variables will be made global.-p PROMPT_CMD
or --prompt=PROMPT_CMD
specifies that the output of the shell command PROMPT_CMD should be used as the prompt for the interactive mode prompt. The default prompt command is set_color green; echo read; set_color normal; echo "> "
.-u
or --unexport
causes the specified environment not to be exported to child processes-U
or --universal
causes the specified environment variable to be made universal. If this option is supplied, the variable will be shared between all the current users fish instances on the current computer, and will be preserved across restarts of the shell.-x
or --export
causes the specified environment variable to be exported to child processes
Read starts by reading a single line of input from stdin, the line is then tokenized using the IFS
environment variable. Each variable specified in VARIABLES
is then assigned one tokenized string element. If there are more tokens than variables, the complete remainder is assigned to the last variable.
echo hello|read foo
Will cause the variable $foo to be assigned the value hello.
set [SCOPE_OPTIONS] set [OPTIONS] VARIABLE_NAME VALUES... set [OPTIONS] VARIABLE_NAME[INDICES]... VALUES... set (-q | --query) [SCOPE_OPTIONS] VARIABLE_NAMES... set (-e | --erase) [SCOPE_OPTIONS] VARIABLE_NAME set (-e | --erase) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]...
The set
builtin causes fish to assign the variable VARIABLE_NAME
the values VALUES...
.
-e
or --erase
causes the specified environment variable to be erased-l
or --local
forces the specified environment variable to be given a scope that is local to the current block, even if a variable with the given name exists and is non-local-g
or --global
causes the specified environment variable to be given a global scope. Non-global variables disappear when the block they belong to ends-U
or --universal
causes the specified environment variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current users fish instances on the current computer, and will be preserved across restarts of the shell.-n
or --names
List only the names of all defined variables-q
or --query
test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined.-u
or --unexport
causes the specified environment not to be exported to child processes-x
or --export
causes the specified environment variable to be exported to child processesIf set is called with no arguments, the names and values of all environment variables are printed. If some of the scope or export flags have been given, only the variables matching the specified scope are printed.
If a variable is set to more than one value, the variable will be an array with the specified elements. If a variable is set to zero elements, it will become an array with zero elements.
If the variable name is one or more array elements, such as PATH[1 3 7]
, only those array elements specified will be changed. When array indices are specified to set, multiple arguments may be used to specify additional indexes, e.g. set PATH[1] PATH[4] /bin /sbin
. If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array.
The scoping rules when creating or updating a variable are:
The exporting rules when creating or updating a variable are identical to the scoping rules for variables:
In query mode, the scope to be examined can be specified.
In erase mode, if variable indices are specified, only the specified slices of the array variable will be erased. When erasing an entire variable (i.e. no slicing), the scope of the variable to be erased can be specified. That way, a global variable can be erased even if a local variable with the same name exists. Scope can not be specified when erasing a slice of an array. The innermost scope is always used.
The set command requires all switch arguments to come before any non-switch arguments. For example, set flags -l
will have the effect of setting the value of the variable flags
to '-l', not making the variable local.
In assignment mode, set exits with an exit status of zero it the variable assignments where sucessfully performed, with a non-zero exit status otherwise. In query mode, the exit status is the number of variables that where not found. In erase mode, set exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if the variable was write-protected or if the variable did not exist.
set -xg
will print all global, exported variables.
set foo hi
sets the value of the variable foo to be hi.
set -e smurf
removes the variable smurf
.
set PATH[4] ~/bin
changes the fourth element of the PATH
array to ~/bin
status [OPTION]
-c
or --is-command-substitution
returns 0 if fish is currently executing a command substitution-b
or --is-block
returns 0 if fish is currently executing a block of code-i
or --is-interactive
returns 0 if fish is interactive, i.e.connected to a keyboard-l
or --is-login
returns 0 if fish is a login shell, i.e. if fish should perform login tasks such as setting up the PATH.switch VALUE; [case [WILDCARD...]; [COMMANDS...];...] end
switch
statement is used to perform one of several blocks of commands depending on whether a specified value equals one of several wildcarded values. The case
statement is used together with the switch
statement in order to determine which block should be performed.
Each case
command is given one or more parameter. The first case
command with a parameter that matches the string specified in the switch command will be evaluated. case
parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the syntax may look a bit like C switch statements, it behaves more like the case stamantes of traditional shells.
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 '*' echo I have no idea what a $animal is end
If the above code was run with $animal
set to whale
, the output would be mammal
.
ulimit [OPTIONS] [LIMIT]
-a
or --all
Set or get all current limits-c
or --core-size
The maximum size of core files created-d
or --data-size
The maximum size of a process’s data segment-f
or --file-size
The maximum size of files created by the shell-l
or --lock-size
The maximum size that may be locked into memory-m
or --resident-set-size
The maximum resident set size-n
or --file-descriptor-count
The maximum number of open file descriptors (most systems do not allow this value to be set)-s
or --stack-size
The maximum stack size-t
or --cpu-time
The maximum amount of cpu time in seconds-u
or --process-count
The maximum number of processes available to a single user-v
or --virtual-memory-size
The maximum amount of virtual memory available to the shell. If supported by OS.If limit is given, it is the new value of the specified resource. If no option is given, then -f is assumed. Values are in kilobytes, except for -t, which is in seconds and -n and -u, which are unscaled values. The return status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit.
The fish implementation of ulimit should behave identically to the implementation in bash, except for these differences:
ulimit -Hs 64
would set the hard stack size limit to 64 kB:
while CONDITION; COMMANDS; end
while
builtin causes fish to continually execute the command COMMANDS while the command CONDITION returns with status 0.while test -f foo.txt; echo file exists; sleep 10; end
causes fish to print the line 'file exists' at 10 second intervals as long as the file foo.txt exists.