hyperlinked_grep.rst 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Hyperlinked grep
  2. =================
  3. .. only:: man
  4. Overview
  5. --------------
  6. .. note::
  7. As of ripgrep versions newer that 13.0 it supports hyperlinks
  8. natively so you can just add the following alias in your shell rc file:
  9. ``alias rg="rg --hyperlink-format=kitty"`` no need to use this kitten.
  10. But, see below for instructions on how to customize kitty to have it open
  11. the hyperlinks from ripgrep in your favorite editor.
  12. This kitten allows you to search your files using `ripgrep
  13. <https://github.com/BurntSushi/ripgrep>`__ and open the results directly in your
  14. favorite editor in the terminal, at the line containing the search result,
  15. simply by clicking on the result you want.
  16. .. versionadded:: 0.19.0
  17. To set it up, first create :file:`~/.config/kitty/open-actions.conf` with the
  18. following contents:
  19. .. code:: conf
  20. # Open any file with a fragment in vim, fragments are generated
  21. # by the hyperlink-grep kitten and nothing else so far.
  22. protocol file
  23. fragment_matches [0-9]+
  24. action launch --type=overlay --cwd=current vim +${FRAGMENT} -- ${FILE_PATH}
  25. # Open text files without fragments in the editor
  26. protocol file
  27. mime text/*
  28. action launch --type=overlay --cwd=current -- ${EDITOR} -- ${FILE_PATH}
  29. Now, run a search with::
  30. kitten hyperlinked-grep something
  31. Hold down the :kbd:`Ctrl+Shift` keys and click on any of the result lines, to
  32. open the file in :program:`vim` at the matching line. If you use some editor
  33. other than :program:`vim`, you should adjust the :file:`open-actions.conf` file
  34. accordingly. TO open links with the keyboard instead, use
  35. :sc:`open_selected_hyperlink`.
  36. Finally, add an alias to your shell's rc files to invoke the kitten as
  37. :command:`hg`::
  38. alias hg="kitten hyperlinked-grep"
  39. You can now run searches with::
  40. hg some-search-term
  41. To learn more about kitty's powerful framework for customizing URL click
  42. actions, see :doc:`here </open_actions>`.
  43. By default, this kitten adds hyperlinks for several parts of ripgrep output:
  44. the per-file header, match context lines, and match lines. You can control
  45. which items are linked with a :code:`--kitten hyperlink` flag. For example,
  46. :code:`--kitten hyperlink=matching_lines` will only add hyperlinks to the
  47. match lines. :code:`--kitten hyperlink=file_headers,context_lines` will link
  48. file headers and context lines but not match lines. :code:`--kitten
  49. hyperlink=none` will cause the command line to be passed to directly to
  50. :command:`rg` so no hyperlinking will be performed. :code:`--kitten hyperlink`
  51. may be specified multiple times.
  52. Hopefully, someday this functionality will make it into some `upstream grep
  53. <https://github.com/BurntSushi/ripgrep/issues/665>`__ program directly removing
  54. the need for this kitten.
  55. .. note::
  56. While you can pass any of ripgrep's command line options to the kitten and
  57. they will be forwarded to :program:`rg`, do not use options that change the
  58. output formatting as the kitten works by parsing the output from ripgrep.
  59. The unsupported options are: :code:`--context-separator`,
  60. :code:`--field-context-separator`, :code:`--field-match-separator`,
  61. :code:`--json`, :code:`-I --no-filename`, :code:`-0 --null`,
  62. :code:`--null-data`, :code:`--path-separator`. If you specify options via
  63. configuration file, then any changes to the default output format will not be
  64. supported, not just the ones listed.