My arsenal of CLI tools

6 minute read for ~1400 words

Background

I’ve been seriously using Linux for (just) over 2 years. The thing I take pride in is my pragmatic, albeit flashy at times, CLI setup. This article could be a dotfiles repository but I keep it private because I think it’s too risky.

Let’s look into some tools I use daily.

My terminal setup
  • kitty, the best terminal emulator

    • fast
    • panes, tabs, windows
    • a plethora of configurable keybindings
    • really good plugin model and ecosystem
    • remote control allows amazing interop between other software
    • fantastic scroll-back buffer manipulation capabilities
    • little features such as following links via keyboard, selecting text, etc.
  • zsh

Tools of trade

There are a lot of awesome articles and resources that list out amazing CLI tools.

I’m going to be talking about the tools which have stuck with me and I actually use, hence the use of word “My” in the title.

Let’s go over the tools categorically as Julia Evans does in her CLI list.

Replacement for standard tools

  • batcat

    The cat command with other niceties such as syntax highlighting, paging, line numbers, etc.

  • fd

    A faster, user-friendlier find

  • ripgrep

    A faster, user-friendlier grep1

  • dua

    A tool to check how much space on disk, a particular directory/file is occupying and to delete it in a nicer way. Can be an alternative to du and rm.

  • btop

    Powerful and pretty resource monitoring tool, alternative to top. One of my favorite tools here because of the convenient keyboard bindings.

  • procs

    Prettier ps with extra features. I mainly use it as it displays the PID of a server associated with its TCP port. Very handy to clear dangling processes. Only if this was possible in btop.

  • tldr

    Provides short usage examples for common commands. I don’t dislike man pages but they can be really hard to sift through when you are just looking for a basic example.

Just as a little game, guess what command I’ve tldred the most.2

  • micro

    I need a quick, in-terminal editor a lot of times. Even though I use a lot of CLI tools, I’m not acquainted with vi3 or nano. I prefer the “vanilla” editor keys such as arrow keys for moving among words, Ctrl+X/Ctrl+V, Shift+Arrow for selecting, etc. micro is a perfect tool to me for this situation.

New(ish) inventions

  • zoxide

    A directory autojumper based on frecency. zoxide isn’t a new invention in itself but autojumping tools are. If there’s a tool that I’d take with me to my grave, it would be this. I’ve used it more than I can admit.

  • dragon

    Render a GUI list of files from the CLI to drag somewhere. I generally use this to drag files into my browser like upload boxes, email attachments, etc.

  • eget

    If it’s not obvious by now, I love tools. And all of these CLI tools are hosted on GitHub. eget makes it way easier to download releases and extract them into the one of many bin directories Linux has.

  • entr

    A small filesystem watcher. I don’t use this much as I rely on language specific tooling like air for Golang.

  • chezmoi

    Powerful and easy dotfile manager using Git. I have auto-commit/push turned on and regularly do a chezmoi re-add so I’m not scared of losing my configuration at all.

  • viu

    View images in the terminal. Good for previewing files. When I came across this for the first time, it was sorcery to me. Thanks again, Kitty.

  • nnn

    I haven’t tried a lot of CLI file managers because nnn was the first I tried and my mind just said, yep, I’m not going to move off this.

    Along with the awesome keyboard navigation features, the real deal for me was the plugin system which leveraged my already existing tools. It has a preview plugin which ties with viu, a dragon plugin, a KDE Connect plugin to send files to otehr devices, and a zoxide plugin for autojumping.

JSON/YAML/CSV things

  • dasel

    Super convenient conversion among JSON <-> CSV <-> YAML <-> etc. It’s simple and just converts one format to the other. No fancy transformation stuff.

  • jq

    Super powerful JSON toolkit. jq has a relatively steeper learning curve but I’ve been successfully using it with the help of this cheat sheet and occasional trips to the manual.

  • tv

    It’s a CLI CSV viewer. It’s just better than cating CSVs.

Miscellaneous

These don’t really fall under CLI tools, but are CLI extensions or alternatives to other tools.

  • kdeconnect-cli

    I do a lot of file sharing from and to my phone and KDE Connect works flawlessly.

  • spotify-tui and spotifyd

    Call me crazy but trying Spotify in the terminal was one of the reason I pay for Spotify Premium. Worth it.

Useful aliases

These are some useful aliases built on top of above mentioned tools and standard tools that I frequently use:

  • share:

    A Wrapper around KDE Connect that shares screenshots and files

    share() {
      # `share ss`: Shares latest screenshots/image in the clipboard
      if [[ $1 = "ss" ]]; then 
          img_path=/tmp/$(date +"%d_%m_%y-%H_%M_%m").png
          xclip -selection clipboard -t image/png -o >$img_path
          kdeconnect-cli -n sam --share $img_path
    
      # `share /some/path/file.ext`: Shares files
      else
          kdeconnect-cli -n sam --share $1
      fi
    }
    
  • j2c & c2j

    Convert JSON <-> CSV

    j2c() {
      dasel -r json -w csv
    }
    c2j() {
        dasel -r csv -w json
    }
    
  • dmv/dcp

    I constantly face this situation where I have to mv or cp the latest downloaded file to the folder I’m currently at. This alias was my solution

    dmv() {
      __fname="$(ls -t ~/Downloads | head -n 1)"
      __fpath="$HOME/Downloads/"$__fname""
      mv "$__fpath" \.
    }
    dcp() {
        __fname="$(ls -t ~/Downloads | head -n 1)"
        __fpath="$HOME/Downloads/"$__fname""
        cp -a "$__fpath" \.
    }
    
  • str

    Shortcut to generate random strings. Useful for placeholders, development secret keys, etc.

    str() {
      # Usage: `str 8`
      node -p "crypto.randomBytes($1/2).toString('hex');"
    }
    
  • pskill

    Usage: pskill foo. Slightly dangerous alias that kills all processes matching foo.

    pskill() {
      procs $1 --no-header --only pid | xargs kill -15
    }
    
  • m

    Quick maths! Stole it from this HN comment.

    m() {
      python3 -c "from math import *; print($*)"
    }
    

A hyperbolic rant

I love the CLI. Dare I say, it’s the easiest way of getting things done if you know what you’re doing. And of course, that’s a gigantic “if”.

Compare the following 2 conversations:

Bob: Hey, how do I [do this] using [that] such that [something] becomes [something else] and [that particular thing] is not messed up?

Alice: Ah, give me a minute!

[10 minutes later]

Alice: Here, yank this into the terminal and run it.

$ dothis --use=that \
  --from=something \
  --to=something-else \
  --ignore=that-particular-thing

Bob: Nice.

vs.

Alice: Hey, how do I connect to Wi-Fi?

Bob: There should be a Wi-Fi icon thingy in the bottom-right corner.

Alice: There isn’t.

Bob: There should be.

Alice: There isn’t.

Bob: You are using Winwoes 10, right?

Alice: Yes.

Bob: Okay, go to Control Panel.

Alice: How?

Bob: Go to start and search for it

Alice: Okay, I’m here.

Bob: Now, on your top-left side, you’ll see a blue button which says View. Change the view to category, then you’ll see the Network and connectivity settings, go there. You’ll see Networks tab. Go there. You’ll see wireless networks, click that. Now you should see the Wi-Fi.

Alice: I don’t.

Bob: FFFUUUUUUUUU

Now, this is obviously a hyperbole. And I’m not bashing GUIs (geddit?). I’m not saying CLIs should be the norm. I’m merely saying that learning how to use the CLI properly will make you a power user.

Conclusion

  • Thanks to the creators of these incredible tools mentioned above.
  • Thanks to Rust and Go for modernizing CLIs and keeping them alive. If I’ve to take a guess, making CLIs in these new, shiny languages made them appealing to new developers.

  1. I started using ripgrep before learning enough grep so I can’t really tell how better it is in terms of UX. The benchmarks speak for the performance. ↩︎

  2. You are correct ↩︎

  3. I’m gonna learn vi some day. ↩︎


Shared on Hackernews