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