Taking the terminal to the next level: customizing features

guto

guto

Posted on January 6, 2023

Taking the terminal to the next level: customizing features

Table of contents

  1. Presentation
  2. Introduction
  3. What is terminal?
  4. Some shell types
    1. Bash
    2. Zsh
    3. Fish
  5. Customizations for each shell
    1. Configuration files
    2. Visual
      1. Bash and oh-my-bash
      2. Zsh and oh-my-zsh
      3. Fish, oh-my-fish, fisher and z
    3. Nerd Fonts
  6. Conclusion

Presentation

If you are interested in starting to use Linux in 2023, or if you already use it and want to customize and maximize your performance using the terminal, know that you are in the right place! This guide intends to show how you can use native tools from the terminal itself and customize it to make it your own, increasing your productivity and stepping out of your comfort zone!

Introduction

The terminal has been part of developers' day-to-day life for a long time, and it is possible to say that the evolution of computers to what we know today only became possible because, way back, the terminal itself was created, with that little face of "a black screen with several small letters", which, during the time when we didn't have a graphical interface, it was our means of communication with the computer.

Currently, we live in a time when technology is part of practically everyone's life, so we have become accustomed to certain interfaces and ways of solving different problems in our daily lives, resulting in an effect that makes cutting-edge technology a reality. increasingly simple to be understood by human eyes according to the levels of abstractions that are added to it.

Therefore, it is not so difficult to find someone who does not know how or does not like to use a computer via a terminal, which is characterized not as a negative phenomenon, but as a phenomenon resulting from the great reach of technology in people's lives, enabling the use of them without the need for large studies behind. Technology is in our midst and is part of our daily lives in such an intertwined way that many times we are not even able to notice it.

Punctuating this advance in technology, today, I will show you how the terminal has also evolved a lot, becoming a powerful tool, making the user who dominates the terminal and its tools become totally independent and productive during the days as a developer.

What is terminal?

Emerging at the beginning of the computing era, existing until today as an essential tool in an operating system, basically, the terminal would be nothing less than the first interface that enabled human-computer interaction, in which a sequence of commands could be sent (input), then it is processed (processing), and it returns a response (output).

The terminal "has" the appearance of a black screen even when waiting for a command entry (the word was placed in quotes because currently, not necessarily a terminal is like that, after all, it can be customized in several ways and this will be shown here later) . He is the user's contact with the "shell", and uses a command interpreter for the "shell".

Shell is nothing more than the layer that acts as an "interlocutor" between the user and the operating system kernel, being responsible for validating and sending commands to the kernel, which is responsible for managing our hardware.

Image demonstrating the shell wrapping the kernel while the user sends input directly to the shell
Image demonstrating the process of user input and sending the instruction to the Kernel

Currently, in most Linux distributions, the terminal is found in the form of an external emulator, running as a common application in which many times some users do not even realize that we can install several other emulators that use GPU acceleration (a powerful tool for users with more "powerful" GPUs), simple visual customization, font customization, among many other possible customizations.

Using the default terminal emulator of your Linux distribution is your choice, it depends on which type of emulator you are most comfortable with, so the choice itself is up to you! I will present some customizations of Shell interpreters, moving on to a presentation of several terminal emulators that can be installed both in Linux distributions and other Unix-based operating systems, such as macOS and FreeBSD for example.

As much as it makes the text longer, the basic explanations of the operation and history of the terminal are necessary for a complete understanding, allowing you to start from that point to advance your knowledge.

Some shell types

There are several types of command interpreters, but I will mention three main ones that you can choose to use and customize, starting from its purest interface, until we reach a point where you will feel comfortable.

Bash

Used in several Linux distributions as a default command interpreter, Bash is currently maintained by the GNU project and the Free Software Foundation. Bash already has a very pleasant interface when compared to other interpreters from the GNU project itself, such as "sh" for example, which is currently found as a standard command interpreter for distributions without a native graphical interface for installation (as in some servers), or then on other Unix-based operating system projects such as FreeBSD.

Widely spread and, I believe, the most used command interpreter in Linux distributions, bash may be the perfect choice for you. Its appearance after installation can be found in different ways, but currently there are two main ones that we can highlight, which are similar to:



[guto@turing ~]$

guto@turing:~ $


Enter fullscreen mode Exit fullscreen mode

Zsh

Emerging in the 1990s, zsh has caught the eye of many users over the years for being a slightly different shell than Bash. Its appearance and functionality after installation is much simpler than bash, but after a lot of customization it can become extremely powerful.

Initially being distributed with a license respecting the Berkeley standards, zsh had its skyrocket in use in macOS systems when Apple in 2020 officially switched the default shell of its operating system for bash users to zsh due to some issues involving the GNU GPL v3.0 license.

Starting zsh after installation is very simple: if you already have the zsh configuration file (it could be .zshrc for example), it will start with an appearance bringing only the machine name (very similar to sh), but, if you don't have this file yet, it will display a message alerting you that this file does not exist, in which case, pressing "0" will automatically create this empty file just to not return this message anymore. The initial appearance of zsh looks something like this:



turing%


Enter fullscreen mode Exit fullscreen mode

Fish

With its initial release in 2005, fish shell has pleased many users around the world mainly due to its ease of customization, with native functions including command autocompletion with automatic suggestions, pre-configured visuals, among other diverse features.

The fish shell is also free software and includes parts of the GNU GPL v2.0 license, OpenBSD license, ISC license and NetBSD license, and can be evaluated in its repository at github. In most cases the fish shell will have to be installed externally, after all, not all distributions have it installed by default.

Its default appearance is nice and bash-like, differing by having a "fish" instead of a simple dollar sign ("$") for non-root users. Its default appearance looks like:



guto@turing ~>


Enter fullscreen mode Exit fullscreen mode

The fish shell can have direct integration with your terminal emulator, allowing its customization directly from a page generated locally by executing the "fish_config" command, in which it is possible to customize the colors, functions, shortcuts, among other diverse functionalities. The generated screen looks like the image below:

Image of the locally generated fish shell configuration screen after running the fish_config command
Showing the fish shell configuration screen with the fish_config command

Customizations for each shell

Now, let's move on to configuring your chosen command interpreter.

Configuration files

The configuration files of each shell may vary in name, but we will address their names and how to access them, and what are the main functions that we can customize and use in our daily lives, such as creating an alias.

  • Bash: .bashrc or .bash_profile
  • Zsh: .zshrc or .zsh_profile
  • Fish: ~/.config/fish/config.fish

Open the file in your favorite text editor, and you may find a series of instructions that you didn't know or even had no idea what they would be for.

In this file, go to the end of it so we don't have the possibility of damaging its content or even compromising some function that you like. On the last line, we can add a series of commands that our interpreter must understand.

The first of the instructions to be created will be an example of "alias", which would be nothing more than a "nickname" for some sequence of commands that we want to execute. In this case I will create an alias to install a package with root permissions (the famous "sudo"). Our alias will look like this:



alias install="sudo apt install" # For Debian based distributions
alias install="sudo dnf install" # For Red Hat based distributions
alias install="sudo pacman -Sy" # For Arch Linux based distributions

# For macOS
alias install="brew install" # If you are using Homebrew as a package manager


Enter fullscreen mode Exit fullscreen mode

Please, pay attention to which distribution you are adding the command to, after all, each one has its own package manager, right? What do you think of an article in the future talking a little about the structure of a Linux operating system?

The structure of creating an alias is very simple and respects the following structure:



alias [command]="[command to be executed when calling this alias]"


Enter fullscreen mode Exit fullscreen mode

The use of aliases on a day-to-day basis is powerful and can make it much easier when it comes to productivity, which we can expand to a series of functions that we can install and customize within our configuration file, in which we are going to customize its appearance now.

Did you notice that the fish shell has a slightly different file? Well, it accepts slightly different instructions in its use, but, in order not to extend myself so much, know that you can access the official fish shell documentation.

Visual

Now you know where your command interpreter configuration file is, so you know where you can create native functions interpreted in Shell for your day-to-day! In this way, we are now going to a visual customization of each shell.

Bash and oh-my-bash

Going to the appearance, we know that bash has an appearance that may not please everyone, but that can be customized and for that there are two main ways that will be presented: using the standard command for creating appearances or through a tool that facilitates our customization, called "oh-my-bash", being maintained by an amazing community.

The line below will show how the appearance of your input line in bash can be modified by changing the PS1, responsible for leaving it with this more pleasant look:



export PS1='\u@\h:\[\e[01;32m\]\w\[\e[0m\]\$ '


Enter fullscreen mode Exit fullscreen mode

Basically it leaves a "user@host:path/to/directory $" with the hostname in green! To change the foreground colors it was necessary to add the code snippet that contains some numbers inside, the color code respecting the ANSI table for bash! An important detail to remember is that according to your terminal emulator these colors may contain different shades that you can customize yourself!

Image with ANSI color table shown by terminal
Table of colors and ANSI codes displayed by the terminal

Support for the so-called "true color", which would be the 256 RGB colors varies according to the terminal emulator you are using.

Right, but what if I want to perform a simpler customization without the need to change color codes or already use some existing customization, can I do it? The answer is yes, you can, and the oh-my-bash project came about for just that purpose!

Accessing the official website you can browse the documentation, contribute and view the themes already published, and their installation can be done using curl or wget. If you haven't installed any of the two packages yet, just use the following commands:

wget



sudo apt install wget # For Debian based distributions
sudo dnf install wget # For Red Hat based distributions
sudo pacman -Sy wget # For Arch Linux based distributions

# For macOS
brew install wget # If you are using Homebrew as a package manager


Enter fullscreen mode Exit fullscreen mode

curl



sudo apt install curl # For Debian based distributions
sudo dnf install curl # For Red Hat based distributions
sudo pacman -Sy curl # For Arch Linux based distributions

# Para macOS
brew install curl # If you are using Homebrew as a package manager


Enter fullscreen mode Exit fullscreen mode

