v0.3.79 28ca733

powershell_setting.go RawHistoryFolder

1package modes
2
3import (
4	"fmt"
5
6	"github.com/patriceckhart/zot/packages/agent/tools"
7	"github.com/patriceckhart/zot/packages/core"
8)
9
10// Optional so existing SettingsStore implementations remain compatible.
11type powerShellSettingsStore interface {
12	SetPowerShell(enabled bool) error
13}
14
15func (i *Interactive) powerShellSettingHint() string {
16	switch {
17	case i.cfg.NoTools:
18		return "disabled for this run by --no-tools"
19	case i.cfg.ToolSelectionExplicit:
20		return "controlled for this run by --tools"
21	}
22	if i.agent != nil {
23		if tool := i.agent.Tools["powershell"]; tool != nil {
24			if _, builtin := tool.(*tools.PowerShellTool); !builtin {
25				return "controlled by a custom tool"
26			}
27		}
28	}
29	return ""
30}
31
32func (i *Interactive) appendPowerShellSetting(items []settingsItem, goos string) []settingsItem {
33	if goos != "windows" {
34		return items
35	}
36	hint := i.powerShellSettingHint()
37	value := i.cfg.PowerShellEnabled != nil && *i.cfg.PowerShellEnabled
38	if hint != "" && i.agent != nil {
39		value = i.agent.Tools["powershell"] != nil
40	}
41	return append(items, settingsItem{
42		key: "powershell_enabled", label: "PowerShell tool",
43		desc:  "enable native PowerShell alongside the default tools; execution remains blocked while jailed",
44		value: value, disabled: hint != "", hint: hint,
45	})
46}
47
48func (i *Interactive) applyPowerShellSetting(value bool, goos string) {
49	var err error
50	switch {
51	case goos != "windows":
52		err = fmt.Errorf("PowerShell is only available on Windows")
53	case i.powerShellSettingHint() != "":
54		err = fmt.Errorf("%s", i.powerShellSettingHint())
55	default:
56		if i.cfg.SettingsStore != nil {
57			if store, ok := i.cfg.SettingsStore.(powerShellSettingsStore); ok {
58				err = store.SetPowerShell(value)
59			} else {
60				err = fmt.Errorf("settings store does not support PowerShell")
61			}
62		}
63	}
64	if err != nil {
65		i.mu.Lock()
66		i.statusErr = "settings: " + err.Error()
67		i.statusOK = ""
68		i.mu.Unlock()
69		// Restore the row that the dialog optimistically toggled.
70		if i.settingsDialog != nil {
71			for idx := range i.settingsDialog.items {
72				if i.settingsDialog.items[idx].key == "powershell_enabled" {
73					i.settingsDialog.items[idx].value = i.cfg.PowerShellEnabled != nil && *i.cfg.PowerShellEnabled
74				}
75			}
76		}
77		return
78	}
79
80	i.cfg.PowerShellEnabled = &value
81	if i.agent != nil {
82		next := core.Registry{}
83		for name, tool := range i.agent.Tools {
84			if name != "powershell" {
85				next[name] = tool
86			}
87		}
88		if value {
89			next["powershell"] = &tools.PowerShellTool{CWD: i.cfg.CWD, Sandbox: i.cfg.Sandbox}
90		}
91		i.agent.SetTools(next)
92	}
93	i.mu.Lock()
94	i.statusOK = "PowerShell tool " + onOff(value)
95	i.statusErr = ""
96	i.mu.Unlock()
97}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close