By Darren Burns

Translation: weakish @ LeanCloud

Link to the original article: url.leanapp.cn/darren

This is the first in a series of articles showing some of the great non-standard command-line tools I’ve discovered in recent years. If you use the command line, chances are that at least one of these tools will make your life easier.

zjump

Modern browser address bars can be smart fuzzy search, saving a lot of time. Want to check Twitter? Just type “TW” in the address box and press Enter.

By contrast, using a CD to access the file system from the command line is archaic. Thankfully, Z brings browser-style navigation to the command line.

After a short learning period, Z lets you jump from anywhere to a directory by typing a substring of the name of the destination directory. Which directory z will jump to depends on the string arguments you provide, how often you access the directory, and the last time you accessed the directory. This is called frecency.

Z not only increases speed, but also reduces cognitive burden. With a CD, you need to remember exactly where the target directory is in the directory tree and calculate the path to the directory. With z, you just need to know the name of the directory.

Z has also been ported to other shells (such as Fish and ZSH). A similar project is AutoJump.

The installationz
  • Use on macOSHomebrewThe installationbashVersion:brew install z
  • Use on macOSFisherThe installationfishVersion:fisher add jethrokuan/z

fzfFast blur finder

After installing FZF, press Ctrl + T anywhere on the command line to open an interactive fuzzy search interface that recursively searches for files in the current directory. After entering the search term, press the up and down keys to select the result and return to the car screen:

In the example above, I type bat (or any other command, such as less, CD, etc.) and then press Ctrl + T. Then type five, press Enter, and insert the path SRC/fiv. rs to where the cursor is, instead of having to type SRC, then TAB, then fi, then TAB — which can be cumbersome if the path is long or hard to remember.

The installationfzf
  • MacOS (Homebrew) :brew install fzf
  • fishBinding:fisher add jethrokuan/fzf

batFile with syntax highlighting

Bat helps you quickly view files, with syntax highlighting. Bat is a seamless replacement for CAT.

If the output is too large (as shown in the example above), BAT passes the output to LESS, automatically paging.

The installationbat
  • MacOS (Homebrew) :brew install bat

benchCode performance testing

Bench is an extremely useful tool for testing code performance. It’s written in Haskell, and in that sense, it’s the coolest thing about this article. Any command that can be run in the terminal can be passed to it (quoted), and bench will run the command repeatedly, measuring the execution time. When the test is complete, bench will output useful statistics.

Bench is a more powerful measure of code execution time than the built-in time command.

A similar tool is Hyperfine, written in Rust.

The installationbench
  • MacOS (Homebrew) :brew install bench

asciinemaandsvg-termRecording terminal for SVG animation

The terminal clip in this article is actually an SVG animation! Using SVG instead of a video file has several advantages:

  • Any zoom 🔍
  • You can embed the Markdown file like any other image 😱
  • Small file 🧐
  • SVG animation is way cooler than video 🔥

I use Asciinema to record the terminal. Type Asciinema rec to start recording. When you’re done, press Ctrl+D and choose to save locally or upload asciinema.org

Svg-term can generate SVG animations from asciinema recorded files. If you upload the recorded file to Asciinema, you need to access the Asciinema link to make it public.

To convert the recording file to an SVG animation, you need to provide the recording ID (you can find the ID in the URL after exposing the Asciinema page), the output file name, and a few other optional parameters. For example, I use the following command to convert the terminal recording (asciinema.org/a/219486) in the above example to an SVG file:

svg-term --cast=219486 --out ~/somewhere/out.svg --padding 18 --height 8 --width 80
Copy the code

Or, if you don’t want to upload the recorded file to Asciinema, you can convert the local recorded file directly using SVG-term (thanks to Mario Nebl, author of SVG-term-CLI for pointing this out) :

asciinema rec cast.json
cat cast.json | svg-term-cli
Copy the code
The installationasciinemasvg-term
  • Install on macOSasciinema:brew install asciinema
  • Install on macOSsvg-term:npm install -g svg-term-cli

wrkTest HTTP API performance

WRK is a handy little tool for testing API performance. To demonstrate its use, I ran a minimal Python HTTP API server locally on port 8001, which has only one endpoint (/hello). Test its performance with WRK (200 connections with 12 threads in 5 seconds) :

Adjusting the number of threads, number of connections, and duration can test the performance of the API under different loads. It is not a replacement for performance testing tools like Locust and JMeter, but it is lightweight and sufficient for many scenarios.

Unfortunately, the WRk-based command line interface is cumbersome to issue a POST request: you need to write a small script in Lua and pass it as an argument to the command (see the documentation).

The installationwrk

  • MacOS (Homebrew) :brew install wrk

exaalternativels

Exa is a modern alternative to LS, with color output that is much easier to read and offers more options to control how the output is rendered.

The –git-ignore argument ignores the file according to.gitignore, and the -t argument lists the directory in a tree structure.

The installationexa

  • MacOS (Homebrew) :brew install exa

fdFind files and directories

The find command is usually used to find files or directories based on regular expressions. Fd is a substitute for find written in Rust. Use reasonable defaults, provide a more convenient interface, and are faster.

Fd follows the.gitignore file and also supports parallel command execution. Parallel command execution commands can be executed (in parallel) on each file and directory returned by the search. An example in a fd document is to find all.jpg files and convert them in parallel to.png files (using the convert command) :

fd -e jpg -x convert {} {.}.png
Copy the code
The installationfd
  • MacOS (Homebrew) :brew install fd

rg(ripgrep) Finds the string in the file

Rg is an alternative to grep, which is much faster than grep.

Rg is written in Rust, and the VS Code editor’s search capabilities are actually implemented by calling RG. In performance measurements, RG consistently outperforms similar tools.

Install ripgrep
  • MacOS (Homebrew) :brew install ripgrep

conclusion

I hope you found a useful tool in this article! I intend this article to be an up-to-date repository of useful alternative command-line tools, so I’ll probably update this article from time to time.

If you’re interested in more content like this, please follow me on Twitter.