fish-shell/doc_src/faq.hdr

300 lines
15 KiB
Plaintext
Raw Normal View History

/**
\page faq Frequently asked questions
\htmlonly[block]
<div class="fish_left_bar">
<div class="logo"></div>
<div class="menu faq_menu">
\endhtmlonly
2013-05-20 10:14:13 +08:00
- <a href='#faq-envvar'>How do I set or clear an environment variable?</a>
- <a href='#faq-login-cmd'>How do I run a command every login? What's fish's equivalent to `.bashrc`?</a>
2013-05-20 10:14:13 +08:00
- <a href='#faq-prompt'>How do I set my prompt?</a>
- <a href='#faq-cmd-history'>How do I run a command from history?</a>
- <a href='#faq-subcommand'>How do I run a subcommand? The backtick doesn't work!</a>
- <a href='#faq-exit-status'>How do I get the exit status of a command?</a>
2013-05-23 13:58:16 +08:00
- <a href='#faq-single-env'>How do I set an environment variable for just one command?</a>
- <a href='#faq-exported-uvar'>Why doesn't `set -Ux` (exported universal vars) seem to work?</a>
2013-05-20 10:14:13 +08:00
- <a href='#faq-customize-colors'>How do I customize my syntax highlighting colors?</a>
- <a href='#faq-update-manpage-completions'>How do I update man page completions?</a>
- <a href='#faq-cwd-symlink'>Why does cd, pwd and other fish commands always resolve symlinked directories to their canonical path?</a>
- <a href='#faq-cd-implicit'>I accidentally entered a directory path and fish changed directory. What happened?</a>
- <a href='#faq-open'>The open command doesn't work.</a>
- <a href='#faq-default'>How do I make fish my default shell?</a>
- <a href='#faq-titlebar'>I'm seeing weird output before each prompt when using screen. What's wrong?</a>
- <a href='#faq-greeting'>How do I change the greeting message?</a>
- <a href='#faq-history'>Why doesn't history substitution ("!$" etc.) work?</a>
- <a href='#faq-find-braces'>Why do I get a missing argument error with `find ... {}`?</a>
2017-07-09 14:11:15 +08:00
- <a href='#faq-cd-minus'>How can I use `-` as a shortcut for `cd -`?</a>
2013-05-17 00:32:31 +08:00
- <a href='#faq-uninstalling'>How do I uninstall fish?</a>
- <a href='#faq-third-party'>Where can I find extra tools for fish?</a>
\htmlonly[block]
</div>
</div>
<div class="faq fish_right_bar">
<h1 class="interior_title">Frequently Asked Questions</h1>
\endhtmlonly
2013-05-20 10:14:13 +08:00
\section faq-envvar How do I set or clear an environment variable?
Use the <a href="commands.html#set">`set`</a> command:
2013-05-20 10:14:13 +08:00
\fish{cli-dark}
set -x key value
set -e key
\endfish
2013-05-20 10:14:13 +08:00
\section faq-login-cmd How do I run a command every login? What's fish's equivalent to .bashrc?
2013-05-20 10:14:13 +08:00
Edit the file `~/.config/fish/config.fish`, creating it if it does not exist (Note the leading period).
2014-09-03 20:06:49 +08:00
<hr>
2013-05-20 10:14:13 +08:00
\section faq-prompt How do I set my prompt?
The prompt is the output of the `fish_prompt` function. Put it in `~/.config/fish/functions/fish_prompt.fish`. For example, a simple prompt is:
\fish{cli-dark}
function fish_prompt
set_color $fish_color_cwd
echo -n (prompt_pwd)
set_color normal
echo -n ' > '
end
\endfish
2013-05-20 10:14:13 +08:00
You can also use the Web configuration tool, <a href="commands.html#fish_config">`fish_config`</a>, to preview and choose from a gallery of sample prompts.
2013-05-20 10:14:13 +08:00
\section faq-cmd-history How do I run a command from history?
2014-08-27 02:19:24 +08:00
Type some part of the command, and then hit the @cursor_key{&uarr;,up} or @cursor_key{&darr;,down} arrow keys to navigate through history matches.
2013-05-20 10:14:13 +08:00
2014-09-03 20:06:49 +08:00
<hr>
2013-05-20 10:14:13 +08:00
\section faq-subcommand How do I run a subcommand? The backtick doesn't work!
`fish` uses parentheses for subcommands. For example:
2013-05-20 10:14:13 +08:00
\fish{cli-dark}
for i in (ls)
echo $i
end
\endfish
2013-05-20 10:14:13 +08:00
\section faq-exit-status How do I get the exit status of a command?
Use the `$status` variable. This replaces the `$?` variable used in some other shells.
2013-05-20 10:14:13 +08:00
\fish{cli-dark}
somecommand
if test $status -eq 7
echo "That's my lucky number!"
end
\endfish
If you are just interested in success or failure, you can run the command directly as the if-condition:
\fish{cli-dark}
if somecommand
echo "Command succeeded"
else
echo "Command failed"
end
\endfish
See the documentation for <a href="commands.html#test">`test`</a> and <a href="commands.html#if">`if`</a> for more information.
Use the <a href="commands.html#fish_update_completions">`fish_update_completions`</a> command.
2014-09-03 20:06:49 +08:00
<hr>
2013-05-23 13:58:16 +08:00
\section faq-single-env How do I set an environment variable for just one command?
<i>`SOME_VAR=1 command` produces an error: `Unknown command "SOME_VAR=1"`.</i>
2013-05-23 13:58:16 +08:00
Use the `env` command.
2013-05-23 13:58:16 +08:00
`env SOME_VAR=1 command`
2013-05-23 13:58:16 +08:00
You can also declare a local variable in a block:
\fish{cli-dark}
begin
set -lx SOME_VAR 1
command
end
\endfish
2013-05-23 13:58:16 +08:00
\section faq-exported-uvar Why doesn't `set -Ux` (exported universal vars) seem to work?
Lots of users try to set exported environment variables like `EDITOR` and `TZ` as universal variables; e.g., `set -Ux`. That works but the behavior can be surprising. Keep in mind that when resolving a variable reference (e.g., `echo $EDITOR`) fish first looks in local scope, then global scope, and finally universal scope. Also keep in mind that environment vars imported when fish starts running are placed in the global scope. So if `EDITOR` or `TZ` is already in the environment when fish starts running your universal var by the same name is not used.
The recommended practice is to not export universal variables in the hope they will be present in all future shells. Instead place statements like the following example in your config.fish file:
\fish{cli-dark}
set -q EDITOR
or set -gx EDITOR vim
\endfish
Now when fish starts it will use the existing value for the variable if it was in the environment. Otherwise it will be set to your preferred default. This allows programs like emacs or an IDE to start a fish shell with a different value for the var. This is effectively the same behavior seen when setting it as a uvar but is explicit and therefore easier to reason about and debug. If you don't want to allow using the existing environment value just unconditionally `set -gx` the var in your config.fish file.
2013-05-23 13:58:16 +08:00
2013-05-20 10:14:13 +08:00
\section faq-customize-colors How do I customize my syntax highlighting colors?
Use the web configuration tool, <a href="commands.html#fish_config">`fish_config`</a>, or alter the <a href="index.html#variables-color">`fish_color` family of environment variables</a>.
2014-09-03 20:06:49 +08:00
<hr>
2013-05-20 10:14:13 +08:00
\section faq-update-manpage-completions How do I update man page completions?
Use the <a href="commands.html#fish_update_completions">`fish_update_completions`</a> command.
2013-05-20 10:14:13 +08:00
2014-09-03 20:06:49 +08:00
<hr>
\section faq-cwd-symlink Why does cd, $PWD and and various fish commands always resolve symlinked directories to their canonical path?
2015-04-26 00:53:15 +08:00
<i>For example if `~/images` is a symlink to `~/Documents/Images`, if I write '`cd images`', my prompt will say `~/Documents/Images`, not `~/images`.</i>
2015-11-11 04:54:28 +08:00
Because it is impossible to consistently keep symlinked directories unresolved. It is indeed possible to do this partially, and many other shells do so. But it was felt there are enough serious corner cases that this is a bad idea. Most such issues have to do with how '..' is handled, and are variations of the following example:
Writing `cd images; ls ..` given the above directory structure would list the contents of `~/Documents`, not of `~`, even though using `cd ..` changes the current directory to `~`, and the prompt, the `pwd` builtin and many other directory information sources suggest that the current directory is `~/images` and its parent is `~`. This issue is not possible to fix without either making every single command into a builtin, breaking Unix semantics or implementing kludges in every single command. This issue can also be seen when doing IO redirection.
Another related issue is that many programs that operate on recursive directory trees, like the find command, silently ignore symlinked directories. For example, ```find $PWD -name '*.txt'``` silently fails in shells that don't resolve symlinked paths.
2014-09-03 20:06:49 +08:00
<hr>
\section faq-cd-implicit I accidentally entered a directory path and fish changed directory. What happened?
If fish is unable to locate a command with a given name, and it starts with '`.`', '`/`' or '`~`', fish will test if a directory of that name exists. If it does, it is implicitly assumed that you want to change working directory. For example, the fastest way to switch to your home directory is to simply press `~` and enter.
2014-09-03 20:06:49 +08:00
<hr>
\section faq-open 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 <a href="index.html#more-help">asking for more help</a>.
2014-09-03 20:06:49 +08:00
<hr>
\section faq-default 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):
\fish{cli-dark}
echo /usr/local/bin/fish | sudo tee -a /etc/shells
\endfish
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:
\fish{cli-dark}
chsh -s /usr/local/bin/fish
\endfish
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.
2014-09-03 20:06:49 +08:00
<hr>
\section faq-titlebar I'm seeing weird output before each prompt when using screen. What's wrong?
Quick answer:
Run the following command in fish:
\fish{cli-dark}
2015-05-20 17:04:34 +08:00
function fish_title; end; funcsave fish_title
\endfish
Problem solved!
The long answer:
2015-04-26 00:53:15 +08:00
Fish is trying to set the titlebar message of your terminal. While screen itself supports this feature, your terminal does not. Unfortunately, when the underlying terminal doesn't support setting the titlebar, screen simply passes through the escape codes and text to the underlying terminal instead of ignoring them. It is impossible to detect and resolve this problem from inside fish since fish has no way of knowing what the underlying terminal type is. For now, the only way to fix this is to unset the titlebar message, as suggested above.
Note that fish has a default titlebar message, which will be used if the fish_title function is undefined. So simply unsetting the fish_title function will not work.
2014-09-03 20:06:49 +08:00
<hr>
\section faq-greeting How do I change the greeting message?
Change the value of the variable `fish_greeting` or create a `fish_greeting` function. For example, to remove the greeting use:
\fish{cli-dark}
set fish_greeting
\endfish
<hr>
\section faq-history 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. Switching requires a small change of habits: if you want to modify an old line/word, first recall it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then type "sudo ".
Fish history recall is very simple yet effective:
- As in any modern shell, the Up arrow, @cursor_key{&uarr;,Up} recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like.
- 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.
- @key{Alt,&uarr;,Up} recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like.
- 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 @key{Alt,&uarr;,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!
- 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 (@key{Alt,D} and @key{Alt,Backspace} are your friends).
2010-09-18 10:18:26 +08:00
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
<hr>
\section faq-find-braces Why do I get a missing argument error with `find ... {}`?
Running `find ... -exec ... {}` produces an error:
find: missing argument to '-exec'
The problem is caused by the empty braces, which are subject to <a href="index.html#expand-brace">brace expansion</a>.
Quote the empty braces to achieve the desired effect:
\fish{cli-dark}
find ... -exec ... '{{}}'
\endfish
<hr>
2017-07-09 14:11:15 +08:00
\section faq-cd-minus 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 several bug fixes that enforce the rule that a bare hyphen is not a valid function (or variable) name. However, you can achieve the same effect via an abbreviation:
\fish{cli-dark}
abbr -a -- - 'cd -'
\endfish
2014-09-03 20:06:49 +08:00
<hr>
2013-05-17 00:32:31 +08:00
\section faq-uninstalling 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.
2013-05-17 00:32:31 +08:00
Next, do the following (assuming fish was installed to /usr/local):
\fish{cli-dark}
2013-05-17 00:32:31 +08:00
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
\endfish
<hr>
\section faq-reserved-chars Unicode private-use characters reserved by fish
Fish reserves the <a href="http://www.unicode.org/faq/private_use.html">Unicode private-use character range</a> 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).
<hr>
\section faq-third-party 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 package. Typically because they solve a niche problem unlikely to appeal to a broad audience. You can find those extensions, including prompts, themes and useful functions, in various third-party repositories. These include:
- <a href="https://github.com/fisherman/fisherman">Fisherman</a>
- <a href="https://github.com/tuvistavie/fundle">Fundle</a>
- <a href="https://github.com/oh-my-fish/oh-my-fish">Oh My Fish</a>
- <a href="https://github.com/justinmayer/tacklebox">Tacklebox</a>
This is not an exhaustive list and the fish project has no opinion regarding the merits of the repositories listed above or the scripts found therein. We mention these only because you may find within them a solution to a need you have such as supporting the `&&` and `||` operators or improved integration with other tools that you use.
\htmlonly[block]
</div>
\endhtmlonly
2014-09-03 20:06:49 +08:00
*/