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:
Installation¶
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:
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
See also
Examples¶
Note
The package is called ripgrep, but the command is rg.
$ rg PATTERNsearches for regexes, whereby you should often use inverted commas to prevent the shell from interpreting special characters.
$ rg PATTERN FILENAMESrestricts the search to certain files by naming them according to the pattern.
$ rg -g|--glob PATTERNfilters files according to so-called globbing patterns.
$ rg -t SUFFIX PATTERNsearches for files with certain file extensions.
With
rg --type-listyou get all possible file extensions.$ rg -i|--ignore-case PATTERNignores upper and lower case.
$ rg --hyperlink-format EDITOR PATTERNcreates 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 PATTERNor$ rg -u |--unrestricted PATTERNalso displays results in files that are usually filtered out by
.gitignorestatements, by.hidden files or binary files.Tip
$ rg -.|--hidden -.PATTERNalso displays results in the.gitdirectory. To exclude this directory from the search, you can exclude this directory with the-g|--globoption and a!, for examplerg -. -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