78cec3748e3e5300c08267bed23b9b575c9df62e
[webi-installers/.git] / fish / README.md
1 ---
2 title: fish
3 homepage: https://github.com/fish-shell/fish-shell
4 tagline: |
5   fish is a smart and user-friendly command line shell for Linux, macOS, and the rest of the family.
6 ---
7
8 ### Updating `fish`
9
10 `webi fish@stable`
11
12 Use the `@beta` tag for pre-releases.
13
14 ## Cheat Sheet
15
16 > Finally, a command line shell for the 90s!
17 >
18 > fish includes features like syntax highlighting, autosuggest-as-you-type, and
19 > fancy tab completions that just work, with no configuration required.
20
21 !["fish features"](https://i.imgur.com/WVCyf5N.png)
22
23 `fish` is an _excellent_ command line shell for day-to-day file browsing and
24 running commands (the _BEST_, in fact).
25
26 However, it is **NOT** compatible with `bash` so you should still write and run
27 your scripts with bash.
28
29 This also covers how to
30
31 - Run bash scripts with bash
32 - Set vim to keep using bash
33 - Set fish as the default shell in **Linux**
34 - Set fish as the default shell in various Terminals
35   - Terminal.app
36   - iTerm2
37   - Hyper
38   - Alacritty
39 - Find fish's config files
40 - Set the default shell back to `bash`
41
42 ### How to run bash scripts from fish
43
44 A bash script should have a "bash shebang" (`#!/bin/bash`) as the first line of
45 the file:
46
47 ```bash
48 #!/bin/bash
49
50 echo "Who am I? I'm $(whoami)."
51 ```
52
53 You can also run bash explicitly:
54
55 ```bash
56 bash ./some-script.sh
57 ```
58
59 ### How to set the fish Color Scheme
60
61 You may like to have your `fish` theme match your Terminal or iTerm2 theme (such
62 as _Solarized_, _Dracula_, or _Tomorrow Night_).
63
64 ```bash
65 fish_config colors
66 ```
67
68 ### How to set vim to keep using bash
69
70 The first line of your `.vimrc` should always be `set shell=/bin/bash`.
71
72 `~/.vimrc`:
73
74 ```vim
75 set shell=/bin/bash
76 ```
77
78 ### How to make fish the default shell on Linux
79
80 This requires editing a protected system file, `/etc/shells`. It is better to
81 use the Terminal-specific methods.
82
83 First, `fish` must be installed and in the `PATH`.
84
85 ```bash
86 # if you don't see a file path as output, fish is not in the path
87 which fish
88 ```
89
90 Second, fish must be in the system-approved list of shells in `/etc/shells`:
91
92 ```bash
93 #!/bin/bash
94
95 if ! grep $(which fish) /etc/shells > /dev/null; then
96     sudo bash -c "echo '$(which fish)' >> /etc/shells";
97     echo "added '$(which fish)' to /etc/shells"
98 fi
99 ```
100
101 You should use `chsh` to change your shell:
102
103 ```bash
104 #!/bin/bash
105
106 sudo chsh -s "$(which fish)" "$(whoami)"
107 ```
108
109 If vim uses `fish` instead of `bash`, annoying errors will happen.
110
111 ### How to switch to fish
112
113 You can simply type `fish` and hit enter to start using fish from any other
114 shell.
115
116 You can also set is as the default for a particular Terminal, or for your user.
117
118 ### How to set fish as the Terminal.app shell
119
120 Find out where `fish` is:
121
122 ```bash
123 which fish
124 ```
125
126 Then update the Terminal preferences:
127
128 ```txt
129 Terminal > Preferences > General > Shells open with:
130 /Users/YOUR_USER/.local/bin/fish
131 ```
132
133 ![Terminal.app preferences](https://i.imgur.com/bulS4Vv.png)
134
135 Or, you can quit Terminal and change the preferences from the command line:
136
137 ```bash
138 #!/bin/bash
139
140 defaults write com.apple.Terminal "Shell" -string "$HOME/.local/bin/fish"
141 ```
142
143 ### How to set fish as the iTerm2 shell
144
145 Find out where `fish` is:
146
147 ```bash
148 which fish
149 ```
150
151 Then update iTerm2 preferences:
152
153 ```
154 iTerm2 > Preferences > Profiles > General > Command >
155 Custom Shell: /Users/YOUR_USER/.local/bin/fish
156 ```
157
158 ![iTerm2 Preferences](https://i.imgur.com/VtBUzVH.png)
159
160 Or, you can quit iTerm2 and change the preferences from the command line:
161
162 ```bash
163 #!/bin/bash
164
165 /usr/libexec/PlistBuddy -c "SET ':New Bookmarks:0:Custom Command' 'Custom Shell'" \
166     ~/Library/Preferences/com.googlecode.iterm2.plist
167
168 /usr/libexec/PlistBuddy -c "SET ':New Bookmarks:0:Command' 'Custom Shell' '$HOME/.local/bin/fish'" \
169     ~/Library/Preferences/com.googlecode.iterm2.plist
170 ```
171
172 ### How to set fish as the Hyper shell
173
174 Hyper is configured with JavaScript.
175
176 `~/.hyper.js`:
177
178 ```js
179 module.exports = {
180   config: {
181     // ...
182     shell: process.env.HOME + '/.local/bin/fish'
183   }
184 };
185 ```
186
187 ### How to set fish as the Alacritty shell
188
189 `~/.config/alacritty/alacritty.yml` should contain the shell config:
190
191 ```yml
192 shell:
193   program: /Users/YOUR_USER/.local/bin/fish
194   args:
195     - --login
196 ```
197
198 If you don't yet have an alacritty config, this will do:
199
200 ```bash
201 #!/bin/bash
202
203 mkdir -p ~/.config/alacritty
204
205 cat << EOF >> ~/.config/alacritty/alacritty.yml:
206 shell:
207   program: $HOME/.local/bin/fish
208   args:
209     - --login
210 EOF
211 ```
212
213 The default `alacritty.yml` is included as an _asset_ with each
214 [Github release](https://github.com/alacritty/alacritty/releases).
215
216 ### Where is the fish config?
217
218 Fish will be installed to the standard user location:
219
220 ```bash
221 ~/.local/opt/fish/
222 ```
223
224 It's config will also go in the standard user location:
225
226 ```bash
227 ~/.config/fish/config.fish
228 ```
229
230 ### How to set the default shell back to bash
231
232 See the instructions above for "How to make fish the default shell in _X_", but
233 use `/bin/bash` as the path instead of `$HOME/.local/bin/fish`.