Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
FISH-FAQ(1)			  fish-shell			   FISH-FAQ(1)

NAME
       fish-faq	- fish-shell faq

HOW DO I SET OR	CLEAR AN ENVIRONMENT VARIABLE?
       Use the set command:

	  set -x key value
	  set -e key

       Since fish 3.1 you can set an environment variable for just one command
       using the key=value some	command	syntax,	like in	other shells.  The two
       lines  below behave identically - unlike	other shells, fish will	output
       value both times:

	  key=value echo $key
	  begin; set -lx key value; echo $key; end

HOW DO I RUN A COMMAND EVERY LOGIN? WHAT'S FISH'S  EQUIVALENT  TO  .BASHRC  OR
       .PROFILE?
       Edit  the  file	~/.config/fish/config.fish, creating it	if it does not
       exist (Note the leading period).

HOW DO I SET MY	PROMPT?
       The prompt is the output	of the fish_prompt function. Put it in ~/.con-
       fig/fish/functions/fish_prompt.fish. For	example, a simple prompt is:

	  function fish_prompt
	      set_color	$fish_color_cwd
	      echo -n (prompt_pwd)
	      set_color	normal
	      echo -n '	> '
	  end

       You  can	 also  use the Web configuration tool, fish_config, to preview
       and choose from a gallery of sample prompts.

HOW DO I RUN A COMMAND FROM HISTORY?
       Type some part of the command, and then hit the ^a (up) or ^a (down)  ar-
       row  keys  to  navigate through history matches.	Additional default key
       bindings	include	Control+P (up) and Control+N (down).

HOW DO I RUN A SUBCOMMAND? THE BACKTICK	DOESN'T	WORK!
       fish uses parentheses for subcommands. For example:

	  for i	in (ls)
	      echo $i
	  end

MY COMMAND (PKG-CONFIG)	GIVES ITS OUTPUT AS A SINGLE LONG STRING?
       Unlike other shells, fish splits	command	 substitutions	only  on  new-
       lines, not spaces or tabs or the	characters in $IFS.

       That means if you run

	  echo x(printf	'%s ' a	b c)x

       It  will	print xa b c x,	because	the "a b c " is	used in	one piece. But
       if you do

	  echo x(printf	'%s\n' a b c)x

       it will print xax xbx xcx.

       In the overwhelming majority of cases, splitting	on spaces is unwanted,
       so this is an improvement.

       However sometimes, especially with pkg-config and related tools,	split-
       ting on spaces is needed.

       In these	cases use string split " " like:

	  g++ example_01.cpp (pkg-config --cflags --libs gtk+-2.0 | string split " ")

HOW DO I GET THE EXIT STATUS OF	A COMMAND?
       Use the $status variable. This replaces the $? variable	used  in  some
       other shells.

	  somecommand
	  if test $status -eq 7
	      echo "That's my lucky number!"
	  end

       If  you are just	interested in success or failure, you can run the com-
       mand directly as	the if-condition:

	  if somecommand
	      echo "Command succeeded"
	  else
	      echo "Command failed"
	  end

       Or if you just want to do one command in	case the  first	 succeeded  or
       failed, use and or or:

	  somecommand
	  or someothercommand

       See the documentation for test and if for more information.

HOW DO I CHECK WHETHER A VARIABLE IS DEFINED?
       Use  set	 -q  var.   For	example, if set	-q var;	echo variable defined;
       end.  To	check multiple variables you can combine with and and or  like
       so:

	  if set -q var1; or set -q var2
	      echo either variable defined
	  end

       Keep  in	 mind  that a defined variabled	could also be empty, either by
       having no elements (if set like set var)	or only	empty elements (if set
       like set	var ""). Read on for how to deal with those.

HOW DO I CHECK WHETHER A VARIABLE IS NOT EMPTY?
       Use  string  length  -q	--  $var.  For example,	if string length -q --
       $var; echo not empty; end.  Note	that string length  will  interpret  a
       list of multiple	variables as a disjunction (meaning any/or):

	  if string length -q -- $var1 $var2 $var3
	      echo at least one	of these variables is not empty
	  end

       Alternatively,  use test	-n "$var", but remember	that the variable must
       be double-quoted.  For example, if test -n "$var"; echo not empty; end.
       The test	command	provides its own and (-a) and or (-o):

	  if test -n "$var1" -o	-n "$var2" -o -n "$var3"
	      echo at least one	of these variables is not empty
	  end

       If you want to know if a	variable has no	elements, use set -q var[1].

WHY DOESN'T SET	-UX (EXPORTED UNIVERSAL	VARIABLES) SEEM	TO WORK?
       A global	variable of the	same name already exists.

       Environment variables such as EDITOR or TZ can be set universally using
       set -Ux.	 However, if there is an environment variable already set  be-
       fore  fish  starts (such	as by login scripts or system administrators),
       it is imported into fish	as a global variable. The variable scopes  are
       searched	 from  the  "inside out", which	means that local variables are
       checked first, followed by  global  variables,  and  finally  universal
       variables.

       This  means  that  the global value takes precedence over the universal
       value.

       To avoid	this problem, consider changing	the setting which fish	inher-
       its.  If	this is	not possible, add a statement to your user initializa-
       tion file (usually ~/.config/fish/config.fish):

	  set -gx EDITOR vim

HOW DO I CUSTOMIZE MY SYNTAX HIGHLIGHTING COLORS?
       Use the web configuration tool, fish_config, or	alter  the  fish_color
       family of environment variables.

HOW DO I UPDATE	MAN PAGE COMPLETIONS?
       Use the fish_update_completions command.

I  ACCIDENTALLY	ENTERED	A DIRECTORY PATH AND FISH CHANGED DIRECTORY. WHAT HAP-
       PENED?
       If fish is unable to locate a command with a given name,	and it	starts
       with  '.',  '/'	or '~',	fish will test if a directory of that name ex-
       ists. If	it does, it is implicitly assumed  that	 you  want  to	change
       working	directory. For example,	the fastest way	to switch to your home
       directory is to simply press ~ and enter.

THE OPEN COMMAND DOESN'T WORK.
       The open	command	uses the MIME type database  and  the  .desktop	 files
       used  by	Gnome and KDE to identify filetypes and	default	actions. If at
       least one of these environments is installed, but the open  command  is
       not  working, this probably means that the relevant files are installed
       in a non-standard location. Consider asking for more help.

HOW DO I MAKE FISH MY DEFAULT SHELL?
       If you installed	fish manually (e.g. by compiling it, not  by  using  a
       package	manager),  you first need to add fish to the list of shells by
       executing  the  following  command  (assuming  you  installed  fish  in
       /usr/local):

	  echo /usr/local/bin/fish | sudo tee -a /etc/shells

       If  you	installed  a  prepackaged version of fish, the package manager
       should have already done	this for you.

       In order	to change your default shell, type:

	  chsh -s /usr/local/bin/fish

       You may need to adjust the above	path to	e.g.  /usr/bin/fish.  Use  the
       command which fish if you are unsure of where fish is installed.

       Unfortunately, there is no way to make the changes take effect at once.
       You will	need to	log out	and back in again.

I'M SEEING WEIRD OUTPUT	BEFORE EACH PROMPT WHEN	USING SCREEN. WHAT'S WRONG?
       Quick answer:

       Run the following command in fish:

	  function fish_title; end; funcsave fish_title

       Problem solved!

       The long	answer:

       Fish is trying to set the titlebar  message  of	your  terminal.	 While
       screen  itself  supports	this feature, your terminal does not. Unfortu-
       nately, when the	underlying terminal doesn't support setting the	title-
       bar,  screen simply passes through the escape codes and text to the un-
       derlying	terminal instead of ignoring them. It is impossible to	detect
       and  resolve  this  problem  from  inside fish since fish has no	way of
       knowing what the	underlying terminal type is. For now, the only way  to
       fix this	is to unset the	titlebar message, as suggested above.

       Note  that  fish	 has a default titlebar	message, which will be used if
       the fish_title function is undefined. So	simply unsetting the  fish_ti-
       tle function will not work.

HOW DO I CHANGE	THE GREETING MESSAGE?
       Change  the value of the	variable fish_greeting or create a fish_greet-
       ing function. For example, to remove the	greeting use:

	  set fish_greeting

