What is Fish Shell? A User-Friendly Shell That Even Beginners Will Love π
Does the "black screen" (also known as the terminal or console) intimidate you? As a web creator, you often have to type commands for things like Git operations or build tasks, right?
"I can't remember the commands..." "I keep getting errors from typos..." "The configuration is too difficult and I gave up..."
If that sounds like you, then you should definitely try the "Fish Shell". Fish stands for "Friendly Interactive Shell," and as the name suggests, it's an incredibly user-friendly shell that's perfect for beginners. In this article, we'll skip the complicated stuff and let you experience the power of Fish by simply copying and pasting!
π What's So Great About Fish Shell? 3 Amazing Features
Fish shell has many great features, but here are three main ones that will surely impress beginners.
1. "Autosuggestions" (Command History Completion) That Feel Like Mind-Reading
The biggest highlight of the Fish shell is its autosuggestions. It remembers the commands you've typed in the past and suggests what you might want to type next in a light gray text after just a few characters. If the suggestion is correct, just press the β (right arrow) key or Ctrl+F to accept it. No more retyping long commands!
For example, let's say you've previously typed the command `git switch feature/new-design`. The next time you type `git s`...
$ git switch feature/new-design
It automatically suggests the rest of the command. This feature alone is guaranteed to dramatically improve your terminal productivity!
2. Instantly Spot Mistakes! "Syntax Highlighting"
Typing commands incorrectly is a major source of errors. Fish shell color-codes your commands in real-time to show whether they are valid.
For instance, an existing command like `git` is displayed in cyan.
$ git
However, if you type a non-existent command like `gitt`, it turns red. This allows you to notice the typo before you even run it.
$ gitt
3. No Config Files Needed! Easy Customization in Your Web Browser
When you think of shell customization, you probably imagine editing complex configuration files like `~/.bashrc`. With Fish shell, you don't have to worry about that. Just run the following command.
$ fish_config
When you run this command, your web browser will automatically open, allowing you to easily customize color schemes and the look of your prompt (the text that appears while waiting for a command) with just a few clicks while seeing a live preview. Even if you're not a fan of the black screen, you can intuitively create an environment you love.
π» Let's Try It Out! Basic Fish Shell Operations
Now, let's try some actual Fish commands. Copy and paste them into your terminal to see how they work.
Printing Text: `echo`
First is the basic `echo` command. It prints the specified string to the screen. This is almost the same as in other shells.
$ echo "Hello, Fish Shell!"
Hello, Fish Shell!
Using Variables: `set`
To handle variables in Fish shell, you use the `set` command. You don't use `=` (the equals sign). Separating with a space is the Fish way.
$ set name "John Smith"
To check the content of a variable, use `echo` with a `$` prefix.
$ echo $name
John Smith
Looping: The `for` Loop
The `for` loop in Fish has a very intuitive and readable syntax compared to other shells.
For example, let's display the strings from `item-1` to `item-3` one by one.
$ for item in item-1 item-2 item-3
echo $item
end
item-1
item-2
item-3
You can also use the output of a command to loop, like with `(seq 1 3)`. This command generates numbers from 1 to 3.
$ for i in (seq 1 3)
echo "Number: $i"
end
Number: 1
Number: 2
Number: 3
Creating a Simple Function: `function`
You can group a series of frequently used commands into a function. Here, let's create a function named `hello` that gives a greeting.
$ function hello
echo "Hello, $argv!"
end
Now you've created a new command called `hello`. `$argv` is a special variable that holds the arguments (in this case, a name) passed to the function.
Let's run the function you just created.
$ hello "World"
Hello, World!
π‘ A Little More Convenient! Advanced Usage
More Powerful Than Aliases: The `abbr` Command
`abbr` (short for abbreviation) allows you to expand short keywords into long commands. It's similar to an alias, but the key feature of `abbr` is that after typing it, pressing Space or Enter expands it into the full command on the spot. This lets you confirm what will be executed beforehand.
Let's set up a shortcut `gco` for the `git checkout` command, which is frequently used by web creators.
$ abbr --add gco "git checkout"
Now, when you type `gco` in the terminal and press space, it will instantly expand to `git checkout`. This reduces the amount of typing and makes things really comfortable!
β οΈ Heads Up! Differences from bash
Fish is excellent, but it has some differences from the `bash` shell, which is standard on many Linux and macOS systems. You need to be especially careful when copying and pasting commands from other websites.
1. How to Write AND (&&)
When running multiple commands in succession, bash uses `&&`, but Fish uses `; and`.
β Incorrect (bash style)
$ mkdir new_dir && cd new_dir
β Correct (Fish style)
$ mkdir new_dir; and cd new_dir
2. How to Set Environment Variables
The method for setting environment variables, such as for adding to your PATH, is also different. Bash uses `export`, while Fish uses the `set` command with the `-x` (export) option.
β Incorrect (bash style)
$ export MY_VARIABLE="some_value"
β Correct (Fish style)
$ set -x MY_VARIABLE "some_value"
As long as you remember these differences, you'll rarely run into trouble.
Summary
So, what did you think? We hope you were able to experience the charm of Fish shell, especially user-friendly features like 'autosuggestions' and 'syntax highlighting,' by copying and pasting.
Even if you've been intimidated by terminal operations until now, we're sure that using Fish shell will make you think, "I want to use this more!" When command operations become comfortable, your development efficiency will dramatically increase.
If you've become interested in Fish shell after reading this article, please proceed to the next article to install it and incorporate it into your development environment!
Next Step βΆ How to Install and Set Up Fish (Linux / macOS)