supports referencing envs in hotkeys (#2420)
* supports referencing envs in hotkeys * add testcase for hotkeys * rename attr name to keepHistorymine
parent
d0f874e01a
commit
3137b2b55a
|
|
@ -525,6 +525,12 @@ 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
|
||||
description: Namespaced resources
|
||||
command: "$RESOURCE_NAME $NAMESPACE"
|
||||
keepHistory: true # whether you can return to the previous view
|
||||
```
|
||||
|
||||
Not feeling so hot? Your custom hotkeys will be listed in the help view `?`.
|
||||
|
|
@ -532,6 +538,8 @@ In order to surface hotkeys globally please follow these steps:
|
|||
|
||||
You can choose any keyboard shortcuts that make sense to you, provided they are not part of the standard K9s shortcuts list.
|
||||
|
||||
Similarly, referencing environment variables in hotkeys is also supported. The available environment variables can refer to the description in the [Plugins](#plugins) section.
|
||||
|
||||
> NOTE: This feature/configuration might change in future releases!
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type HotKey struct {
|
|||
ShortCut string `yaml:"shortCut"`
|
||||
Description string `yaml:"description"`
|
||||
Command string `yaml:"command"`
|
||||
KeepHistory bool `yaml:"keepHistory"`
|
||||
}
|
||||
|
||||
// NewHotKeys returns a new plugin.
|
||||
|
|
|
|||
|
|
@ -21,4 +21,5 @@ func TestHotKeyLoad(t *testing.T) {
|
|||
assert.Equal(t, "shift-0", k.ShortCut)
|
||||
assert.Equal(t, "Launch pod view", k.Description)
|
||||
assert.Equal(t, "pods", k.Command)
|
||||
assert.Equal(t, true, k.KeepHistory)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ hotKeys:
|
|||
shortCut: shift-0
|
||||
description: Launch pod view
|
||||
command: pods
|
||||
keepHistory: true
|
||||
|
|
|
|||
|
|
@ -74,16 +74,23 @@ func hotKeyActions(r Runner, aa ui.KeyActions) {
|
|||
log.Warn().Err(fmt.Errorf("HOT-KEY Doh! you are trying to override an existing command `%s", k)).Msg("Invalid shortcut")
|
||||
continue
|
||||
}
|
||||
|
||||
command, err := r.EnvFn()().Substitute(hk.Command)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Invalid shortcut command")
|
||||
continue
|
||||
}
|
||||
|
||||
aa[key] = ui.NewSharedKeyAction(
|
||||
hk.Description,
|
||||
gotoCmd(r, hk.Command, ""),
|
||||
gotoCmd(r, command, "", !hk.KeepHistory),
|
||||
false)
|
||||
}
|
||||
}
|
||||
|
||||
func gotoCmd(r Runner, cmd, path string) ui.ActionHandler {
|
||||
func gotoCmd(r Runner, cmd, path string, clearStack bool) ui.ActionHandler {
|
||||
return func(evt *tcell.EventKey) *tcell.EventKey {
|
||||
r.App().gotoResource(cmd, path, true)
|
||||
r.App().gotoResource(cmd, path, clearStack)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue