A Fistful of better CLI tools

Command-line interface (CLI) tools have gone through rapid innovation in the last couple years. Ancient stalwarts have been challenged with better newcomers that make life easier, quicker, and better. I feel this Cambrian explosion of new tools may be because of better CLI creation libraries, but think a certain nod has to go to systems programming languages like Go and Rust becoming more popular.

In the vein of my 2021 Software Tools list, and the CLI LIfe Starter post, I’ve run across a whack of great CLI tools in the last couple months which I incorporated into my workflows, and a notable fistful of five. All are available on both OSX (via homebrew) and Linux.

The Fistful

Visidata

While technically a console based app, it’s triggered by the command line and used in-terminal, and I have to give it a shoutout as an amazing swiss army knife for any data scientist, analyst, or engineer dealing with data. It allows you to look at a wide variety of tabular data formats across a wide range of programs, and do lightning fast EDA (exploratory data analysis), quick plots, and data munging and conversion. I have to admit to loving it way more than jupyter noteboks right now and trying to squeeze every last ounce of value out of it. I’ve used it now to take some pretty gnarly data tasks and massively reduce the time to crunch through them (as in, from days to hours.). Huge fan and really can’t believe I hadn’t heard of this tool before this year. Please make sure you check this one out.

Easy to install on just about any platform and trigger from the command line with a simple vd file.ext . It’s the bomb. Run, don’t walk, to https://www.visidata.org. Installable via homebrew with brew install saulpw/vd/visidata as a tap, and any other system with working python via pip3 install visidata (Ubuntu systems also have it as an apt install).

Delta

If you do a lot of coding, especially with other people, understanding changes to your code is important. Visualizing what’s changed can make a big difference but git generally does not make this as easy as it should and diff tools still can leave you wanting. This is where delta comes in. It’s a nicer, colour-coded, and better diff pager for you to look at files and (especially) your git-controlled code. Use it to replace the default command on your git pager and you get some sweet looking and much more grokable output to comparing files. It is super nice and I’m a big fan already. Install on homebrew via brew install git-delta or on Linux via package manager or a working Rust system via cargo install git-delta. The code is at https://github.com/dandavison/delta.

You need to do a tiny bit of config on this one in your ~/.gitconfig file and set it up with a delta section and change your pager somewhat like this:

[pager]
    diff = delta
    log = delta
    reflog = delta
    show = delta

[interactive]
    diffFilter = delta --color-only --features=interactive

[delta]
    features = decorations

[delta "interactive"]
    keep-plus-minus-markers = false

[delta "decorations"]
    commit-decoration-style = blue ol
    commit-style = raw
    file-style = omit
    hunk-header-decoration-style = blue box
    hunk-header-file-style = red
    hunk-header-line-number-style = "#067a00"
    hunk-header-style = file line-number syntax

After that, your git diff and other git commands are transformed.

zoxide

A rust-reengineered and faster z, which in itself is a better cd, zoxide allows you to move around your directories faster and with less thought about your hierarchical structure. It saves a surprising number of keystrokes for you by not having to remember the precise path for some of your deep directories. It’s heuristics figure out what you want probably better than your memory and have to admit it’s been very nice to type z something and jump. It learns over time and gets better and better, and the database is easily greppable as well, so a nice addition to your toolset if you are already someone who uses the command line a lot, or trying to get better at it, but find the typing of long pathnames tedious.

https://github.com/ajeetdsouza/zoxide

dust

Dust is a better du and very handy for seeing the size of your directories with a nice graph of which is taking up what. It sports saner defaults and switches (as well as the graphical output) for things you actually want to know about your filesystem. I like it since it usually is my first indication something is sucking up a ridiculous amount of data on my SSD (read: data), and that I need to do some spring cleaning or offload some stuff to GCS or S3 and backups. It does do a reverse tree of how your disk is being used which some people might find counterintuitive at first, but the bar graphs it gives make it a logical design choice and quickly adjust to it as UI. Very Handy.

https://github.com/bootandy/dust

fd

Much like dust, fd is a better find which avoids having to type switches for what are for most people’s defaults (so, not having to put -name or iname in every search). It’s also very fast, which is nice, and gets out the way doing what you want. Much like dust, it’s written in rust which is definitely making me lean more towards the language over Golang.

Some CLI tips

Alias new commands to their old counterparts

If you’re an old timer like me, it’s a good idea to alias older commands to new new ones. You’ll surprise yourself by how many times after you install zoxide you still type cd whatever simply because you’ve been doing iot that way all along and your brain and muscle memory simply get you where you want to go like starting to walk somewhere.

tmux is your best friend

If you’re not using tmux, you do not know what you’re missing. While some people may prefer having multiple tabbed terminals, tmux also does things like make sure processes don’t die if your interface to them does, making things recoverable (and for more advanced users, entire sessions). This also allows me to switch over to my terminal and easily keystroke between different panes as applications which becomes a very intuitive way of interacting with your CLI apps and keeps everything nice and ordered. I also use tmuxp to have a default configuration loaded every time I start up the terminal or reattach to my session, with the handy startup command tmux attach -t C || tmuxp load ~/.tmuxp/c.yaml. tmux starts off super ugly without customization, but there are easy ways to style it and configure it to your needs now.

For example, I use a nice, dark nord-theme I picked up and have the following config with some powerline fonts to make a really nice experience in tmux.

set -g default-shell $SHELL

bind C-c copy-mode
bind b choose-buffer
bind s choose-session

# quick pane cycling
unbind ^b
bind ^b select-pane -t :.+

# shorten command delay
set -sg escape-time 1

# Use C-b q to kill a pane
bind q kill-pane

# Start window and pane counts from 1
set -g base-index 1
set -g pane-base-index 1

# Do not automatically rename panes
set-option -g allow-rename off

# Renumber panes if close a middle pane
set-option -g renumber-windows on

# Use C-b n to rename a pane
bind n command-prompt "rename-window '%%'"

# Use r to quickly reload tmux settings
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded tmux config."

# improve colors
set -g default-terminal "screen-256color"

# soften status bar color from harsh green to light gray
set -g status-bg colour23
set -g status-fg white

#Set the left and right status
set -g status-left '#[bg=colour7]#[fg=colour0] #S #[bg=colour23]#[fg=colour7] '
set -g status-right '#[bg=colour7]#[fg=colour0] %b %d %H:%M '

set -g window-status-current-format "#[fg=colour23]#[bg=colour7]#[fg=colour0]#[bg=colour7] #I #[fg=colour0] #W #[fg=colour7]#[bg=colour23]"
set -g window-status-format "#[fg=colour7]#[bg=colour23]#I#[fg=colour7]  #W"

set-option -g status-interval 1

# Use vim keybindings in copy mode
setw -g mode-keys vi

# New window with default path set to last path
bind - split-window -v -c "#{pane_current_path}"
bind \\ split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

run-shell "~/.tmux/themes/nord-tmux/nord.tmux"

Tenzing tmux setup

Hotkey to your fullscreen

Another thing is to use a hotkey to get direct to terminal.

This is probably one of my most used keystrokes after using Alfred or rofi to launch things. On Linux, use something like guake which rolls down and on OSX I keep kitty fullscreened and then simply use ctrl-⇒ to shift over to the terminal whenever I need it. That and a tmux pane change usually have me into whatever I need to do right away and then out of it again before a similar gui based program could even start. Also, check out a tiling window manager like i3 or sway if you are a serious terminal nerd or use the CLI more than anything else.

Makes it painless with a CTRL → hotkey to move to fullscreen terminal (unless I’m doing something special, kitty is the only thing fullscreened in the OSX sense). On linux, I like i3 or sway as a window manager for this similar full screen app approach to switching though I tend to keep every app fullscreened and then use CTRL-Number to switch between the different screens.

fish is your friend

While shell is a highly personal choice amongst CLI users, if you haven’t already, I highly recommend checking out the excellent fish shell. I honestly do not understand why more people don’t use it, since it makes everything better on the command line. Sure, people like zsh cuz posix compliance but fish makes actual usage on the command line better, makes scripting non-arcane, and its autocompletion, history, as you type, syntax highlighting just make life better. Try it. Low learning curve and once you’ve got it, you’ll wonder how you did without it (and going back to bash ends up being irksome.)

Fin

I hope you discovered something in this post that makes your life in terminal a little better. If you’ve missed other tools I’ve recommneded on the command line, I’d also mention newsboat for feeds, gopass for password management, and (shameless plug) harsh for habit tracking as well as things which I use daily to make life better and faster than slower, bloated guis.

Let me know what you think about the post on twitter @awws or via email hola@wakatara.com. Love to hear feedback about other CLI tools that might have made your life better or work well in your workflows. Let me know what may have worked for you.