WHY DOESN'T HISTORY SUBSTITUTION ("!$" ETC.) WORK?
       Because history substitution is an awkward interface that was  invented
       before  interactive  line  editing was even possible.  Fish drops it in
       favor of	perfecting the interactive history recall interface.   Switch-
       ing  requires  a	 small	change of habits: if you want to modify	an old
       line/word, first	recall it, then	edit.  E.g. don't  type	 "sudo	!!"  -
       first press Up, then Home, then type "sudo ".

       Fish history recall is very simple yet effective:

       o As in any modern shell, the Up	arrow, ^a recalls whole lines, starting
	 from the last line executed.  A single	 press	replaces  "!!",	 later
	 presses replace "!-3" and the like.

	 o 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  constrain
	   the recall to lines that include this text, and you will get	to the
	   line	you want much faster.  This replaces "!vi", "!?bar.c" and  the
	   like.

       o Alt+^a,Up  recalls  individual arguments, starting from	the last argu-
	 ment in the last line executed.  A single press replaces "!$",	 later
	 presses  replace  "!!:4"  and	the  like. An alternate	key binding is
	 Alt+..

	 o If the argument you want is far back	in history (e.g. 2 lines  back
	   -  that's  a	 lot  of  words!),  type any part of it	and then press
	   Alt+^a,Up.  This will	show only arguments containing that  part  and
	   you	will  get what you want	much faster.  Try it out, this is very
	   convenient!

	 o If you want to reuse	several	arguments from the same	line  ("!!:3*"
	   and	the like), consider recalling the whole	line and removing what
	   you don't need (Alt+D and Alt+Backspace are your friends).

       See documentation for more details about	line editing in	fish.

HOW CAN	I USE -	AS A SHORTCUT FOR CD -?
       In fish versions	prior to 2.5.0 it was possible to  create  a  function
       named  -	that would do cd -. Changes in the 2.5.0 release included sev-
       eral bug	fixes that enforce the rule that a bare	hyphen is not a	 valid
       function	 (or  variable)	name. However, you can achieve the same	effect
       via an abbreviation:

	  abbr -a -- - 'cd -'

UNINSTALLING FISH
       Should you wish to uninstall fish, first	ensure fish is not set as your
       shell. Run chsh -s /bin/bash if you are not sure.

       Next, do	the following (assuming	fish was installed to /usr/local):

	  rm -Rf /usr/local/etc/fish /usr/local/share/fish ~/.config/fish
	  rm /usr/local/share/man/man1/fish*.1
	  cd /usr/local/bin
	  rm -f	fish fish_indent

UNICODE	PRIVATE-USE CHARACTERS RESERVED	BY FISH
       Fish  reserves the Unicode private-use character	range from U+F600 thru
       U+F73F for internal use.	Any attempt to feed characters in  that	 range
       to  fish	will result in them being replaced by the Unicode "replacement
       character" U+FFFD. This includes	both interactive input as well as  any
       file read by fish (but not programs run by fish).

WHERE CAN I FIND EXTRA TOOLS FOR FISH?
       The  fish  user	community  extends  fish in unique and useful ways via
       scripts that aren't always appropriate for bundling with	the fish pack-
       age. Typically because they solve a niche problem unlikely to appeal to
       a broad audience. You can find  those  extensions,  including  prompts,
       themes and useful functions, in various third-party repositories. These
       include:

       o Fisher

       o Fundle

       o Oh My Fish

       o Tacklebox

       This is not an exhaustive list and the fish project has no opinion  re-
       garding	the  merits  of	 the  repositories listed above	or the scripts
       found therein.

AUTHOR
       fish-shell developers

COPYRIGHT
       2019, fish-shell	developers

3.1				 Mar 02, 2021			   FISH-FAQ(1)

NAME | HOW DO I SET OR CLEAR AN ENVIRONMENT VARIABLE? | HOW DO I RUN A COMMAND EVERY LOGIN? WHAT'S FISH'S EQUIVALENT TO .BASHRC OR | HOW DO I SET MY PROMPT? | HOW DO I RUN A COMMAND FROM HISTORY? | HOW DO I RUN A SUBCOMMAND? THE BACKTICK DOESN'T WORK! | MY COMMAND (PKG-CONFIG) GIVES ITS OUTPUT AS A SINGLE LONG STRING? | HOW DO I GET THE EXIT STATUS OF A COMMAND? | HOW DO I CHECK WHETHER A VARIABLE IS DEFINED? | HOW DO I CHECK WHETHER A VARIABLE IS NOT EMPTY? | WHY DOESN'T SET -UX (EXPORTED UNIVERSAL VARIABLES) SEEM TO WORK? | HOW DO I CUSTOMIZE MY SYNTAX HIGHLIGHTING COLORS? | HOW DO I UPDATE MAN PAGE COMPLETIONS? | I ACCIDENTALLY ENTERED A DIRECTORY PATH AND FISH CHANGED DIRECTORY. WHAT HAP- | THE OPEN COMMAND DOESN'T WORK. | HOW DO I MAKE FISH MY DEFAULT SHELL? | I'M SEEING WEIRD OUTPUT BEFORE EACH PROMPT WHEN USING SCREEN. WHAT'S WRONG? | HOW DO I CHANGE THE GREETING MESSAGE? | WHY DOESN'T HISTORY SUBSTITUTION ("!$" ETC.) WORK? | HOW CAN I USE - AS A SHORTCUT FOR CD -? | UNINSTALLING FISH | UNICODE PRIVATE-USE CHARACTERS RESERVED BY FISH | WHERE CAN I FIND EXTRA TOOLS FOR FISH? | AUTHOR | COPYRIGHT

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=fish-faq&sektion=1&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help