After installing, just open a new tab of your terminal emulator to update and you will be able to see that the default theme has been changed! To browse between the oh-my-bash themes, just click on the themes tab and access the repository which presents all the themes and choose one of your interest.

Once you choose, just open the bash configuration file (.bashrc or .bash_profile) and right at the beginning of the file you will see something like:



OSH_THEME="font"


Enter fullscreen mode Exit fullscreen mode

Just change the name "font" to the name of the theme you want to put (without removing the quotes), and that's it! Now just restart your terminal emulator or open a new tab and you'll be in your new look! Did you like it?

Zsh and oh-my-zsh

The configuration of the look of zsh shell starts from the same principle as bash with the creation of a variable "PS1" that can be accessed in the tab above.

oh-my-zsh is a project maintained by a community just like the oh-my-bash project, however, it has some differences that make this community huge, ranging from complete documentation to even a store of products from the which we can purchase t-shirts, stickers, among others.

Accessing the official website project we can view a simple installation guide using curl or wget, in which it was previously shown how we can install both tools.

After installation, we can easily browse the oh-my-zsh themes tab (which is also available on the website) and choose a theme from our preference that, when opening our configuration file (.zshrc or .zsh_profile for example) we will come across something similar at the beginning of our configuration file:



ZSH_THEME="robbyrussell"


Enter fullscreen mode Exit fullscreen mode

To change the theme and choose the theme of your personal taste, just change the name that is between quotes to the name of the theme you want to install and then open a new tab of your terminal emulator to boot with the new theme working normally!

Fish, oh-my-fish, fisher and z

The fish shell, as mentioned earlier, has some additional settings that can be used to customize our shell and in this case, we can handle and manipulate plugins within it.

The fish configuration file is found in the path "~/.config/fish/config.fish" and we can customize the entry using "PS1", just like in bash and zsh. If you want a slightly nicer interface to customize its operation, just use the "fish_config" command, which will open a mini local server so that your changes take effect in real time.

Like oh-my-bash and oh-my-zsh, oh-my-fish came up with the possibility for users to use pre-defined themes published and maintained by the community as a way to provide a better use of the fish shell. Oh-my-fish does not have an official page, but its repository is published on GitHub and can be installed in several ways, but with the simple installation script we will use the command:



curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish


Enter fullscreen mode Exit fullscreen mode

If you have any problems with the installation, just access the official GitHub page of oh-my-fish and install by directly cloning the official repository, as shown in the README of the project.

The themes can be accessed and chosen according to your taste and their installation can be done with the command:



omf install URL # To enter the theme URL
omf install user/repo # To enter the theme repository
omf install name # To enter the theme name from the list of pre-installed themes


Enter fullscreen mode Exit fullscreen mode

Now, starting with the usability customization of the fish shell we can mention fisher, which is a plugin manager for the fish shell, being used to install several repositories with functionalities incredible things that fish shell can offer.

To install fisher just run the following command:



curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher


Enter fullscreen mode Exit fullscreen mode

After installed you can check a list of plugins that shows several that are used by the community.

The big icing on the cake comes now, with the plugins being able to be customized and their appearance being unique: z. That's right, this name, the "z" has the function of working to record the directories you visit and create shortcuts that facilitate your navigation within your operating system. To install z with fisher just run the following command:



fisher install jethrokuan/z


Enter fullscreen mode Exit fullscreen mode

After that, you can start using your terminal emulator normally, until it manages to register repetitive entries in a directory to create several shortcuts. If in doubt, z's manual can still be accessed on GitHub.

If you want more extensive configurations involving the fish shell, I recommend watching Takuya Matsuyama's channel called "devaslife" and a specific video in which he shows how to configure the fish shell in your daily life.

Nerd Fonts

In our daily lives, many times we will find several special characters or symbols formed that, when we type, do not form exactly what we would like. A practical example would be when we're writing our code and the "!=" doesn't look like it does in math, or the "->" doesn't look that much like an arrow.

It was from this need that "Nerd Fonts" emerged, with the aim of supplying and making our code editor look cooler, working in our terminal and making special symbols understood and presented in the expected way.

The homepage has a link to the offiical repository of the project, showing its releases and updates with new fonts. To install the fonts is very simple: you can install by downloading the zipped files and installing the fonts, or, install by your package manager.

The number of symbols that these fonts can reach is enormous, allowing for several customizations.

Image demonstrating the compatibility of 'Nerd Fonts' fonts compared with various icons and symbols
Comparison of "Nerd Fonts" with various icons and symbols and their compatibility

Conclusion

The use of the terminal in the day-to-day of the developer can be useful in infinite ways. Knowing how to be independent and being able to use the terminal is a job that requires dedication, but which is certainly worth every second of learning.

The terminal is a powerful tool and may be the only one a developer can use in their daily lives as long as they know how to use it correctly.

Customizing the terminal is not a waste of time, it's a learning process to make your work environment more comfortable and accessible to your personal tastes, making you feel satisfied.

Regardless of the shell you choose, how you customize it and which terminal emulator you like, I hope this guide has helped you and added something new to your learning experience.

💖 💪 🙅 🚩
guto
guto

Posted on January 6, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related