linux超级好用检索跳转工具hg:hyperlinked_grep (grep+kitty)

1,安装命令:

install kitty:

curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin

install repgrep:

    curl -LO  https://github.com/BurntSushi/ripgrep/releases/download/12.1.1/ripgrep_12.1.1_amd64.deb
    sudo dpkg -i ripgrep_12.1.1_amd64.deb

2,新建配置文件:

touch .config/kitty/open-actions.conf

3,编辑配置文件:

vi .config/kitty/open-actions.conf

4,拷贝下面配置中一种(VIM或gedit)并粘贴到3打开的open-actions.conf文件中,保存并退出。

VIM方式:

# Open any file with a fragment in vim, fragments are generated
# by the hyperlink_grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay vim +${FRAGMENT} ${FILE_PATH}

# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay ${EDITOR} ${FILE_PATH}

gedit方式:

# Open any file with a fragment in gedit, fragments are generated
# by the hyperlink_grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay gedit +${FRAGMENT} ${FILE_PATH}

# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay ${EDITOR} ${FILE_PATH}

5,打开kitty终端

 .local/kitty.app/bin/kitty 

6, kitty终端输入要搜索内容

kitty +kitten hyperlinked_grep UFC

 点击搜索到的关键词,波浪显示并自动跳转打开文件,光标显示在对应行(我用gedit方式):

7,kitty终端内复制粘贴是ctrl+shift+c/ctrl+shift+v,记住多了个shift。


还可以参考以下链接

Hyperlinked grep - kittyhttps://sw.kovidgoyal.net/kitty/kittens/hyperlinked_grep/?highlight=grep

Hyperlinked grep - kitty



Hyperlinked grep

This kitten allows you to search your files using ripgrep and open the results directly in your favorite editor in the terminal, at the line containing the search result, simply by clicking on the result you want.

New in version 0.19.0.

To set it up, first create ~/.config/kitty/open-actions.conf with the following contents:

# Open any file with a fragment in vim, fragments are generated
# by the hyperlink_grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay vim +${FRAGMENT} ${FILE_PATH}

# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay ${EDITOR} ${FILE_PATH}

Now, run a search with:

kitty +kitten hyperlinked_grep something

Hold down the Ctrl+Shift keys and click on any of the result lines, to open the file in vim at the matching line. If you use some editor other than vim, you should adjust the open-actions.conf file accordingly.

Finally, add an alias to your shell’s rc files to invoke the kitten as hg:

alias hg="kitty +kitten hyperlinked_grep"

You can now run searches with:

hg some-search-term

If you want to enable completion, for the kitten, you can delegate completion to rg. How to do that varies based on the shell:

zsh

Instead of using an alias, create a simple wrapper script named hg somewhere in your PATH:

#!/bin/sh
exec kitty +kitten hyperlinked_grep "$@"

Then, add the following to .zshrc:

compdef _rg hg

fish

To learn more about kitty’s powerful framework for customizing URL click actions, see here.

By default, this kitten adds hyperlinks for several parts of ripgrep output: the per-file header, match context lines, and match lines. You can control which items are linked with a --kitten hyperlink flag. For example, --kitten hyperlink=matching_lines will only add hyperlinks to the match lines. --kitten hyperlink=file_headers,context_lines will link file headers and context lines but not match lines. --kitten hyperlink=none will cause the command line to be passed to directly to rg so no hyperlinking will be performed. --kitten hyperlink may be specified multiple times.

Hopefully, someday this functionality will make it into some upstream grep program directly removing the need for this kitten.

Note

While you can pass any of ripgrep’s comand line options to the kitten and they will be forwarded to rg, do not use options that change the output form

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值