Skip to content
/ grug Public

Command-line tool that provides a workflow for extending, editing, diffing, and writing to vim-style grep lines.

License

Notifications You must be signed in to change notification settings

jtrv/grug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grug

Grug is a command-line tool that provides a workflow for expanding, editing, diffing, and writing edits to files using vim-styled grep lines (such as grep -RHn, ripgrep --vimgrep, ugrep -HknI, etc).

TODO

  • adapt --write to apply hunk changes (e.g. edited output from --expand)
  • create --preview to view a diff of lines/hunks supplied and current file contents
  • refactor so it doesn't seem like I leaned on chatgpt as much as I did
  • add tests

Usage

grug [OPTIONS]

  -A, --above <LINES_ABOVE>        Include LINES_ABOVE lines above each line from stdin in the hunk
  -B, --below <LINES_BELOW>        Include LINES_BELOW lines below each line from stdin in the hunk
  -C, --context <CONTEXT_LINES>    Include CONTEXT_LINES above and below each line from stdin in the hunk
  -e, --expand                     Expand the lines from stdin into hunks
  -h, --help                       Print help information
  -w, --write                      Replace lines in files based on input from stdin

Examples

To expand lines from stdin into hunks:

echo "src/main.rs:10" | grug --expand

To replace lines in files based on input from stdin:

echo "src/main.rs:10:new content" | grug --write

Installation

cargo install --git https://github.com/jtrv/grug

Kakoune

In order to use this with kakoune you can add the following code to your kakrc

define-command grep-write -docstring "
  grep-write: pipe the current grep-buffer to grug -w and print results
" %{
  evaluate-commands -draft %{
    execute-keys '%'
    evaluate-commands %sh{
      printf %s "$kak_selection" | grug -w > "$XDG_DATA_HOME"/kak/grug
    }
  }
  evaluate-commands %sh{
    output=$(cat "$XDG_DATA_HOME"/kak/grug)
    echo "echo -markup {Information} '$output'; echo -debug '$output';"
  }
}

License

This project is licensed under the MIT License.

About

Command-line tool that provides a workflow for extending, editing, diffing, and writing to vim-style grep lines.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages