8000 GitHub - letientai299/tag: Instantly jump to your ag or ripgrep matches. · GitHub
[go: up one dir, main page]

Skip to content
letientai299Public
forked from aykamko/tag

About

Instantly jump to your ag or ripgrep matches.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

tag

Personal fork of aykamko/tag. Wraps ripgrep and creates numbered shell aliases for opening search matches in an editor. Only rg is supported.

Install

Install rg and mise, then run from this checkout:

mise install
mise run install

The 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.

Filter matches

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.

Configure

  • TAG_ALIAS_FILE: alias file path; defaults to /tmp/tag_aliases for existing shell setups. The shell snippet above gives each session its own file.
  • TAG_ALIAS_PREFIX: alias prefix; defaults to e.
  • EDITOR: editor command for both aliases and --fzf; defaults to nvim.
  • 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.

Develop

mise run fmt
mise run lint
mise run test
mise run build
mise run bench

Tests require rg on PATH. Install fzf and nvim to run their integration tests; those tests skip when the corresponding tool is missing.

License

MIT license.

About

Instantly jump to your ag or ripgrep matches.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

301A Contributors

Languages

0