Shell configuration and command line tools

In this chapter I would like to introduce you to two powerful shell extensions:

Starship is a fast tool that you can use with any shell.

Pipes (|)

Git never uses less if you redirect the output to another programme, for example

$ git log --oneline | grep Jupyter

However, you can pass the output back to less:

$ git log --oneline | grep Jupyter | less

delta

delta is a smart diff display, see for example:

Schicke Diff-Anzeige mit delta

Installation

The .deb files can be found on the Release page.

$ brew install git-delta
> choco install delta

Configuration

An example configuration can be found in Git config file:

[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true  # use n and N to move between diff sections

[merge]
    conflictstyle = zdiff3

However, delta not only extends the display of git diff, but also that of git add --patch, git log --patch, git blame, git rebase merge conflicts and git show. In addition, delta can also display side-by-side diffs, for example:

Side-by-Side-Diffs mit delta

You can also configure this globally with:

$ git config --global delta.side-by-side true

ripgrep

Installation

You can install ripgrep with a binary .deb file, which is included in every ripgrep release.

$ curl -LO https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep_14.1.0-1_amd64.deb
$ sudo dpkg -i ripgrep_14.1.0-1_amd64.deb
$ brew install ripgrep
> choco install ripgrep

Examples

Note

The package is called ripgrep, but the command is rg.

$ rg PATTERN

searches for regexes, whereby you should often use inverted commas to prevent the shell from interpreting special characters.

$ rg PATTERN FILENAMES

restricts the search to certain files by naming them according to the pattern.

$ rg -g|--glob PATTERN

filters files according to so-called globbing patterns.

$ rg -t SUFFIX PATTERN

searches for files with certain file extensions.

With rg --type-list you get all possible file extensions.

$ rg -i|--ignore-case PATTERN

ignores upper and lower case.

$ rg --hyperlink-format EDITOR PATTERN

creates file paths as terminal hyperlinks that can be opened by holding down the Strg or key. Possible editors can be obtained with man rg.

$ rg --no-ignore PATTERN, $ rg -.|--hidden -.PATTERN, $ rg --binary PATTERN or $ rg -u |--unrestricted PATTERN

also displays results in files that are usually filtered out by .gitignore statements, by . hidden files or binary files.

Tip

$ rg -.|--hidden -.PATTERN also displays results in the .git directory. To exclude this directory from the search, you can exclude this directory with the -g|--glob option and a !, for example rg -. -g '!.git' PATTERN.

Configuration

You can create a configuration file for ripgrep in ~/.config/ripgreprc, for example:

--hyperlink-format
default
--smart-case
--hidden
--glob
!.git

You can then define the RIPGREP_CONFIG_PATH environment variable with

$ export RIPGREP_CONFIG_PATH=~/.config/ripgreprc