A blog by Darren Burns
Darren
Burns
Hey 👋 I'm Darren.
I'm a software engineer based in Edinburgh, Scotland

Posts
Twitter
GitHub

Power Up Your Command Line II

January 4, 2019
productivity | command line | tips

This is part II of the series “Power Up Your Command Line”, which showcases excellent non-standard tools that will make using the command line easier and more enjoyable.

peco, interactively filter anything

Pipe the output of any command into peco (GitHub), and you’ll be able to interactively filter it to find the information you need. Think of it like an interactive form of grep, where the real-time updating of results as you type allows for a more exploratory search process.

peco-processes

You can move up and down through the search results, and select them with enter. When you press enter, the command outputs the result.

Installing peco

  • On macOS with Homebrew: brew install peco

hexyl, a hex viewer

If you want to examine a binary file, you typically do so by looking at the hexadecimal representation of the file. hexyl (GitHub) is a command line tool for doing just that.

hexyl

The view is split into three columns:

  1. An offset column, which tells you how many bytes into the file you are.
  2. A hex column (which itself has a divider down the middle - not visible in the example gifs), which contains the hexadecimal representation of the file.
  3. A representation column (also split in two, and not shown in the example gifs), which attempts to show the file as text.

Each byte in hexyl is colour-coded depending on the type of byte it is (NULL, ASCII, non-ASCII, etc.) which really helps with readability.

Bonus tip: If viewing binary files or large text files, the output will often be too large for your screen, so you can pipe the output from hexyl into bat or less to give you the ability to paginate through it! You’ll need to use the --raw-control-chars/-r flag for the output to be coloured correctly if you use less:

hexyl-less

hexyl is written in Rust, and is developed by David Peter who also wrote bat, fd, and hyperfine, all of which I mentioned in part one of this series.

Installing hexyl

Installing hexyl requires a few steps on macOS:

  1. Download the binary from GitHub: curl -L -o hexyl.tar.gz https://github.com/sharkdp/hexyl/releases/download/v0.3.0/hexyl-v0.3.0-x86_64-apple-darwin.tar.gz
  2. Extract the tarball: tar -xf hexyl.tar.gz
  3. Add it to your PATH: mv hexyl-v0.3.0-x86_64-apple-darwin/hexyl /usr/local/bin
  4. Make executable: chmod +x /usr/local/bin/hexyl

pomo, a pomodoro timer

The pomodoro technique is a great way to boost your productivity. If you haven’t heard of it before, it works like this:

  1. For 25 minutes, you work and allow for no distractions.
  2. For 5 minutes, you relax and do whatever you want (as long as it isn’t work 😁).
  3. Repeat the steps above 4 times (you can adjust this number to suit yourself), then rest for 15 minutes

If you follow the plan above, the theory is that you’ll get considerably more done in considerably less time. It might not work for everyone, but I can personally vouch for it’s effectiveness!

pomo

pomo (GitHub) is a simple CLI tool to help you manage your time through the pomodoro technique.

Installing pomo

There’s a few steps to follow to install this one (on macOS):

  1. Download the binary from GitHub: curl -L -o pomo https://github.com/kevinschoon/pomo/releases/download/0.6.0/pomo-0.6.0-darwin-amd64
  2. Grant permissions: chmod +x pomo
  3. Put it on your PATH so you can use it from anywhere: mv pomo /usr/local/bin
  4. Initialise the database: pomo init

ncdu, analyse and free disk space

If you’ve got a lot of projects on your computer and haven’t cleaned up your disk recently, you’ll almost certainly find a rogue folder that is hogging disk space (I’ve found some node_modules folders in older projects to be particularly susceptible). [ncdu](https://dev.yorhel.nl/ncdu) is my favourite tool for fixing this. In fact, in the process of creating the demonstration for ncdu below, I freed up over 10GiB of disk space!

ncdu

To use it, run ncdu. It’ll scan all subdirectories from the directory you ran it in, so if you run it in your home directory, it might take some time.

You can use its ncurses interface to browse through your filesystem using the arrow keys, or the navigation keys from vim, if that’s your thing.

Installing ncdu

  • On macOS with Homebrew: brew install ncdu

HTTPie, a modern replacement for curl

HTTPie (http) is a simpler (meaning I don’t have to Google it every time, unlike with curl), feature-rich and beautiful alternative to curl, which will let you call APIs over HTTP from the command line. It’s the most popular utility I’ve reviewed so far, and has exceptional documentation.

httpie

The output from the http command is what really sets it apart from cURL. JSON responses are pretty printed with syntax highlighting, making them far more readable. If you'd rather use a graphical UI for interacting with APIs, you might like Insomnia, Postman or Paw (Paw requires a license and is macOS only).

Installing HTTPie

  • On macOS with Homebrew: brew install httpie

Conclusion

Thanks for reading! There are a couple more tools I’d like to mention in the next post in the series, but if you have any suggestions let me know! If you’re interested in more content like this, follow me on Twitter.


Copyright © 2022 Darren Burns