Personal fork of aykamko/tag. Wraps ripgrep and creates
numbered shell aliases for opening search matches in an editor. Only rg is
supported.
Install rg and mise, then run from this checkout:
mise install
mise run installThe install task writes to ~/.local/bin. Put that directory on PATH.
Add this to ~/.zshrc or ~/.bashrc:
export TAG_ALIAS_FILE="${TMPDIR:-/tmp}/tag-aliases-${UID}-$$"
_tag() {
local tag_name="$1" tag_status=0
shift
(exec -a "$tag_name" "$HOME/.local/bin/tag" "$@") || tag_status=$?
if [ -r "$TAG_ALIAS_FILE" ]; then
source "$TAG_ALIAS_FILE"
fi
return "$tag_status"
}
alias tag='_tag tag'
alias rg='_tag rg'Run rg pattern, then e1 to open match [1]. Alias files are private to each
shell session. Aliases from earlier searches remain defined until replaced or
removed with unalias.
tag --help shows tag's options. tag --version shows both tag and ripgrep
versions. Through the alias, rg --help and rg --version show ripgrep's
output. The wrapper preserves the invoked name through argv[0]. Use
command rg to bypass tag.
Pipes, redirected output, and alternate output modes such as --json,
--files, and --count run rg directly. Formatting options that prevent
tagging, including multiline searches and custom separators, also pass through.
These searches leave the alias file unchanged. Search exit codes are preserved.
Install fzf and optionally bat, then run:
rg --fzf PATTERN [PATH ...]Type to filter, Tab to select multiple matches, Enter to edit, or Escape to
cancel. The preview highlights the matching line with bat, falling back to
plain cat. tag --fzf works too.
The search finishes before the picker opens. Enter opens the selected files in
one editor session. Neovim and Vim keep each buffer at its selected line and
column; use :next and :previous to move between files. Repeated files keep
the first selected location. Existing aliases stay unchanged.
This mode requires a terminal and standard match output. Pipes, --json,
--count, and other alternate output modes cannot be combined with --fzf.
TAG_ALIAS_FILE: alias file path; defaults to/tmp/tag_aliasesfor existing shell setups. The shell snippet above gives each session its own file.TAG_ALIAS_PREFIX: alias prefix; defaults toe.EDITOR: editor command for both aliases and--fzf; defaults tonvim.TAG_CMD_FMT_STRING: Go template for the editor command. Fields:.Filename,.LineNumber,.ColumnNumber,.MatchIndex.
Use EDITOR for normal editor selection, including arguments:
export EDITOR='nvim'Vim-compatible editors jump to the match; other editors receive the filenames.
TAG_CMD_FMT_STRING overrides EDITOR and runs once per file, without
batching:
export TAG_CMD_FMT_STRING='nvim -c "call cursor({{.LineNumber}}, {{.ColumnNumber}})" -- {{shellQuote .Filename}}'Use {{shellQuote .Filename}} without surrounding quotes in custom templates.
It protects paths containing spaces, quotes, or shell expressions. Existing
templates using quoted {{.Filename}} should migrate to this form.
mise run fmt
mise run lint
mise run test
mise run build
mise run benchTests require rg on PATH. Install fzf and nvim to run their integration
tests; those tests skip when the corresponding tool is missing.