main 59bf5a6

bash_unix.go RawHistoryFolder

1//go:build !windows
2
3package tools
4
5import (
6	"io"
7	"os/exec"
8	"sync"
9	"syscall"
10	"time"
11)
12
13const bashProcessWaitDelay = 5 * time.Second
14
15// configureBashProcess makes context cancellation terminate the shell's
16// process group and closes the output pipe exactly once. CommandContext calls
17// cmd.Cancel from its context watcher, so no second cancellation watcher is
18// needed here.
19func configureBashProcess(cmd *exec.Cmd, output io.Closer) func() {
20	setProcessGroup(cmd)
21	cmd.WaitDelay = bashProcessWaitDelay
22	var closeOutput sync.Once
23	closePipe := func() {
24		closeOutput.Do(func() {
25			if output != nil {
26				_ = output.Close()
27			}
28		})
29	}
30	cmd.Cancel = func() error {
31		closePipe()
32		return killBashProcessGroup(cmd)
33	}
34	return closePipe
35}
36
37// setProcessGroup puts the command in its own process group so
38// killProcessGroup can target the entire tree including background
39// children spawned with &.
40func setProcessGroup(cmd *exec.Cmd) {
41	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
42}
43
44// killBashProcessGroup forcefully terminates the entire process group so
45// backgrounded children (cmd &) cannot survive cancellation or retain an
46// output pipe.
47func killBashProcessGroup(cmd *exec.Cmd) error {
48	if cmd == nil || cmd.Process == nil {
49		return nil
50	}
51	pgid := cmd.Process.Pid
52	err := syscall.Kill(-pgid, syscall.SIGKILL)
53	if err == syscall.ESRCH {
54		return nil
55	}
56	return err
57}
58
59// killProcessGroup sends SIGTERM then SIGKILL to the entire process group.
60// It is also used by the worktree Git helper, which keeps graceful
61// cancellation behavior.
62func killProcessGroup(cmd *exec.Cmd) {
63	if cmd == nil || cmd.Process == nil {
64		return
65	}
66	pgid := cmd.Process.Pid
67	_ = syscall.Kill(-pgid, syscall.SIGTERM)
68	time.AfterFunc(3*time.Second, func() {
69		_ = syscall.Kill(-pgid, syscall.SIGKILL)
70	})
71}

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 477

↑↓ moveenter openesc close