feat: allow override of plugins & hotkeys shortcuts (#2510)
* feat: allow override of plugins & hotkeys shortcuts * add docs and log.info when overrides * edit log message * fix doc * Update README.mdmine
parent
9ca46ab027
commit
914bffc0a7
|
|
@ -532,9 +532,10 @@ In order to surface hotkeys globally please follow these steps:
|
|||
shortCut: Shift-2
|
||||
description: Xray Deployments
|
||||
command: xray deploy
|
||||
# Hitting Ctrl-U view the resources in the namespace of your current selection
|
||||
ctrl-u:
|
||||
shortCut: Ctrl-U
|
||||
# Hitting Shift-S view the resources in the namespace of your current selection
|
||||
shift-s:
|
||||
shortCut: Shift-S
|
||||
override: true # => will override the default shortcut related action if set to true (default to false)
|
||||
description: Namespaced resources
|
||||
command: "$RESOURCE_NAME $NAMESPACE"
|
||||
keepHistory: true # whether you can return to the previous view
|
||||
|
|
@ -642,6 +643,7 @@ K9s allows you to extend your command line and tooling by defining your very own
|
|||
A plugin is defined as follows:
|
||||
|
||||
* Shortcut option represents the key combination a user would type to activate the plugin
|
||||
* Override option make that the default action related to the shortcut will be overrided by the plugin
|
||||
* Confirm option (when enabled) lets you see the command that is going to be executed and gives you an option to confirm or prevent execution
|
||||
* Description will be printed next to the shortcut in the k9s menu
|
||||
* Scopes defines a collection of resources names/short-names for the views associated with the plugin. You can specify `all` to provide this shortcut for all views.
|
||||
|
|
@ -678,6 +680,7 @@ plugins:
|
|||
# Defines a plugin to provide a `ctrl-l` shortcut to tail the logs while in pod view.
|
||||
fred:
|
||||
shortCut: Ctrl-L
|
||||
override: false
|
||||
confirm: false
|
||||
description: Pod logs
|
||||
scopes:
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type HotKeys struct {
|
|||
// HotKey describes a K9s hotkey.
|
||||
type HotKey struct {
|
||||
ShortCut string `yaml:"shortCut"`
|
||||
Override bool `yaml:"override"`
|
||||
Description string `yaml:"description"`
|
||||
Command string `yaml:"command"`
|
||||
KeepHistory bool `yaml:"keepHistory"`
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"shortCut": {"type": "string"},
|
||||
"override": { "type": "boolean" },
|
||||
"description": {"type": "string"},
|
||||
"command": {"type": "string"},
|
||||
"keepHistory": {"type": "boolean"}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"shortCut": { "type": "string" },
|
||||
"override": { "type": "boolean" },
|
||||
"description": { "type": "string" },
|
||||
"confirm": { "type": "boolean" },
|
||||
"scopes": {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ type Plugin struct {
|
|||
Scopes []string `yaml:"scopes"`
|
||||
Args []string `yaml:"args"`
|
||||
ShortCut string `yaml:"shortCut"`
|
||||
Override bool `yaml:"override"`
|
||||
Pipes []string `yaml:"pipes"`
|
||||
Description string `yaml:"description"`
|
||||
Command string `yaml:"command"`
|
||||
|
|
|
|||
|
|
@ -76,9 +76,11 @@ func hotKeyActions(r Runner, aa ui.KeyActions) error {
|
|||
continue
|
||||
}
|
||||
_, ok := aa[key]
|
||||
if ok {
|
||||
if ok && !hk.Override {
|
||||
errs = errors.Join(errs, fmt.Errorf("duplicated hotkeys found for %q in %q", hk.ShortCut, k))
|
||||
continue
|
||||
} else if ok && hk.Override == true {
|
||||
log.Info().Msgf("Action %q has been overrided by hotkey in %q", hk.ShortCut, k)
|
||||
}
|
||||
|
||||
command, err := r.EnvFn()().Substitute(hk.Command)
|
||||
|
|
@ -125,14 +127,17 @@ func pluginActions(r Runner, aa ui.KeyActions) error {
|
|||
continue
|
||||
}
|
||||
key, err := asKey(plugin.ShortCut)
|
||||
|
||||
if err != nil {
|
||||
errs = errors.Join(errs, err)
|
||||
continue
|
||||
}
|
||||
_, ok := aa[key]
|
||||
if ok {
|
||||
if ok && !plugin.Override {
|
||||
errs = errors.Join(errs, fmt.Errorf("duplicated plugin key found for %q in %q", plugin.ShortCut, k))
|
||||
continue
|
||||
} else if ok && plugin.Override == true {
|
||||
log.Info().Msgf("Action %q has been overrided by plugin in %q", plugin.ShortCut, k)
|
||||
}
|
||||
aa[key] = ui.NewKeyActionWithOpts(
|
||||
plugin.Description,
|
||||
|
|
|
|||
Loading…
Reference in New Issue