/docs/kittens/hyperlinked_grep.rst

https://github.com/kovidgoyal/kitty · ReStructuredText · 61 lines · 40 code · 21 blank · 0 comment · 0 complexity · f45bdde37e6255a4244692dcf599e7e2 MD5 · raw file

  1. Hyperlinked grep
  2. =================
  3. This kitten allows you to search your files using `ripgrep
  4. <https://www.google.com/search?q=ripgrep>`_ and open the results
  5. directly in your favorite editor in the terminal, at the line containing
  6. the search result, simply by clicking on the result you want.
  7. To set it up, first create :file:`~/.config/kitty/open-actions.conf` with the
  8. following contents:
  9. .. code:: conf
  10. # Open any file with a fragment in vim, fragments are generated
  11. # by the hyperlink_grep kitten and nothing else so far.
  12. protocol file
  13. fragment_matches [0-9]+
  14. action launch --type=overlay vim +${FRAGMENT} ${FILE_PATH}
  15. # Open text files without fragments in the editor
  16. protocol file
  17. mime text/*
  18. action launch --type=overlay ${EDITOR} ${FILE_PATH}
  19. Now, run a search with::
  20. kitty +kitten hyperlinked_grep something
  21. Hold down the :kbd:`ctrl+shift` keys and click on any of the
  22. result lines, to open the file in vim at the matching line. If
  23. you use some editor other than vim, you should adjust the
  24. :file:`open-actions.conf` file accordingly.
  25. Finally, add an alias to your shell's rc files to invoke the kitten as ``hg``::
  26. alias hg='kitty +kitten hyperlink_grep'
  27. You can now run searches with::
  28. hg some-search-term
  29. If you want to enable completion, for the kitten, you can delegate completion
  30. to rg. For ZSH, you do that with::
  31. compdef _rg kitty +kitten hyperlinked_grep
  32. To learn more about kitty's powerful framework for customizing URL click
  33. actions, :doc:`see here <../open_actions>`.
  34. Hopefully, someday this functionality will make it into some `upstream grep
  35. <https://github.com/BurntSushi/ripgrep/issues/665>`_
  36. program directly removing the need for this kitten.
  37. .. note::
  38. While you can pass any of ripgrep's comand line options to the kitten and
  39. they will be forwarded to rg, do not use options that change the output
  40. formatting as the kitten works by parsing the output from ripgrep.