Abhijit Hota
My arsenal of CLI tools
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
ohmyzsh
- powerlevel10k
- Bunch of plugins
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
-
The
cat
command with other niceties such as syntax highlighting, paging, line numbers, etc. -
A faster, user-friendlier
find
-
A faster, user-friendlier
grep
1 -
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
andrm
. -
Powerful and pretty resource monitoring tool, alternative to
top
. One of my favorite tools here because of the convenient keyboard bindings. -
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 inbtop
. -
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 tldr
ed the most.2
-
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
vi
3 ornano
. 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
-
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. -
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.
-
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 manybin
directories Linux has. -
A small filesystem watcher. I don’t use this much as I rely on language specific tooling like
air
for Golang. -
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. -
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.
-
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
, adragon
plugin, a KDE Connect plugin to send files to otehr devices, and azoxide
plugin for autojumping.
JSON/YAML/CSV things
-
Super convenient conversion among JSON <-> CSV <-> YAML <-> etc. It’s simple and just converts one format to the other. No fancy transformation stuff.
-
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. -
It’s a CLI CSV viewer. It’s just better than
cat
ing CSVs.
Miscellaneous
These don’t really fall under CLI tools, but are CLI extensions or alternatives to other tools.
-
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
orcp
the latest downloaded file to the folder I’m currently at. This alias was my solutiondmv() { __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 matchingfoo
.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.