Now completion for hyperlinked_grep is automatic thanks to delegation
Also fix delegation for zsh when the command being completed differs from the current command.
This commit is contained in:
parent
5666b1b0fd
commit
54ec486d3a
@ -43,34 +43,6 @@ You can now run searches with::
|
|||||||
|
|
||||||
hg some-search-term
|
hg some-search-term
|
||||||
|
|
||||||
If you want to enable completion, for the kitten, you can delegate completion
|
|
||||||
to :program:`rg`. How to do that varies based on the shell:
|
|
||||||
|
|
||||||
|
|
||||||
.. tab:: zsh
|
|
||||||
|
|
||||||
Instead of using an alias, create a simple wrapper script named
|
|
||||||
:program:`hg` somewhere in your :envvar:`PATH`:
|
|
||||||
|
|
||||||
.. code-block:: sh
|
|
||||||
|
|
||||||
#!/bin/sh
|
|
||||||
exec kitty +kitten hyperlinked_grep "$@"
|
|
||||||
|
|
||||||
Then, add the following to :file:`.zshrc`::
|
|
||||||
|
|
||||||
compdef _rg hg
|
|
||||||
|
|
||||||
.. tab:: fish
|
|
||||||
|
|
||||||
You can combine both the aliasing/wrapping and pointing fish to ripgrep's
|
|
||||||
autocompletion with a fish wrapper function in your :file:`config.fish`
|
|
||||||
or :file:`~/.config/fish/functions/hg.fish`:
|
|
||||||
|
|
||||||
.. code-block:: fish
|
|
||||||
|
|
||||||
function hg --wraps rg; kitty +kitten hyperlinked_grep $argv; end
|
|
||||||
|
|
||||||
To learn more about kitty's powerful framework for customizing URL click
|
To learn more about kitty's powerful framework for customizing URL click
|
||||||
actions, see :doc:`here </open_actions>`.
|
actions, see :doc:`here </open_actions>`.
|
||||||
|
|
||||||
|
|||||||
@ -166,6 +166,7 @@ def completion(self: TestCompletion, tdir: str):
|
|||||||
add('kitty -1 bash ', is_delegate(2, 'bash'))
|
add('kitty -1 bash ', is_delegate(2, 'bash'))
|
||||||
add('kitty -1 bash --n', is_delegate(2, 'bash'))
|
add('kitty -1 bash --n', is_delegate(2, 'bash'))
|
||||||
add('kitty @launch --type tab bash --n', is_delegate(4, 'bash'))
|
add('kitty @launch --type tab bash --n', is_delegate(4, 'bash'))
|
||||||
|
add('kitty +kitten hyperlinked_grep --s', is_delegate(2, 'rg'))
|
||||||
add('kitty @launch e', all_words('exe1', 'exe2'))
|
add('kitty @launch e', all_words('exe1', 'exe2'))
|
||||||
|
|
||||||
for cmd, tests, result in zip(all_cmds, all_tests, run_tool()):
|
for cmd, tests, result in zip(all_cmds, all_tests, run_tool()):
|
||||||
|
|||||||
@ -81,41 +81,43 @@ func serialize(completions *Completions, f *markup.Context, screen_width int) ([
|
|||||||
fmt.Fprintln(&output, "shift words")
|
fmt.Fprintln(&output, "shift words")
|
||||||
fmt.Fprintln(&output, "(( CURRENT-- ))")
|
fmt.Fprintln(&output, "(( CURRENT-- ))")
|
||||||
}
|
}
|
||||||
fmt.Fprintln(&output, "_normal -p ", utils.QuoteStringForSH(completions.Delegate.Command))
|
service := utils.QuoteStringForSH(completions.Delegate.Command)
|
||||||
return []byte(output.String()), nil
|
fmt.Fprintln(&output, "words[1]="+service)
|
||||||
}
|
fmt.Fprintln(&output, "_normal -p", service)
|
||||||
for _, mg := range completions.Groups {
|
} else {
|
||||||
cmd := strings.Builder{}
|
for _, mg := range completions.Groups {
|
||||||
cmd.WriteString("compadd -U -J ")
|
cmd := strings.Builder{}
|
||||||
cmd.WriteString(utils.QuoteStringForSH(mg.Title))
|
cmd.WriteString("compadd -U -J ")
|
||||||
cmd.WriteString(" -X ")
|
cmd.WriteString(utils.QuoteStringForSH(mg.Title))
|
||||||
cmd.WriteString(utils.QuoteStringForSH("%B" + mg.Title + "%b"))
|
cmd.WriteString(" -X ")
|
||||||
if mg.NoTrailingSpace {
|
cmd.WriteString(utils.QuoteStringForSH("%B" + mg.Title + "%b"))
|
||||||
cmd.WriteString(" -S ''")
|
if mg.NoTrailingSpace {
|
||||||
}
|
cmd.WriteString(" -S ''")
|
||||||
if mg.IsFiles {
|
|
||||||
cmd.WriteString(" -f")
|
|
||||||
}
|
|
||||||
lcp := mg.remove_common_prefix()
|
|
||||||
if lcp != "" {
|
|
||||||
cmd.WriteString(" -p ")
|
|
||||||
cmd.WriteString(utils.QuoteStringForSH(lcp))
|
|
||||||
}
|
|
||||||
if mg.has_descriptions() {
|
|
||||||
fmt.Fprintln(&output, "compdescriptions=(")
|
|
||||||
limit := mg.max_visual_word_length(16)
|
|
||||||
for _, m := range mg.Matches {
|
|
||||||
fmt.Fprintln(&output, utils.QuoteStringForSH(fmt_desc(m.Word, m.Description, limit, f, screen_width)))
|
|
||||||
}
|
}
|
||||||
fmt.Fprintln(&output, ")")
|
if mg.IsFiles {
|
||||||
cmd.WriteString(" -l -d compdescriptions")
|
cmd.WriteString(" -f")
|
||||||
|
}
|
||||||
|
lcp := mg.remove_common_prefix()
|
||||||
|
if lcp != "" {
|
||||||
|
cmd.WriteString(" -p ")
|
||||||
|
cmd.WriteString(utils.QuoteStringForSH(lcp))
|
||||||
|
}
|
||||||
|
if mg.has_descriptions() {
|
||||||
|
fmt.Fprintln(&output, "compdescriptions=(")
|
||||||
|
limit := mg.max_visual_word_length(16)
|
||||||
|
for _, m := range mg.Matches {
|
||||||
|
fmt.Fprintln(&output, utils.QuoteStringForSH(fmt_desc(m.Word, m.Description, limit, f, screen_width)))
|
||||||
|
}
|
||||||
|
fmt.Fprintln(&output, ")")
|
||||||
|
cmd.WriteString(" -l -d compdescriptions")
|
||||||
|
}
|
||||||
|
cmd.WriteString(" --")
|
||||||
|
for _, m := range mg.Matches {
|
||||||
|
cmd.WriteString(" ")
|
||||||
|
cmd.WriteString(utils.QuoteStringForSH(m.Word))
|
||||||
|
}
|
||||||
|
fmt.Fprintln(&output, cmd.String(), ";")
|
||||||
}
|
}
|
||||||
cmd.WriteString(" --")
|
|
||||||
for _, m := range mg.Matches {
|
|
||||||
cmd.WriteString(" ")
|
|
||||||
cmd.WriteString(utils.QuoteStringForSH(m.Word))
|
|
||||||
}
|
|
||||||
fmt.Fprintln(&output, cmd.String(), ";")
|
|
||||||
}
|
}
|
||||||
// debugf("%#v", output.String())
|
// debugf("%#v", output.String())
|
||||||
return []byte(output.String()), nil
|
return []byte(output.String()), nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user