- Introduction
- Syntax highlighting
- Autosuggestions
- Autocompletions
- Tab completion
- A
Control
+R
for the future - Flying through directories
- A note on POSIX compliance
- Default shell
- Plugins
- Resources
- References
...the friendly interactive shell. A shell is a program that starts other programs
(you might have installed bash
or zsh
). fish offers a command-line interface that is focused on usability and interactive use1.
This introduction will be less about the syntax differences between the fish language and bash or zsh and more about the out-of-the-box features that are offered from this shell.
Some of you might be familiar with zsh plugin managers such as oh-my-zsh that can configure zsh to your liking, but fish just works. No more messing with chunky zsh configs and slow shells that make you wait several hundred milliseconds to type another command.
It's recommended to check the fish homepage for up-to-date instructions for installing the latest version of fish on your platform.
fish performs syntax highlighting as you type. Invalid or non-existent, unexecutable commands appear red if they cannot be executed.
![invalid-syntax-highlighting](https://private-user-images.githubusercontent.com/40929644/285758436-69c96e62-5404-4f37-840e-1bbdffcb6538.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU3NTg0MzYtNjljOTZlNjItNTQwNC00ZjM3LTg0MGUtMWJiZGZmY2I2NTM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYzNjViY2ZhMDFmNDc5N2YwMjg4ZGNlNTMzOTBiMDY5Y2U3NjIxMmY4NTNmMzQ3OGRlOTM2NmIxZjlhNWE4NmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6SCaiKPYZ_NlmtCCd6aT7_3AetkfspaC4KofrGJlAkg)
On the contrary, valid commands will appear in a different color.
![valid-syntax-highlighting](https://private-user-images.githubusercontent.com/40929644/285758500-46110031-e0e2-4522-b630-791f9c387005.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU3NTg1MDAtNDYxMTAwMzEtZTBlMi00NTIyLWI2MzAtNzkxZjljMzg3MDA1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVlOGQzNmU0NzFkNjU2ODViNzE4MzM4ODc4YTU1NWRlNDdkZTk3MjI4ZjVkN2M2ZTU1NDA5OGIzMTEwODU3NjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.4fNqqYUS2KfDaBSeW_58m6x_6O_TBWsSL-4Tw9ur3bU)
fish suggests commands as you type, based on command history. As you type commands,
suggestions are offered after the cursor in gray. To accept the suggestion, press
→
or Control
+F
.
![autosuggestions](https://private-user-images.githubusercontent.com/40929644/285632769-fd505f17-4265-41ac-b41f-59bbdd0eb670.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU2MzI3NjktZmQ1MDVmMTctNDI2NS00MWFjLWI0MWYtNTliYmRkMGViNjcwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlmYzRiZWFmMzdkMmVlOTlhNDZmMGFmYzJiOTY1ZjNiZjdkNjhlZmU3ZTkxZjcyMGNjNjYxYTQzMTI0ZDE2NTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Le_ibbTjUG6oYCPOhfhZW7SDJhIHHA8SGEXPrnn3s7E)
fish comes built with many autocompletions for commands you will encounter often. It also parses man pages and automatically generates completions.
![autocompletions](https://private-user-images.githubusercontent.com/40929644/285755950-7aa5d9fc-021a-48a8-9f20-823e666a068c.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU3NTU5NTAtN2FhNWQ5ZmMtMDIxYS00OGE4LTlmMjAtODIzZTY2NmEwNjhjLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY2Njk5ZGE2Y2MwNjJkZWI4NzFiMDEyY2IyZDNjMjdhYzU5YjNhZDU1ZDRlNjRmY2Q1MmIyZWVkOGU4OTQxMmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0._pLlO4sGpCAH1tsnTQar7bZY0Q02EkL8rFRsZg3kLO4)
Many shells offer tab completion, but fish provides a modern interface out of the box.
When you type Tab
, fish guesses the rest of the word under the cursor. It suggests
a number of possibilities and opens a menu (or "pager") that allows you to select
the command you're looking for.
![tab](https://private-user-images.githubusercontent.com/40929644/285759074-2a4c924f-d3a8-4205-8480-d541839b923d.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU3NTkwNzQtMmE0YzkyNGYtZDNhOC00MjA1LTg0ODAtZDU0MTgzOWI5MjNkLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc1OTgyZWQ1MzBjM2Q1ZTZjYTIyZWE2M2Y3YzcxNWJmYTk1ZGI0NDg2MjNjNDMyZjgxMzE3NDU1NzlmNTcyNzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.wUf6hnqf7gVjx1kdGjemGAVtHXSjwveOHcEReBjjm0c)
This is a command that you might find yourself using a lot! In bash or zsh, to
search your history, you can use Control
+R
to find some commands you've used
previously. With fish, you can type a substring, such as 'alac', and press
↑
and ↓
(or Control
+P
and Control
+N
) to traverse commands in your
history containing 'alac'.
![substr-updown](https://private-user-images.githubusercontent.com/40929644/285759408-1c616bac-6071-460f-89c5-a4f73450a05d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU3NTk0MDgtMWM2MTZiYWMtNjA3MS00NjBmLTg5YzUtYTRmNzM0NTBhMDVkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWIzMDMwZWYzNDYyMjRmZjVhOGVhODU1ZGI3NmJhYzcwMjJhOTRmMzFhYTk4MTg0MDA5NTA2MmM3ZGM1ZjAyOGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.8gj_3BcXDszPnrBoGOI5eAvkw9bjloYx9hvb-_31P8k)
You can also use Control
+R
as usual and this opens a pager to search your history.
![ctrlr](https://private-user-images.githubusercontent.com/40929644/285759753-1b4feb10-44c0-4a78-b33e-aca7dd54de79.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTE1MDMsIm5iZiI6MTczODk5MTIwMywicGF0aCI6Ii80MDkyOTY0NC8yODU3NTk3NTMtMWI0ZmViMTAtNDRjMC00YTc4LWIzM2UtYWNhN2RkNTRkZTc5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA1MDY0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYzMDhkMjVjNGRhMWM2MTE2ZGY1ZDdmYjRjODc5ZDE0MTI3YjgyYWMxNjVhOWY4MzI4Y2Q3ODM5MDY4NGI2M2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.4__y2w7fnYjCOHEyDHq_RDPvZEwmDZtYtrN1AUx2tRI)
Prefixing the command-line with a space prevents the line from being stored in history. This can be useful if your command contains a secret token that you don't want to be stored on disk.
If you've ever used pushd
or popd
, you won't have to ever again! Using Alt
+→
or Alt
+←
, you can traverse through directories you've previously changed to.
fish isn't POSIX compliant, but it isn't designed to be! Typing bash
into the
command-line to execute a command or running a script opening with a hashbang are
always options if you need bash.
At this point, if you're convinced with the benefits of fish, you can change your login shell to it as follows:
- Add the shell to
/etc/shells/
:
echo /usr/local/bin/fish | sudo tee -a /etc/shells
- Change your default shell:
chsh -s /usr/local/bin/fish
Now, log out and log back in to see the changes in effect.
First — yes, this post starts with saying fish works out of the box, and it does! You could stop right before this section and be happy with your new found shell.
But there's just one plugin to fish to leave you with: Tide. Its most useful feature is that it enables asynchronous rendering, making the prompt instantly responsive.