mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Use compopt to manage files and spaces
This commit is contained in:
@@ -220,9 +220,9 @@ _ksi_main() {
|
|||||||
builtin eval "${src}"
|
builtin eval "${src}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
builtin complete -o nospace -F _ksi_completions kitty
|
builtin complete -F _ksi_completions kitty
|
||||||
builtin complete -o nospace -F _ksi_completions edit-in-kitty
|
builtin complete -F _ksi_completions edit-in-kitty
|
||||||
builtin complete -o nospace -F _ksi_completions clone-in-kitty
|
builtin complete -F _ksi_completions clone-in-kitty
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wrap our prompt additions in markers we can use to remove them using
|
# wrap our prompt additions in markers we can use to remove them using
|
||||||
|
|||||||
@@ -13,21 +13,33 @@ var _ = fmt.Print
|
|||||||
|
|
||||||
func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) {
|
func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) {
|
||||||
output := strings.Builder{}
|
output := strings.Builder{}
|
||||||
f := func(format string, args ...interface{}) { fmt.Fprintf(&output, format, args...) }
|
f := func(format string, args ...interface{}) { fmt.Fprintf(&output, format+"\n", args...) }
|
||||||
n := completions[0].Delegate.NumToRemove
|
n := completions[0].Delegate.NumToRemove
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
n--
|
n--
|
||||||
f("COMP_WORDS[%d]=%s\n", n, utils.QuoteStringForSH(completions[0].Delegate.Command))
|
f("compopt +o nospace")
|
||||||
f("_command_offset %d\n", n)
|
f("COMP_WORDS[%d]=%s", n, utils.QuoteStringForSH(completions[0].Delegate.Command))
|
||||||
|
f("_command_offset %d", n)
|
||||||
} else {
|
} else {
|
||||||
for _, mg := range completions[0].Groups {
|
for _, mg := range completions[0].Groups {
|
||||||
mg.remove_common_prefix()
|
mg.remove_common_prefix()
|
||||||
for _, m := range mg.Matches {
|
if mg.NoTrailingSpace {
|
||||||
w := m.Word
|
f("compopt -o nospace")
|
||||||
if !mg.NoTrailingSpace {
|
} else {
|
||||||
w += " "
|
f("compopt +o nospace")
|
||||||
}
|
}
|
||||||
f("COMPREPLY+=(%s)\n", utils.QuoteStringForSH(w))
|
if mg.IsFiles {
|
||||||
|
f("compopt -o filenames")
|
||||||
|
for _, m := range mg.Matches {
|
||||||
|
if strings.HasSuffix(m.Word, utils.Sep) {
|
||||||
|
m.Word = m.Word[:len(m.Word)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f("compopt +o filenames")
|
||||||
|
}
|
||||||
|
for _, m := range mg.Matches {
|
||||||
|
f("COMPREPLY+=(%s)", utils.QuoteStringForSH(m.Word))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user