A few of our favourite tools

Marie-Hélène Burle & Alex Razoumov
training@westgrid.ca
March 16, 2022

lazygit

(Terminal UI for Git written in Go)

lazygit brings the ease of use of a visual Git tool to the command line

Unlike slow, buggy, & limited Git GUIs, it is nimble, portable, & super fast

In the following demo, as an additional visual goody, I will introduce diff-so-fancy to display the outputs of git diff

Bat

(“A cat clone with wings”)

bat is a great tool to display the content of files in your terminal

The standard Unix utility for this task is cat, but bat adds a lot to it

Syntax highlighting…

…in a huge number of languages. See the impressive list with:

bat -L
cat /home/marie/parvus/prog/slides/static/files/tools/julia.jl

Syntax highlighting…

…in a huge number of languages. See the impressive list with:

bat -L
bat /home/marie/parvus/prog/slides/static/files/tools/julia.jl

Smart behaviour with pager

Uses less by default with options -RFX

Very convenient: quits the pager automatically if the entire content fits on one script

Integration with Git

Git diff

bat -d

Man page syntax highlighting

Even colourizes your man pages if you set the MANPAGER environment variable (e.g. in your .bashrc):

export MANPAGER="sh -c 'col -bx | bat -l man -p'"

Useful flags

bat -n              # Remove frame
bat -p              # Remove frame & line numbers

I personally have an alias for this: alias rat='bat -p'

bat -pp             # Remove frame & line numbers & don't use pager
bat -f              # Keep colour highlighting after piping

I made this the default behaviour for bat with the alias: alias bat='bat -f'

Fully customizable

The defaults are great, but if they don’t suit you, you can change tab width, language, wrapping method…

bat --config-file             # Location of config file (if it exists)
bat --generate-config-file    # Create config file template
bat --list-themes             # List themes with examples

ripgrep

(A fast recursive alternative to grep)

ripgrep provides the utility rg:
an alternative to grep very fast for recursive searches

Syntax

The syntax is similar to that of grep

Because, by default, rg is recursive (grep isn’t) & ignores some files, rg -uuu is equivalent to grep -r

Benchmarks

I will compare grep and rg to recursively search the word “Unix” in my directory “~/parvus/prog/tcl”

grep -r Unix ~/parvus/prog/tcl
rg Unix ~/parvus/prog/tcl

I will do a cold test (clearing my computer cache before each run) using hyperfine

hyperfine -i --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' \
		  'grep -r Unix ~/parvus/prog/tcl' \
		  'rg Unix ~/parvus/prog/tcl'

Results

Benchmark 1: grep -r Unix ~/parvus/prog/tcl
Time (mean ± σ):      1.027 s ±  0.016 s  [User: 0.269 s, System: 0.222 s]
Range (min … max):    1.007 s …  1.052 s  10 runs

Benchmark 2: rg Unix ~/parvus/prog/tcl
Time (mean ± σ):      76.0 ms ±   5.6 ms  [User: 21.5 ms, System: 29.6 ms]
Range (min … max):    63.0 ms …  82.4 ms  10 runs

Summary
'rg Unix ~/parvus/prog/tcl' ran
13.51 ± 1.02 times faster than 'grep -r Unix ~/parvus/prog/tcl'

What makes rg fast?

Uses parallelism

Uses Rust regex engine with finite automata, SIMD, & aggressive literal optimizations (regular expressions follow the syntax of grep -E; see this & this for details)

By default, ignores files in .gitignore & similar, hidden files/directories, & binary files (this behaviour can be changed with flags)

fd

(Fast & friendly alternative to find)

fd has an intuitive syntax & is super fast

pass

(A command line password manager for Unix systems)

pass is a command line password manager using GnuPG for encryption

pass has a Git integration & several extensions

pass is easy to use in scripts or combined with other utilities

Main pass commands

pass init your-gpg-id                    # Initialize password store
pass insert somesite.ca/your@email       # Enter password for a site
pass somesite.ca/your@email              # Print password
pass -c somesite.ca/your@email           # Copy password to clipboard
pass edit somesite.ca/your@email         # Edit password
pass generate othersite.com/userid 12    # Generate password of size 12
pass generate -c othersite.com/userid 12 # Same, but copy to clipboard
pass generate -n othersite.com/userid 12 # Same, without special characters
pass rm othersite.com/userid             # Delete password
pass                                     # Print content of password store

TRAMP

(“A remote file editing package for Emacs”)

The TRAMP (Transparent Remote Access, Multiple Protocol) Emacs package allows to edit remote files as if they were local

You can thus use your init file & usual packages to write files on a remote machine or for another user (e.g. root)

You can also use the Emacs GUI to edit remote files without efficiency loss

It is a convenient alternative to using Emacs on a remote machine after you have sshed into it or to using sudo emacs to edit root files

Using TRAMP from within Emacs

Remote file

C-x C-f /ssh:user@server:/home/user/path/to/file RET

Root

C-x C-f /sudo::/path/to/file RET

Using TRAMP from the command line

Remote file

emacs /ssh:user@server:/home/user/path/to/file

Root

emacs /sudo::/path/to/file

Helm

(“Incremental completion & selection narrowing framework”)

The Helm package provides an incremental completion & narrowing selection API for search applications in Emacs

Virtually every Emacs search application has built-in integration with Helm

Grep equivalent

Navigate mark ring

Navigate kill ring

Navigate open & recent files

Navigate recent files

Find file

Locate

Search objects in working environment

Search in Git repo

Manage major/minor modes

Search help files

Search key bindings

Search in emails

Select colour

Select emoji

Questions?