Let's Try Fish Shell's Powerful Completion, Color-Coding, and History Features
Hello! For those of you just diving into the world of web development, and for intermediate developers looking to make your daily coding a bit more comfortable. Ever thought your daily "terminal" could be more convenient? π€
Many people's first shell is probably "Bash", but today I'm going to introduce a very smart and easy-to-use shell called "Fish Shell." Fish stands for "Friendly Interactive SHell," and as the name suggests, it's very kind to us users.
In this article, we'll focus on three of Fish's many charms: its powerful completion, intuitive color-coding, and smart history features, to let you experience just how amazing it is. No difficult setup required! Just by copying and pasting the code in this article, you should feel, "Wow, this is convenient!" Let's explore the world of Fish together and dramatically improve your terminal efficiency! π
π No More Memorizing Commands? Fish's Super-Powerful "Completion" Feature
The biggest stress of terminal operations is the hassle of having to remember or look up commands every time, asking yourself, "Wait, what was that command?" or "How do I spell that option?" Fish's completion feature makes such worries a thing of the past.
When you start typing a command, it suggests the likely next command in a light gray color based on your history and context. If the suggestion is what you want, just press β (right arrow key) or Ctrl + F to accept it! It saves a surprising amount of typing.
Completing Command Subcommands
For example, the version control tool `git` has many subcommands (`commit`, `push`, `pull`, etc.). Just by typing `git` and pressing the space key, Fish will show you a list of available subcommands.
$ git
(After typing the above, a list of commands like `add`, `blame`, `branch`, `checkout`, etc., will be displayed)
Completing Options (Flags)
It's easy to forget command options, too. But with Fish, you're covered. If you type a hyphen `-`, it will display a list of available options for that command, complete with descriptions. You'll hardly ever need to use the `man` command again.
$ ls -
(After typing the above, options like `-a` (all), `-l` (long format), `-t` (sort by time) will be displayed with their descriptions)
Completing File and Directory Paths
Of course, its path completion for files and directories is also powerful. When you start typing a path with a command like `cd` and press the Tab key, it shows a list of candidates. As you type more characters, the list of candidates narrows down. This also prevents typos, killing two birds with one stone!
$ cd D/P/
(For example, if you want to navigate to `Documents/Projects/`, Fish can cleverly complete it even if you type in uppercase like above)
π¨ Understand at a Glance! Intuitive "Color Display"
A black screen with only white text is a bit bland and can make it hard to figure out what's what. Fish, by default, color-codes text according to its syntax. This allows you to judge the correctness of a command or the type of a file at a single glance.
Valid Commands are Blue
Executable commands that exist on the system are displayed in blue. You can visually confirm "Ah, this command is usable" the moment you type it, which is reassuring.
$ ls -l
(`ls` will be displayed in blue)
Invalid Commands are Red
On the other hand, non-existent commands or typos are displayed in red. You can spot a mistake before you even run it, preventing unnecessary errors. This is truly convenient!
$ lss -l
(The typo `lss` for `ls` will be displayed in red)
Color-coding File and Directory Types
The output of commands is also colorful. For example, when you use the `ls` command, directories are in bold blue, executable files are in green, compressed files are in red, and so on, colored according to their type. You can find what you're looking for right away.
$ ls
(Files and folders in the current directory will be displayed in different colors)
π°οΈ Search the Past as You Type! The Incremental "History" Feature
Ever thought, "I want to use that long command I just ran again..." and then mashed the β (up arrow key)? With Fish, you can recall history much more smartly.
Fish's history search is based on "incremental search." By simply typing part of a command, the most recent history entry containing that string is suggested.
Search History While Typing
For example, let's say you've run the `git commit` command several times in the past. Try typing `git` at the prompt and then pressing the β key. Instead of just showing the previous command, it will search back through only the history of commands that start with `git`.
$ git
(After typing the above, pressing β will display past commands that start with `git`)
Search the Entire History with a Keyword
If you want to find an older history entry or search by a keyword in the middle of a command, `history search` is useful. It lists only the commands from your history that contain the specified keyword.
$ history search "commit"
(A list of commands from your history that include the string "commit" will be displayed)
πββοΈ The "Help" Feature for When You're Stuck
Fish is friendly even when you need help. If you don't know how to use a command, try the `help` command.
Amazingly, Fish will automatically open the help page (man page) for many commands in your default web browser. Even if you dislike reading English help pages on a black screen, you can read them carefully in your familiar browser.
$ help ls
(The manual page for the `ls` command will be opened in a new tab in your web browser)
β οΈ A Point of Caution When Using Fish
I've introduced many of Fish's good points so far, but there is one thing you should be careful about. That is the "syntax difference from Bash."
Many shell scripts and configuration examples in the world are still written based on Bash. Therefore, if you paste a command you found in an online article directly into Fish, it may not work.
For example, the command to set an environment variable. In Bash, you use `export`, but in Fish, you use `set`.
Setting Environment Variables in Bash
# This will cause an error in Fish
$ export MY_VARIABLE="hello"
Setting Environment Variables in Fish
In Fish, you set variables with the `-x` or `--export` option.
# This is the correct way in Fish
$ set -x MY_VARIABLE "hello"
You might be a little confused at first, but Fish's syntax is simpler and more consistent, so once you get used to it, you'll probably find it easier to understand. If you want to run a Bash script, you can also explicitly run it with Bash, like `bash -c "script content"`.
Conclusion
What did you think? This was just a small part of the powerful features that Fish shell has, but I hope you were able to get a glimpse of its convenience.
- The completion feature that drastically reduces typing
- The color display that prevents mistakes before they happen
- The history feature that lets you find the command you want to use right away
All of these features are available right from the moment you install it, with no additional configuration. Just by eliminating these small daily stresses, your enjoyment and concentration in coding should increase dramatically.
Please take this opportunity to install Fish shell and start your comfortable terminal life!