add fish
[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 vim to keep using bash
60
61 The first line of your `.vimrc` should always be `set shell=/bin/bash`.
62
63 `~/.vimrc`:
64
65 ```vim
66 set shell=/bin/bash
67 ```
68
69 ### How to make fish the default shell on Linux
70
71 This requires editing a protected system file, `/etc/shells`. It is better to
72 use the Terminal-specific methods.
73
74 First, `fish` must be installed and in the `PATH`.
75
76 ```bash
77 # if you don't see a file path as output, fish is not in the path
78 which fish
79 ```
80
81 Second, fish must be in the system-approved list of shells in `/etc/shells`:
82
83 ```bash
84 #!/bin/bash
85
86 if ! grep $(which fish) /etc/shells > /dev/null; then
87     sudo bash -c "echo '$(which fish)' >> /etc/shells";
88     echo "added '$(which fish)' to /etc/shells"
89 fi
90 ```
91
92 You should use `chsh` to change your shell:
93
94 ```bash
95 #!/bin/bash
96
97 sudo chsh -s "$(which fish)" "$(whoami)"
98 ```
99
100 If vim uses `fish` instead of `bash`, annoying errors will happen.
101
102 ### How to switch to fish
103
104 You can simply type `fish` and hit enter to start using fish from any other
105 shell.
106
107 You can also set is as the default for a particular Terminal, or for your user.
108
109 ### How to set fish as the Terminal.app shell
110
111 Find out where `fish` is:
112
113 ```bash
114 which fish
115 ```
116
117 Then update the Terminal preferences:
118
119 ```txt
120 Terminal > Preferences > General > Shells open with:
121 /Users/YOUR_USER/.local/bin/fish
122 ```
123
124 ![Terminal.app preferences](https://i.imgur.com/bulS4Vv.png)
125
126 Or, you can quit Terminal and change the preferences from the command line:
127
128 ```bash
129 #!/bin/bash
130
131 defaults write com.apple.Terminal "Shell" -string "$HOME/.local/bin/fish"
132 ```
133
134 ### How to set fish as the iTerm2 shell
135
136 Find out where `fish` is:
137
138 ```bash
139 which fish
140 ```
141
142 Then update iTerm2 preferences:
143
144 ```
145 iTerm2 > Preferences > Profiles > General > Command >
146 Custom Shell: /Users/YOUR_USER/.local/bin/fish
147 ```
148
149 ![iTerm2 Preferences](https://i.imgur.com/VtBUzVH.png)
150
151 Or, you can quit iTerm2 and change the preferences from the command line:
152
153 ```bash
154 #!/bin/bash
155
156 /usr/libexec/PlistBuddy -c "SET ':New Bookmarks:0:Custom Command' 'Custom Shell'" \
157     ~/Library/Preferences/com.googlecode.iterm2.plist
158
159 /usr/libexec/PlistBuddy -c "SET ':New Bookmarks:0:Command' 'Custom Shell' '$HOME/.local/bin/fish'" \
160     ~/Library/Preferences/com.googlecode.iterm2.plist
161 ```
162
163 ### How to set fish as the Hyper shell
164
165 Hyper is configured with JavaScript.
166
167 `~/.hyper.js`:
168
169 ```js
170 module.exports = {
171   config: {
172     // ...
173     shell: process.env.HOME + '/.local/bin/fish'
174   }
175 };
176 ```
177
178 ### How to set fish as the Alacritty shell
179
180 `~/.config/alacritty/alacritty.yml` should contain the shell config:
181
182 ```yml
183 shell:
184   program: /Users/YOUR_USER/.local/bin/fish
185   args:
186     - --login
187 ```
188
189 If you don't yet have an alacritty config, this will do:
190
191 ```bash
192 #!/bin/bash
193
194 mkdir -p ~/.config/alacritty
195
196 cat << EOF >> ~/.config/alacritty/alacritty.yml:
197 shell:
198   program: $HOME/.local/bin/fish
199   args:
200     - --login
201 EOF
202 ```
203
204 The default `alacritty.yml` is included as an _asset_ with each
205 [Github release](https://github.com/alacritty/alacritty/releases).
206
207 ### Where is the fish config?
208
209 Fish will be installed to the standard user location:
210
211 ```bash
212 ~/.local/opt/fish/
213 ```
214
215 It's config will also go in the standard user location:
216
217 ```bash
218 ~/.config/fish/config.fish
219 ```
220
221 ### How to set the default shell back to bash
222
223 See the instructions above for "How to make fish the default shell in _X_", but
224 use `/bin/bash` as the path instead of `$HOME/.local/bin/fish`.