DEV Community

Cover image for CLI Love Inside ❤️
Boris Jamot ✊ /
Boris Jamot ✊ /

Posted on • Updated on • Originally published at mamyn0va.github.io

CLI Love Inside ❤️

fish logo

The command line is a powerful tool, and sadly forsaken by most of us.

The goal of this post is to reconcile some of you with the CLI (Command Line Interface), wether you are a developer or not.

When coding, we find ourselves confronted to this choice: IDE or text editor + CLI?

Modern IDE embed (almost) all the required dev tools: code edition, syntax highlighting, automatic formatting, versioning, compilation, debugging, ... and even runtime environments!

Thus, why choose a simple text editor?

Personally, I made this choice because I'd rather use one tool for each task than one tool for every tasks.

I prefer learn to master each tool, probably more deeply than in an IDE, even if it requires more time, than let the IDE do all the stuff for me and be stuck in case of problem.

It may seem philosophic, but in an IDE, we may sometimes feel constrained and restricted to the proposed features whereas in the CLI, there are plenty of tools, scripts, frameworks for many use cases, many environments, many languages... And the power of Unix allows the interoperability of all these commands.

Of course, if you're under Windows, you'll get into some troubles, because terminal emulators have their limits, but if you're convinced by the CLI, you'll take the plunge by switching to Linux (or maybe just use WSL if you're under Windows 10 :)).

🐟 fish shell

fish shell (or "fish") is a shell oriented to the user interaction, in opposition to Bash which is more scripting-oriented. Thus, it's a good candidate for a daily and interactive usage.

It includes native syntax highlighting for many commands and tools, and autocompletion is, as well native.

Zsh is another credible alternative for this kind of use-cases.

Here is an example of autocompletion with git:

autocompletion

By typing git, then <tab>, fish propose the list of the git commands (checkout, commit, log, ...). By pressing several times <tab>, we can browse the commands until we reach the desired one, and then we just have to click on <enter> to validate (e.g. git checkout), and here fish shows all its magic: it's able to autocomplete the list of the git branches of your repo! Of course, it works with many other tools than git.

Two frameworks allow to enhance the fish features: oh-my-fish and fisherman.

Both of them allow to install themes for the prompt and plugins.

💲 prompt

At first sight, customize his prompt may seem useless, but if the CLI is your main UI, then it becomes mandatory.

It allows to know, among others, for git:

  • on which branch you are
  • if you have commits to push/pull to/from the remote
  • if your index is clean or not, if you have uncommitted or untracked files
  • ...

But also:

  • in which folder you are
  • what is the status of the last command
  • the response time of the last command
  • ...

There are dozens of prompts available, so everyone will be able to choose according to its own preferences. On my side, I selected two of them: bobthefish and neolambda​, that you can install with oh-my-fish : omf install bobthefish.

The first one, highly visual, is based on powerline, a status-line for Vim that includes many patterns and symbols to make it more user-friendly:

bobthefish

The second one is sleeker and with less features, but yet interesting (omf install neolambda):

neolambda

Apart from the prompt, many plugins allow to enhance the user journey, in particular:

  • colorman which adds syntax highlighting for the man pages (omf install colorman)

    colorman

  • grc that adds syntax highlighting for many Unix commands: tail, ping, cat, ps, df, ... (to install it: fisher grc)

    • Example with ping :

    grc_ping

  • pj is a plugin to quickly switch from a project to another, whether it is in your terminal or in your editor (omf install pj)

  • g2 is a wrapper to simplify the git usage.

💄 pimp my terminal!

  • colorls (gem install colorls) -- This ls wrapper really is a must have. It colors stdout; it uses colors intensity to emphasize the modification date of the current directory's files; it makes the file sizes human readable; and, on top of that, it displays the git status of current files/folders!

    colorls

🌈 color my logs!

If you, like me, are a developer or a devops engineer, visualizing logs is thus a recurring task of your job and it becomes mandatory to have the good tools to be productive.

Modern IDE are not suited for logs viewing because they're already overloaded by your source files, and moreover, their huge weight may have a significant impact on your editor's performance. That's what happened for me in Atom as soon as the file's weight exceeded 10Mb.

The solution: use your terminal to tail the logs, while benefiting from available tools to autoformat them, to enable the syntax highlighting and to perform searches.

I use two different tools depending on the log type:

  • ccze for traditional logs (Apache, syslog, php, ...)

    ccze

  • jq for JSON logs

    jq

The benefit of jq is that on top of the JSON syntax highlighting, it automatically formats your logs to facilitate the reading. Thus, if you have one-liner compacted JSON logs for your ELK or any other data analysis stack, it will allow you to unpack your logs and to make them human readable.

jq is a much more powerful tool that would deserve its own article, as it is in fact a JSON parser with its own query description language, in the same way as xpath for XML, but with the simplicity of JSON.

Thus, by tailing each of your log files with tail -f in a dedicated term, and by piping stdout to jq or ccze depending on the type, you'll have a quick access to the information you need, formatted in an elegant way.

👾 other awesome CLI tools

  • ccat : syntax highlighting for cat
  • tig : allows to enhance the ouput of many known git commands (e.g. git log | tig)
  • howdoi : if you're wondering how to format a date in PHP, then just type howdoi format date php
  • htop : to display the list of current processes
  • glances (pip install glances) : a supervision console for your computer (processes, RAM, network, I/O, captors, ...)
  • clog (cargo install clog) : generate CHANGELOGs from your git repo's metadata
  • googler : Google CLI
  • slacker / matterhorn : CLI for (respectively) Slack and Mattermost
  • toot (pip install toot) : CLI for mastodon
  • dockly (npm install -g dockly) : monitor your containers and Docker images from your term
  • wunderline (npm install -g wunderline) : CLI for Wunderlist
  • newman (npm install -g newman) : you want to integrate Postman in your CI/CD pipeline? then newman is made for you!
  • ttyrec/ttygif : allow to create animated GIF from a shell session to be included in a blog post for example (that's what I used for this article)

For each of the commands/tools quoted above, I put in brackets the command to install it. When there isn't, you'll find it in your package manager or easily on Internet.

Most of these commands require a third-party package manager like pip (python), npm (Node.js), gem (Ruby) or cargo (Rust).

Please feel free to share your own CLI by commenting this article!

Top comments (33)

Collapse
 
dreamtigers profile image
Ivan Gonzalez

An alternative to colorman with more options: fish-colored-man.

Btw, can you share your colorscheme? I took the liberty to look for it in your dotfiles repo but couldn't find it. Thanks for the post!

Collapse
 
tbodt profile image
tbodt

I use Neovim's man page viewing functionality for this. $MANPAGER is set to nvim -c 'set ft=man' -.

Collapse
 
dreamtigers profile image
Ivan Gonzalez

I had no idea neovim had such a functionality. Just tried and looks really nice! Nice enough to really make me consider change to it. Thanks!

Collapse
 
biros profile image
Boris Jamot ✊ /

You mean my colorscheme for colorman ? I don't have one.
It's the default colors of the plugin.

Collapse
 
dreamtigers profile image
Ivan Gonzalez

No, I mean the terminal colorscheme, the one you see in, for example, your first gif.

Thread Thread
 
biros profile image
Boris Jamot ✊ /

The terminal in the gif is deepin-terminal with the default colorscheme as it's not customizable with this term.
But I think that what you're asking for is my prompt: neolambda for fish shell.

Thread Thread
 
dreamtigers profile image
Ivan Gonzalez

Thanks a lot!

Collapse
 
katafrakt profile image
Paweł Świątkowski

I've been using ZSH for ages (but recently without oh-my-zsh) but I keep hearing good things about fish. Do you know any decent comparison article? Maybe I'll try it.
My main worry is that quick oneliners would not work there as they used.

Collapse
 
biros profile image
Boris Jamot ✊ /

I used zsh a long time ago when I was a student. It was more user-friendly than bash.

But as I didn't use since more than 15 years, I couldn't say more about the comparison with fish.

Recently I've installed zsh + oh-my-zsh as a POSIX alternative to fish, but it seems that many native features of fish (auto-completion, coloration, ...) have to be configured manually in zsh (through plugins or conf file).

Fish works great out of the box!

Collapse
 
katafrakt profile image
Paweł Świątkowski

Actually I don't like autocompletion. It can reveal far too much when you are for example showing something for larger audience ;) So having that built-in in fish does not count for me as better. But I guess I'll give it another shot some time soon.

Thread Thread
 
biros profile image
Boris Jamot ✊ /

I get your point :)
But the real strength of fish is its ability to auto-complete commands and sub-commands, for example for git (branch , docker stop , ...). It's really powerful !

Collapse
 
tunaxor profile image
Angel Daniel Munoz Gonzalez

Fish is one of my favorite shells! nice to see it mentioned. great collection of resources by the way!

Collapse
 
biros profile image
Boris Jamot ✊ /

Have a look at spacefish, it's crazy fish theme with integrations with many, many languages and tools !

Collapse
 
tunaxor profile image
Angel Daniel Munoz Gonzalez

Will do! thanks

Collapse
 
jmplourde profile image
Jean-Michel Plourde

I try to learn more and more about how to use the CLI. My dev laptop that I use for university assigments runs Linux. I recently switch to zsh with ohmyzsh. I downloaded a popular theme which enables many useful visual cues. It has a solid auto completion and suggestion, besides many other useful features.

Collapse
 
moopet profile image
Ben Sinclair

colorls [...] makes the file sizes human readable

Regular ls does this with the -h flag. In fact, so do a lot of CLI apps, like du and df for example.

Collapse
 
iberianpig profile image
Kohei Yamada

try best tig integration for vim.
github.com/iberianpig/tig-explorer...

Collapse
 
lyfolos profile image
Muhammed H. Alkan • Edited

There are much fish ((f)riendly (i)nteractive (sh)ell) users because of the autocompletion, syntax highlighting etc. But actually fish is much less compatible with other shells. For example, ZSH & Bash are really similar, and they can interop with "many" scripts. You can get similar features using plugins. I do not think there is a reason to use fish.

Collapse
 
biros profile image
Boris Jamot ✊ /

I use both fish and bash. Fish is my term shell and bash is my scripting shell.
I agree with you on fish not being compliant with bash and other bourne shells. That's because fish isn't 100% POSIX compliant.

Collapse
 
richjdsmith profile image
Rich Smith • Edited

I actually just tried the Fish shell this past week and while I absolutely loved how it had somany great tools right out of the box, I ended up having to go back to my old trusty ZSH + Oh-My-ZSH combo.

Because fish isn't fully bash compatible (commands like && don't work.) it broke many plugins I rely on in in VSCode, as well as a few ruby cli tools I use.

I loved it, but the headache and hassle just wasnt worth it.

To get most of the same gains, I just use ZSH + Oh-My-ZSH + Spaceship ZSH.

Everything just works.

Collapse
 
biros profile image
Boris Jamot ✊ /

Yes, spaceship is also great with fish. I love their prompt !

Collapse
 
vishal423 profile image
Vishal Mahajan

could you share the fonts configured on your setup to properly display Unicode characters like \uE74E and \uE749 ?

Collapse
 
jhspetersson profile image
jhspetersson

What do you think about fselect to search files with SQL-like queries?

Collapse
 
biros profile image
Boris Jamot ✊ /

It seems powerful but I don't use so much file search in my every day tasks.