Basic BASH completion
This commit is contained in:
parent
928a4db817
commit
266e51310c
@ -215,7 +215,7 @@ _ksi_main() {
|
||||
builtin local limit
|
||||
# Send all words up to the word the cursor is currently on
|
||||
builtin let limit=1+$COMP_CWORD
|
||||
src=$(builtin printf "%s\n" "${COMP_WORDS[@]:0:$limit}" | builtin command kitty +complete bash)
|
||||
src=$(builtin printf "%s\n" "${COMP_WORDS[@]:0:$limit}" | builtin command kitty-tool __complete__ bash)
|
||||
if [[ $? == 0 ]]; then
|
||||
builtin eval "${src}"
|
||||
fi
|
||||
|
||||
27
tools/completion/bash.go
Normal file
27
tools/completion/bash.go
Normal file
@ -0,0 +1,27 @@
|
||||
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package completion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) {
|
||||
output := strings.Builder{}
|
||||
for _, mg := range completions[0].Groups {
|
||||
for _, m := range mg.Matches {
|
||||
fmt.Fprintln(&output, "COMPREPLY+=("+utils.QuoteStringForSH(m.Word)+")")
|
||||
}
|
||||
}
|
||||
return []byte(output.String()), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
input_parsers["bash"] = shell_input_parser
|
||||
output_serializers["bash"] = bash_output_serializer
|
||||
}
|
||||
@ -15,6 +15,21 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func shell_input_parser(data []byte, shell_state map[string]string) ([][]string, error) {
|
||||
raw := string(data)
|
||||
new_word := strings.HasSuffix(raw, "\n\n")
|
||||
raw = strings.TrimRight(raw, "\n \t")
|
||||
scanner := bufio.NewScanner(strings.NewReader(raw))
|
||||
words := make([]string, 0, 32)
|
||||
for scanner.Scan() {
|
||||
words = append(words, scanner.Text())
|
||||
}
|
||||
if new_word {
|
||||
words = append(words, "")
|
||||
}
|
||||
return [][]string{words}, nil
|
||||
}
|
||||
|
||||
func zsh_input_parser(data []byte, shell_state map[string]string) ([][]string, error) {
|
||||
matcher := shell_state["_matcher"]
|
||||
q := ""
|
||||
@ -32,18 +47,7 @@ func zsh_input_parser(data []byte, shell_state map[string]string) ([][]string, e
|
||||
// these matcher types break completion, so just abort in this case.
|
||||
return nil, fmt.Errorf("ZSH anchor based matching active, cannot complete")
|
||||
}
|
||||
raw := string(data)
|
||||
new_word := strings.HasSuffix(raw, "\n\n")
|
||||
raw = strings.TrimRight(raw, "\n \t")
|
||||
scanner := bufio.NewScanner(strings.NewReader(raw))
|
||||
words := make([]string, 0, 32)
|
||||
for scanner.Scan() {
|
||||
words = append(words, scanner.Text())
|
||||
}
|
||||
if new_word {
|
||||
words = append(words, "")
|
||||
}
|
||||
return [][]string{words}, nil
|
||||
return shell_input_parser(data, shell_state)
|
||||
}
|
||||
|
||||
func fmt_desc(word, desc string, max_word_len int, f *markup.Context, screen_width int) string {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user