Top CLI Programs Which Finally Solved My Fear Of The Terminal ⌨️
Published: 2020-10-19 00:34:45

This post is for those who are scared of using the command line.

I have switched back and forth between Windows and various Linux distributions for the better part of 3 years.

Frustration about lack of hardware or software support, inability to play some games, and most importantly, using the terminal, were some of the biggest factors which made me go back to Windows from Linux every time.

It wasn't like I was not touching the terminal at all; installing NPM dependencies, changing directory, even simple editing with VI are not the challenges with using the terminal.

The issue was leaving the terminal to search for a command I just used 5 minutes ago or forgetting the correct flag for a certain command that did not have a detailed man page.

So I was stuck in eternal limbo, bouncing back and forth with operating systems and other command tools.

That was until I found the subreddit that changed my view of the terminal (literally) - [r/unixporn](https://www.reddit.com/r/unixporn/)

# Customizing My Terminal

After spending way too much time researching and testing out various terminal emulators, colour themes, and fonts, this is my current terminal start-up view.

![My current terminal](https://dev-to-uploads.s3.amazonaws.com/i/ar6ol63rvyiah4f7js27.png)

Let's dive into some programs which helped me use the terminal for programming!

# Fuzzy Search 🔍

You open a terminal, and bam, you're faced with a black screen with a blinking white line. 

What do you do next? Why is the white line blinking? What do you type? 

The oncoming feelings of confusion and helplessness can be overwhelming and many stop there.

Searching is familiar, we're all used to using a search engine to solve our problems, and most searches gives many matching options and even account for our spelling errors.

The default terminal doesn't have any of those, so here are my favourite programs that can help you find the file or line you need.

## [FZF](https://github.com/junegunn/fzf) + [FD](https://github.com/sharkdp/fd) And [FZF](https://github.com/junegunn/fzf) + [RipGrep](https://github.com/BurntSushi/ripgrep)

![FZF and FD used to search for files](https://dev-to-uploads.s3.amazonaws.com/i/8aranmey3cu04awt4a8p.png)

While fd (file finder) and ripgrep (text searcher) can be used by themselves, I felt the real power came from using them in conjunction with fzf, the fuzzy finder. The combination of these tools allows a filter-based workflow where you can change the search input and the results will dynamically change. My favourite is using it within Neovim.

### FZF in Neovim

![FZF and FD searching for files inside Neovim](https://dev-to-uploads.s3.amazonaws.com/i/0vsmsbu7kbuuw9xcirr6.png)

### Ripgrep in Neovim

![FZF and RipGrep searching for words inside files inside Neovim](https://dev-to-uploads.s3.amazonaws.com/i/0bb6tutp19l59ir2c8p7.png)

# Auto-complete ✅

Another useful tool for everyday use in the command line is auto-complete. Sometimes we just forget what we need to type or forgot the full command.

In these scenarios, [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions) come in handy. This plugin for ZSH by default checks your command history for a command that matches what you're typing and you can bind that to any keyboard short-cut to auto-complete.

![Auto-suggestion for matching last used command](https://dev-to-uploads.s3.amazonaws.com/i/4zzfhsqubqdl0kdl9koy.png)

If you mistype frequently and don't have the self-control to not press enter, here's a program which might tickle your fancy: [thef*ck](https://github.com/nvbn/thefuck)

{% github nvbn/thefuck %}

Thef*ck has an interesting history, originating from Twitter and gone on to amassing 56 thousand plus stars on GitHub. It's essentially an auto-correct for your previous command based on a set of rules for common CLI programs (you can find the full list of supported programs on their README). While I don't personally use this, it's really cool in the sense that it was inspired by the community and reminds me of what open-source is about.

# Coloured Outputs 🌈

This section is about blinging up your terminal. ✨

As you can tell, I already customized the colour scheme and fonts of my current terminal. However, this section is for the other parts of using the terminal which usually lacks coloured outputs such as `cat` or `man`.

For starters, I use [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting), a plugin to highlight commands and strings in your input. To be honest, I think this is why I don't need thef*ck most of the time, if I see the program command highlighted in red it either means I miss-typed it or it doesn't exist on my system.

Next, there is [bat](https://github.com/sharkdp/bat) and one of its add-ons: [batman](https://github.com/eth-p/bat-extras/blob/master/doc/batman.md) which provides git diff support, syntax highlighting and vim-style navigation on top of the base command of `cat` and `man`.

![Colored syntax highlight for printing file to terminal with bat](https://dev-to-uploads.s3.amazonaws.com/i/2xy37xnv2t0n43qzphyu.png)

Finally, a common workflow I found myself doing was running `git status` and having to print the files out to see what I changed. Instead, there is a program known as [forgit](https://github.com/wfxr/forgit) which gives interactive previews to common git operations. Powered by fzf and optionally bat, you can see the actual diffs of files before you add them or when looking at previous commits.

![Using git-add with forgit shows all changed files and previews their diff](https://dev-to-uploads.s3.amazonaws.com/i/sgyldqf5s0dzhysxv0uc.png)

![Forgit has a custom git-log output to navigate between commits and shows the files changed](https://dev-to-uploads.s3.amazonaws.com/i/cmpgfup81v3541xxs7j2.png)

# Tabs + Split Screen 👥

Wrapping up all my terminal programs is [tmux](https://github.com/tmux/tmux), a split-screen, multi-tab, terminal session manager can be manipulated all in one window. It's basically how I can have "one" terminal window open all the time, only alt-tabbing for browser and other GUI apps.

Tmux honestly has too much going for it (including paired programming) that I am not really doing it justice saying it's just for split-screen and tabs. 

For example, it has its own plugin ecosystem, including [tmux-resurrect](https://github.com/tmux-plugins/tmux-resurrect) which can store and restore your session, tabs and splits included, allowing you to pick up your work where you left off!

![An example of using tmux with split-screen and tabs](https://dev-to-uploads.s3.amazonaws.com/i/hdjimew4vznu7flyb8m2.png)

# Wrapping up

So these are my favourite command-line programs which helped me start using the terminal on a day-to-day basis!
I hope you found something interesting and let me know if you have any suggestions in the comments!

Follow me on Twitter [@justinhodev](https://twitter.com/justinhodev) to keep up with my daily code bits!

# Bonus - Dotfile Management

To manage all of these program's configuration can be a massive pain. Instead, because all of the configurations are managed in files (usually preceded by a dot), people have figured out to just store them as a git repository to make it portable and all the other advantages. If you read posts from r/unixporn, you'll find people talking about "dots" or "dotfiles" which is referring to these configuration files. Here's an article I followed to set up my own dotfile repository: [The best way to store your dotfiles: A bare Git repository](https://www.atlassian.com/git/tutorials/dotfiles).

# List of all the programs

- [bat](https://github.com/sharkdp/bat) + [batman](https://github.com/eth-p/bat-extras/blob/master/doc/batman.md)
- [fd](https://github.com/sharkdp/fd)
- [forgit](https://github.com/wfxr/forgit)
- [fzf](https://github.com/junegunn/fzf)
- [ripgrep](https://github.com/BurntSushi/ripgrep)
- [thef*ck](https://github.com/nvbn/thefuck)
- [tmux](https://github.com/tmux/tmux) + [tmux-resurrect](https://github.com/tmux-plugins/tmux-resurrect)
- [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions)
- [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting)