mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Completion for kitty @ load-config --override xxx
This commit is contained in:
@@ -238,13 +238,10 @@ def completion_for_launch_wrappers(*names: str) -> None:
|
||||
|
||||
|
||||
def generate_completions_for_kitty() -> None:
|
||||
from kitty.config import option_names_for_completion
|
||||
print('package completion\n')
|
||||
print('import "kitty/tools/cli"')
|
||||
print('import "kitty/tools/cmd/tool"')
|
||||
print('import "kitty/tools/cmd/at"')
|
||||
conf_names = ', '.join((f'"{serialize_as_go_string(x)}"' for x in option_names_for_completion()))
|
||||
print('var kitty_option_names_for_completion = []string{' + conf_names + '}')
|
||||
|
||||
print('func kitty(root *cli.Command) {')
|
||||
|
||||
@@ -573,6 +570,7 @@ def load_ref_map() -> Dict[str, Dict[str, str]]:
|
||||
|
||||
def generate_constants() -> str:
|
||||
from kittens.hints.main import DEFAULT_REGEX
|
||||
from kitty.config import option_names_for_completion
|
||||
from kitty.fast_data_types import FILE_TRANSFER_CODE
|
||||
from kitty.options.utils import allowed_shell_integration_values
|
||||
del sys.modules['kittens.hints.main']
|
||||
@@ -583,6 +581,7 @@ def generate_constants() -> str:
|
||||
placeholder_char = int(m.group(1), 16)
|
||||
dp = ", ".join(map(lambda x: f'"{serialize_as_go_string(x)}"', kc.default_pager_for_help))
|
||||
url_prefixes = ','.join(f'"{x}"' for x in Options.url_prefixes)
|
||||
option_names = '`' + '\n'.join(option_names_for_completion()) + '`'
|
||||
return f'''\
|
||||
package kitty
|
||||
|
||||
@@ -618,6 +617,7 @@ Term: "{Options.term}", Shell_integration: "{' '.join(Options.shell_integration)
|
||||
Select_by_word_characters: `{Options.select_by_word_characters}`, Wheel_scroll_multiplier: {Options.wheel_scroll_multiplier},
|
||||
Shell: "{Options.shell}", Url_excluded_characters: "{Options.url_excluded_characters}",
|
||||
}}
|
||||
const OptionNames = {option_names}
|
||||
''' # }}}
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ or a previous load-config-file command are respected. Use this option to have th
|
||||
|
||||
--override -o
|
||||
type=list
|
||||
completion=type:special group:complete_kitty_override
|
||||
Override individual configuration options, can be specified multiple times.
|
||||
Syntax: :italic:`name=value`. For example: :option:`{appname} -o` font_size=20
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"kitty"
|
||||
"kitty/tools/cli"
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
@@ -24,3 +25,15 @@ func complete_actions(completions *cli.Completions, word string, arg_num int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func complete_kitty_override(completions *cli.Completions, word string, arg_num int) {
|
||||
mg := completions.AddMatchGroup("Config directives")
|
||||
mg.NoTrailingSpace = true
|
||||
scanner := utils.NewLineScanner(kitty.OptionNames)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if strings.HasPrefix(line, word) {
|
||||
mg.AddMatch(line + "=")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
kitty_constants "kitty"
|
||||
"kitty/tools/cli"
|
||||
"kitty/tools/themes"
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@@ -15,9 +17,11 @@ var _ = fmt.Print
|
||||
func complete_kitty_override(completions *cli.Completions, word string, arg_num int) {
|
||||
mg := completions.AddMatchGroup("Config directives")
|
||||
mg.NoTrailingSpace = true
|
||||
for _, q := range kitty_option_names_for_completion {
|
||||
if strings.HasPrefix(q, word) {
|
||||
mg.AddMatch(q + "=")
|
||||
scanner := utils.NewLineScanner(kitty_constants.OptionNames)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if strings.HasPrefix(line, word) {
|
||||
mg.AddMatch(line + "=")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user