Skip to content

Commit 2d75ab8

Browse files
Add FAQ to sphinx docs build
1 parent db90f42 commit 2d75ab8

File tree

2 files changed

+254
-0
lines changed

2 files changed

+254
-0
lines changed

sphinx_doc_src/faq.rst

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
Frequently asked questions
2+
==========================
3+
4+
How do I set or clear an environment variable?
5+
----------------------------------------------
6+
Use the <a href="commands.html#set">``set``</a> command::
7+
8+
set -x key value
9+
set -e key
10+
11+
12+
How do I run a command every login? What's fish's equivalent to .bashrc?
13+
------------------------------------------------------------------------
14+
Edit the file ``~/.config/fish/config.fish``, creating it if it does not exist (Note the leading period).
15+
16+
17+
How do I set my prompt?
18+
-----------------------
19+
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::
20+
21+
function fish_prompt
22+
set_color $fish_color_cwd
23+
echo -n (prompt_pwd)
24+
set_color normal
25+
echo -n ' > '
26+
end
27+
28+
29+
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.
30+
31+
32+
How do I run a command from history?
33+
------------------------------------
34+
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.
35+
36+
37+
How do I run a subcommand? The backtick doesn't work!
38+
-----------------------------------------------------
39+
``fish`` uses parentheses for subcommands. For example::
40+
41+
for i in (ls)
42+
echo $i
43+
end
44+
45+
46+
My command (pkg-config) gives its output as a single long string?
47+
-----------------------------------------------------------------
48+
Unlike other shells, fish splits command substitutions only on newlines, not spaces or tabs or the characters in $IFS.
49+
50+
That means if you run
51+
52+
::
53+
54+
echo x(printf '%s ' a b c)x
55+
56+
57+
It will print ``xa b c x``. But if you do
58+
59+
::
60+
61+
echo x(printf '%s\n' a b c)x
62+
63+
64+
it will print ``xax xbx xcx``.
65+
66+
In the overwhelming majority of cases, splitting on spaces is unwanted, so this is an improvement.
67+
68+
However sometimes, especially with ``pkg-config`` and related tools, splitting on spaces is needed.
69+
70+
In these cases use ``string split " "`` like::
71+
72+
g++ example_01.cpp (pkg-config --cflags --libs gtk+-2.0 | string split " ")
73+
74+
75+
How do I get the exit status of a command?
76+
------------------------------------------
77+
Use the ``$status`` variable. This replaces the ``$?`` variable used in some other shells.
78+
79+
::
80+
81+
somecommand
82+
if test $status -eq 7
83+
echo "That's my lucky number!"
84+
end
85+
86+
87+
If you are just interested in success or failure, you can run the command directly as the if-condition::
88+
89+
if somecommand
90+
echo "Command succeeded"
91+
else
92+
echo "Command failed"
93+
end
94+
95+
96+
See the documentation for <a href="commands.html#test">``test``</a> and <a href="commands.html#if">``if``</a> for more information.
97+
98+
~~
99+
How do I set an environment variable for just one command?
100+
----------------------------------------------------------
101+
``SOME_VAR=1 command`` produces an error: ``Unknown command "SOME_VAR=1"``.
102+
103+
Use the ``env`` command.
104+
105+
``env SOME_VAR=1 command``
106+
107+
You can also declare a local variable in a block::
108+
109+
begin
110+
set -lx SOME_VAR 1
111+
command
112+
end
113+
114+
115+
Why doesn't ``set -Ux`` (exported universal variables) seem to work?
116+
--------------------------------------------------------------------
117+
A global variable of the same name already exists.
118+
119+
Environment variables such as ``EDITOR`` or ``TZ`` can be set universally using ``set -Ux``. However, if
120+
there is an environment variable already set before fish starts (such as by login scripts or system
121+
administrators), it is imported into fish as a global variable. The <a
122+
href="index.html#variables-scope">variable scopes</a> are searched from the "inside out", which
123+
means that local variables are checked first, followed by global variables, and finally universal
124+
variables.
125+
126+
This means that the global value takes precedence over the universal value.
127+
128+
To avoid this problem, consider changing the setting which fish inherits. If this is not possible,
129+
add a statement to your <a href="index.html#">user initialization file</a> (usually
130+
``~/.config/fish/config.fish``)::
131+
132+
set -gx EDITOR vim
133+
134+
135+
How do I customize my syntax highlighting colors?
136+
-------------------------------------------------
137+
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>.
138+
139+
~~
140+
How do I update man page completions?
141+
-------------------------------------
142+
Use the <a href="commands.html#fish_update_completions">``fish_update_completions``</a> command.
143+
144+
~~
145+
I accidentally entered a directory path and fish changed directory. What happened?
146+
----------------------------------------------------------------------------------
147+
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.
148+
149+
150+
The open command doesn't work.
151+
------------------------------
152+
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>.
153+
154+
155+
How do I make fish my default shell?
156+
------------------------------------
157+
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)::
158+
159+
echo /usr/local/bin/fish | sudo tee -a /etc/shells
160+
161+
162+
If you installed a prepackaged version of fish, the package manager should have already done this for you.
163+
164+
In order to change your default shell, type::
165+
166+
chsh -s /usr/local/bin/fish
167+
168+
169+
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.
170+
171+
Unfortunately, there is no way to make the changes take effect at once. You will need to log out and back in again.
172+
173+
174+
I'm seeing weird output before each prompt when using screen. What's wrong?
175+
---------------------------------------------------------------------------
176+
Quick answer:
177+
178+
Run the following command in fish::
179+
180+
function fish_title; end; funcsave fish_title
181+
182+
183+
Problem solved!
184+
185+
The long answer:
186+
187+
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.
188+
189+
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.
190+
191+
192+
How do I change the greeting message?
193+
-------------------------------------
194+
Change the value of the variable ``fish_greeting`` or create a ``fish_greeting`` function. For example, to remove the greeting use::
195+
196+
set fish_greeting
197+
198+
199+
200+
Why doesn't history substitution ("!$" etc.) work?
201+
--------------------------------------------------
202+
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 ".
203+
204+
Fish history recall is very simple yet effective:
205+
206+
- 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.
207+
208+
- 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.
209+
210+
- @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.
211+
212+
- 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!
213+
214+
- 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).
215+
216+
See <a href='index.html#editor'>documentation</a> for more details about line editing in fish.
217+
218+
219+
How can I use ``-`` as a shortcut for ``cd -``?
220+
-----------------------------------------------
221+
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::
222+
223+
abbr -a -- - 'cd -'
224+
225+
226+
Uninstalling fish
227+
-----------------
228+
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.
229+
230+
Next, do the following (assuming fish was installed to /usr/local)::
231+
232+
rm -Rf /usr/local/etc/fish /usr/local/share/fish ~/.config/fish
233+
rm /usr/local/share/man/man1/fish*.1
234+
cd /usr/local/bin
235+
rm -f fish fish_indent
236+
237+
238+
239+
Unicode private-use characters reserved by fish
240+
-----------------------------------------------
241+
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).
242+
243+
244+
Where can I find extra tools for fish?
245+
--------------------------------------
246+
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:
247+
248+
- `Fisher <https://github.com/jorgebucaran/fisher>`_
249+
- `Fundle <https://github.com/tuvistavie/fundle>`_
250+
- `Oh My Fish <https://github.com/oh-my-fish/oh-my-fish>`_
251+
- `Tacklebox <https://github.com/justinmayer/tacklebox>`_
252+
253+
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.

sphinx_doc_src/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ Commands
521521
commands
522522
design
523523
tutorial
524+
faq
524525

525526

526527
Autosuggestions

0 commit comments

Comments
 (0)