rig

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 13 Imported by: 0

README

Rig

Rigging up ripgrep to open results in an editor. Unlike regular ripgrep, rig hooks into your shell to provide shell aliases that open up your editor of choice.

Inspired by tag.

Usage

~/workspace $ rig 'my pattern here' ./path/to/search/under

Configuration

Configuration is done entirely with environment variables:

Variable Default Description
RIG_BOOTSTRAP N/a Bootstraps your shell init script with the required shell hooks.
RIG_ALIAS_FILE /tmp/rig-aliases A temp file containing shell aliases for each match.
RIG_ALIAS_PREFIX e The prefix for each shell alias. Keep this to 1 or 2 letters.
RIG_EDITOR vim Which editor you want the shell aliases to open. See below.
RIG_EDIT_COMMAND N/a Command used to open your editor to the exact line and column.
RIG_RIPGREP_CMD rg Fully-qualified path to the ripgrep executable for rig to use.

These environment variables may be placed in your shell init script (e.g., ~/.bashrc).

Editors

The following are a list of supported editors for which RIG_EDITOR can specify the command name. To support any other editors, the command must be specified with RIG_EDIT_COMMAND. (e.g., mcedit for Midnight Commander) to choose your editor

Editor RIG_EDITOR RIG_EDIT_COMMAND
Emacs emacs emacs +{{ .LineNumber }}:{{ .ColumnNumber }} --file="{{ .Filename }}"
Helix hx hx "{{ .Filename }}:{{ .LineNumber }}:{{ .ColumnNumber }}"
Micro micro micro +{{ .LineNumber }}:{{ .ColumnNumber }} "{{ .Filename }}"
Midnight Commander mcedit mcedit "{{ .Filename }}:{{ .LineNumber }}"
Nano nano nano +{{.LineNumber}},{{ .ColumnNumber }} "{{ .Filename }}"
NeoVim nvim nvim -c "call cursor({{.LineNumber}}, {{.ColumnNumber}})" "{{.Filename}}"
Nice Editor ne ne +{{.LineNumber}},{{ .ColumnNumber }} "{{ .Filename }}"
Vim vim vim -c "call cursor({{.LineNumber}}, {{.ColumnNumber}})" "{{.Filename}}"
Visual Studio Code code code --goto "{{ .Filename }}:{{ .LineNumber }}:{{ .ColumnNumber }}"
Custom editor support

The RIG_EDIT_COMMAND variable is a rendered go template that exposes the following variables:

Variable Example Description
{{ .MatchIndex }} 23 The number appended to the shell alias
{{ .Filename }} /tmp/fizz/buzz.html The absolute path to the file containing the match
{{ .LineNumber }} 590 The line on which the match occurs
{{ .ColumnNumber }} 14 The column on which the first matching character appears
Shell environments
  • Bourne Again Shell (bash)
  • Zsh (zsh)
  • Fish (fish)

Install

Compile it yourself using Nix, or download the appropriate binary from the latest release.

The resulting binary must be named rig and be present somewhere in your PATH (e.g., /usr/local/bin/rig).

On first run, execute as follows:

~/workspace $ env RIG_BOOTSTRAP="$SHELL" rig

Then restart your shell session.

OPTIONAL: Run alias rg=rig to use rig as a drop-in replacement for most of the common uses of ripgrep.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL