Boost your Terminal with These Powerful CLI Tools
Last Updated: September 15, 2024, By: Abdelhamid Boudjit, 14 min read.
Knowing how to use a terminal is an essential skill for every developer. But what makes it so powerful is its extensions and plugins along with some CLI tools. Making the terminal experience more efficient and enjoyable.
Before We Start:
-
This guid I ma going to use the Kitty Terminal which is:
The fast, feature-rich, GPU based terminal emulator
Kitty TerminalYou can use whatever Terminal emulator you prefer. If you want to use the same configuration I use you can check my Configurations repository. Where you can install kitty along with the configurations and theme.
-
I will use Debian as my OS, all installation scripts will only work on Debian based linux distributions (Don't worry I'll include the official websites & installations if you are not using Debian based Linux distributions).
-
I will use Zsh as my shell. checkout my previous Blog post Boost your Terminal with Zsh extensions. If you want to add custom behaviors in the following sections.
CLI Tools
For Lazy People Like me:
I will Include a Github Repository for automated installation process in
the end of the section. So feel free to skip the manual installation.
-
bat
A cat(1) clone with syntax highlighting and Git integration.
batBasically it is a replacement for cat command with more powerful features.
- Use the arrow keys to navigate the code. And press
qto quit.
You can also display more than one file at once:
To install it you have to run the following command.
zshsudo apt install bat mkdir -p ~/.local/bin ln -s /usr/bin/batcat ~/.local/bin/bat
You also can change the theme. Checkout the official documentation for more explicit details.
-
Integration with other CLI tools:
You can pass any command output to
batvia piping in order to display it in a more convenient way: For example You can pass the output ofcurlcommand to bat:Before:
After:
Note:
In the coming sections we will see how other CLI tools integrate with Bat
- Use the arrow keys to navigate the code. And press
-
eza
eza is a modern, maintained replacement for the venerable file-listing command-line program ls that ships with Unix and Linux operating systems, giving it more features and better defaults. It uses colours to distinguish file types and metadata. It knows about symlinks, extended attributes, and Git. And it's small, fast, and just one single binary.
By deliberately making some decisions differently, eza attempts to be a more featureful, more user-friendly version ofls.
eza
To install it run the following commands or check the installation documentation:
zshsudo apt update sudo apt install -y gpg sudo mkdir -p /etc/apt/keyrings wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list sudo apt update sudo apt install -y eza-
Replace
lswitheza:It is better to use
ezabut with thelskeyword to save up some muscle memory. In order to do so you need to set up aliases in the.zshrcfile. Here are my eza aliases:zshalias ls='eza --color=always --git --no-filesize --icons=always --no-time --no-user --no-permissions' alias lc='eza --color=always --long --git --no-filesize --icons=always --no-time --no-user --no-permissions' alias ll='eza -l --color=always --long --git --icons=always' alias la='eza -a --color=always --long --git --icons=always' alias lt='eza --tree --level=2 --icons=always --color=always'
-
-
zoxide
zoxide is a smarter cd command, inspired by z and autojump.
It remembers which directories you use most frequently, so you can "jump" to them in just a few keystrokes
zoxide works on all major shells.
zoxideSimilar to
eza,zoxideis the bettercd
To install it via the following command:
zshcurl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh-
Replace
cdwithzoxide:Similar to
ezait is better to use thecdkeyword instead:Here are my aliases in my
.zshrcfile:zshalias cd='z' alias ..='z ..' alias ...='z ../..' alias ....='z ../../..' alias ~='z ~'
-
-
fzf
fzf is a general-purpose command-line fuzzy finder.
fzfIt is a better and super fast way to search in the terminal
To install it run the following command:
zshgit clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf ~/.fzf/install-
Integrating With Bat: You can also display the output of
fzfin a beautiful way usingbatvia passing the--previewargument tofzfzshfzf --preview "bat --color=always --style=numbers --line-range=:500 {}"Here is the result:
You can use the arrow keys to navigate the files and
Ctrl + arrow keysto navigate the code (file data). -
Integrating With eza:
You can setup shortcuts in your terminal emulator to make it easier to access the fuzzy finder along with
.zshrc:Here is an example using
Zsh(it is also similar in other shells): in your.zshrcfile, add the following lines (easier than typing the whole string each time):zshshow_file_or_dir_preview="if [ -d {} ]; then eza --tree --color=always {} | head -200; else bat -n --color=always --line-range :500 {}; fi" export FZF_CTRL_T_OPTS="--preview '$show_file_or_dir_preview'" export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"Now you can click
Alt + cto preview subdirectories in the current directory:
Similarly you can can click
Ctrl + tto preview files in the current directory:
-
-
trash-cli
trash-cli trashes files recording the original path, deletion date, and permissions. It uses the same trashcan used by KDE, GNOME, and XFCE, but you can invoke it from the command line (and scripts).
trash-cliIt provides these commands:
zshtrash-put trash files and directories. trash-empty empty the trashcan(s). trash-list list trashed files. trash-restore restore a trashed file. trash-rm remove individual files from the trashcan.Similar to previous commands it is a better
rmwhere you can not delete an important file accidentally. If so you can find it in the trash can.Replacing
rmwithtrash-cli:You can add aliases in the
.zshrcto replace thermcommand withtrash-cli, while keeping you muscle memory too:Here are mine:
zshalias rm="trash" alias tl="trash-list" alias tr="trash-restore" alias te="trash-empty"
Automated Installation script
Here is a GitHup Repository created by me to automate the process. The Repository called dot-cli.
It Includes Two parts:
- Full Installer.
- individual Plugin Installer.
Here is how to use it:
-
Clone the Repository
Clone this repository to your local machine:
bashgit clone https://github.com/syntaxbox/dot-cli cd dot-cli -
Run the Installation Script
Execute the
install.shscript to install all the CLI tools presented in the repo:zshchmod +x install.sh ./install.sh -
Install individual CLI tools only
If you want to install a specific CLI tool:
For example
eza, here is how:zshchmod +x tools/eza.sh ./tools/eza.sh
Conclusion
These are the CLI Tools that I personally use daily.
Make sure to check out the official documentation for each CLI tool to see the customizations and the tweaks that you can make.
I will be updating this post whenever I find my self using a new CLI tool. See you around :)