Boost your Terminal with These Powerful CLI Tools

Sep 15, 2024

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:

  1. This guid I ma going to use the Kitty Terminal which is:

    The fast, feature-rich, GPU based terminal emulator
    Kitty Terminal

    You 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.

  2. 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).

  3. 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.

  1. bat

    A cat(1) clone with syntax highlighting and Git integration.
    bat

    Basically it is a replacement for cat command with more powerful features.

    bat CLI tool preview 0 bat CLI tool preview 1
    • Use the arrow keys to navigate the code. And press q to quit.

    You can also display more than one file at once:

    bat CLI tool preview 2 bat CLI tool preview 3

    To install it you have to run the following command.

    zsh
    sudo 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 bat via piping in order to display it in a more convenient way: For example You can pass the output of curl command to bat:

      Before:

      zsh-syntax-highlighting preview

      After:

      zsh-syntax-highlighting preview

      Note:
      In the coming sections we will see how other CLI tools integrate with Bat

  2. 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 of ls.
    eza

    zsh-syntax-highlighting preview zsh-syntax-highlighting preview zsh-syntax-highlighting preview zsh-syntax-highlighting preview zsh-syntax-highlighting preview zsh-syntax-highlighting preview

    To install it run the following commands or check the installation documentation:

    zsh
    sudo 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 ls with eza:

      It is better to use eza but with the ls keyword to save up some muscle memory. In order to do so you need to set up aliases in the .zshrc file. Here are my eza aliases:

      zsh
      alias 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'
  3. 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.
    zoxide

    Similar to eza, zoxide is the better cd

    zsh-syntax-highlighting preview

    To install it via the following command:

    zsh
    curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
    • Replace cd with zoxide:

      Similar to eza it is better to use the cd keyword instead:

      Here are my aliases in my .zshrc file:

      zsh
      alias cd='z'
      alias ..='z ..'
      alias ...='z ../..'
      alias ....='z ../../..'
      alias ~='z ~'
  4. fzf

    fzf is a general-purpose command-line fuzzy finder.
    fzf

    It is a better and super fast way to search in the terminal

    zsh-syntax-highlighting preview zsh-syntax-highlighting preview zsh-syntax-highlighting preview

    To install it run the following command:

    zsh
    git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
    ~/.fzf/install
    • Integrating With Bat: You can also display the output of fzf in a beautiful way using bat via passing the --preview argument to fzf

      zsh
      fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"

      Here is the result:

      zsh-syntax-highlighting preview zsh-syntax-highlighting preview

      You can use the arrow keys to navigate the files and Ctrl + arrow keys to 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 .zshrc file, add the following lines (easier than typing the whole string each time):

      zsh
      show_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 + c to preview subdirectories in the current directory:

      zsh-syntax-highlighting preview

      Similarly you can can click Ctrl + t to preview files in the current directory:

      zsh-syntax-highlighting preview
  5. 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-cli

    It provides these commands:

    zsh
    trash-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 rm where you can not delete an important file accidentally. If so you can find it in the trash can.

    Replacing rm with trash-cli:

    You can add aliases in the .zshrc to replace the rm command with trash-cli, while keeping you muscle memory too:

    Here are mine:

    zsh
    alias 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.

dot-cli repository preview

It Includes Two parts:

  1. Full Installer.
  2. individual Plugin Installer.

Here is how to use it:

  1. Clone the Repository

    Clone this repository to your local machine:

    bash
    git clone https://github.com/syntaxbox/dot-cli
    cd dot-cli
  2. Run the Installation Script

    Execute the install.sh script to install all the CLI tools presented in the repo:

    zsh
    chmod +x install.sh
    ./install.sh
  3. Install individual CLI tools only

    If you want to install a specific CLI tool:

    For example eza, here is how:

    zsh
    chmod +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 :)