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