. 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.
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.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.
switch $animal case cat echo evil case wolf dog human moose dolphin whale echo mammal case duck goose albatros echo bird case shark trout stingray echo fish 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 CDPATH environment variable will be separated using the : as separator, and the resulting list will be searched for a suitable new current directory. 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.
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-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-f
or --no-files
specifies that the option specified by this completion may not be followed by a filename-x
or --exclusive
implies both -r
and -f
-p
or --path
implies that the string COMMAND is the full path of the command-o
or --old-option
implies that the command uses old long style options with only one dash-e
or --erase
implies that the specified completion should be deleted-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
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:
complete
only allows one of old style long options and GNU style long options to be used on a specific command, but short options can always be specified.
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)"
.
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
end
ends a block of commands. For more information, read the documentation for the block constructs, such as if
, for
and \ while. 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.
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 0.If exit is called while sourcing a file (using the . builtin) the rest of the file will be skipped, but the shell 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 NAME; BODY; end
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
will run the ls
command, using the -l
option, while passing on any additional files and switches to ls
.
function mysearch cat (find . -name $1)|grep -l $2 endwill recursively search the current directory for files with a name matching the first parameter containing the text of the second parameter.
functions [-e] FUNCTIONS...
-e
or --erase
causes the specified functions to be erased.-n
or --names
List only the names of all defined functions
If functions
is called with no arguments, the names and definition of all functions are printed, otherwise, the specified function definitions will be printed.
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
. jobs
jobs
builtin causes fish to print a list of the currently running jobs and their status.On systems that supports this feature, jobs will also 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%.
read [OPTIONS] [VARIABLES...]
read
builtin causes fish to read one line from standard input and store the result in one or more environment variables.
-e
or --export
specifies that the variables will be exported to subshells.-g
or --global
specifies that the variables will be made global.-pPROMPT_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 "> "
.-cCMD
or --command=CMD
specifies that the initial string in the interactive mode command buffer should be CMD.
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 [OPTIONS] VARIABLE_NAME [VALUES...]
The set
builtin causes fish to assign the variable VARIABLE_NAME
the values VALUES...
.
-e
or --erase
causes the specified environment variables to be erased.-x
or --export
causes the specified environment variable to be exported to subprocesses.-g
or --global
causes the specified environment variable to be made global. If this option is not supplied, the specified variable will dissapear when the current block ends.-l
or --local
forces the specified environment variable to be made local to the current block, even if the variable already exists and is non-local.-n
or --names
List only the names of all defined variablesIf set is called with no arguments, the names and values of all environment variables are printed.
If set is called with only one argument, the scope of the variable with the given name will be changed as specified, but it's value will remain the same. If the variable did not previously exist, it's value will be an empty string.
If the -e
or --erase
option is specified, all the variables specified by the following arguments will be erased
If set is called with more than one value, the variable will be an array.
If the variable name is an array element, such as PATH[3]
, only that array element will be changed.
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
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.
switch $animal case cat echo evil case wolf dog human moose dolphin whale echo mammal case duck goose albatros echo bird case shark trout stingray echo fish end
If the above code was run with $animal set to whale
, the output would be mammal
.
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.
function NAME; [COMMANDS...] break [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.
STATUS
is the return status of the function. If unspecified, the status is set to 0.
function false return 1 end
commandline [[-a|--append]CMD]
commandline
builtin prints or sets the current commandline
CMD
is the new buffer conntents of the commandline-a
or --append
causes CMD to be inserted into the current commandline buffer at the current cursor position commandline $history[3]
sets the current commandline to the third item from ther commandline history.