Debian: fzf/ripgrep/bat

Die folgende Kurzanleitung zeigt Umsetzungen für Debian!

  • einfache Integration Fuzzy Finder fzf und Ripgrep rg

  • Aufruf für gestylte Ausgaben mit Tool batcat (sonst bat).

Kurzanleitung:

  1. Falls noch nicht geschehen:

    apt install fzf ripgrep bat

  2. Eine beispielhafte Konfiguration in ~/.bashrc integrieren/einkopieren

    # FZF - RIPGREP - bat/batcat (on Debian Distro)
    # =============================================================================
    # https://github.com/junegunn/fzf
    # fzf environment:
    . /usr/share/doc/fzf/examples/key-bindings.bash
    . /usr/share/doc/fzf/examples/completion.bash
    #
    # fzf exports:
    export FZF_DEFAULT_OPTS='--height 40% --border --preview="batcat --style numbers,changes --color=always {}"'
    # use ripgrep with FZF instead of find
    # export FZF_DEFAULT_COMMAND='find ~ -name .git -prune -o -name tmp -prune -o -type f,d -print'
    export FZF_DEFAULT_COMMAND='rg --files --hidden -g !.git/'
    # more commands:
    export FZF_ALT_C_COMMAND='find .'
    export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
    # configuration for ripgrep
    export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
    # =============================================================================
    # CDD - Change Directory with Dialogue
    alias cddhome="cd ~ && cd \$(find . -type d | fzf)"
    alias cddprojects="cd /var/www/html && cd \$(find . -type d | fzf)"
    
  3. NUTZEN! Per Tastenkombinationen oder Alternativen Aufrufen!

Es folgen noch ein paar Hinweise.

Vorschau

Diese Konfigurationen erlaubt die Vorschau auf Textformate inklusive Zeilennummerierung und Syntaxhighlighting für bekannte Formate.

In der Priview lässt sich auch Scrollen:

  • Rollrad der Maus bei entsprechendem Fensterfokus

  • Strg + Up / Down mit Cursortasten

Alias Beispiele: CDD - Change Directory with Dialogue

Solche Anwendungen setze ich in allen meinen Shells um. Natürlich kann man klever tippen oder weitere Tools benutzen (siehe z).

Aber wenn man schon alles beisammen hat? Die Aliase cddhome und cddprojects erlauben den schnellen Wechsel über die Konsole in gewünschte Ordner.

Und man erkennt an der Gleichförmigkeit der Alias auch schnell, dass man diese durch eine Allgemeine Shell Funktion ersetzen könnte.

Ripgrep Konfiguration

Wenn das Tool Ripgrep (rg) genutzt wird und man die Konfiguration setzt, dann kann es Meldungen zu einer fehlenden Konfigurationsdatei .ripgreprc geben.

Hinweise zur ripgrep Konfiguration: ~/.ripgreprc

# Don't let ripgrep vomit really long lines to my terminal, and show a preview.
--max-columns=150
--max-columns-preview

# Add my 'web' type.
--type-add
web:*.{html,css,js}*

# Using glob patterns to include/exclude files or folders
--glob=!git/*

# or
--glob
!git/*

# Set the colors.
--colors=line:none
--colors=line:style:bold

# Because who cares about case!?
--smart-case

Man kann aber auch einfach eine leere ~/.ripgreprc bereitstellen.