0.1.3 fb536a2

humanize.go RawHistoryFolder

1package humanize
2
3import (
4	"fmt"
5	"time"
6)
7
8// BytesToReadableSize converts a number of bytes to a human-readable size
9func BytesToReadableSize(size int64) string {
10	var unit string
11	var converted float64
12
13	if size >= 1<<30 {
14		unit = "GB"
15		converted = float64(size) / (1 << 30)
16	} else if size >= 1<<20 {
17		unit = "MB"
18		converted = float64(size) / (1 << 20)
19	} else if size >= 1<<10 {
20		unit = "KB"
21		converted = float64(size) / (1 << 10)
22	} else {
23		unit = "B"
24		converted = float64(size)
25	}
26
27	return fmt.Sprintf("%.2f%s", converted, unit)
28}
29
30// TimeAgo returns a string representing the time elapsed since t
31func TimeAgo(t time.Time) string {
32	var duration time.Duration
33	now := time.Now()
34	if t.After(now) {
35		duration = t.Sub(now)
36	} else {
37		duration = now.Sub(t)
38	}
39
40	switch {
41	case duration < time.Minute:
42		return fmt.Sprintf("%d seconds ago", int(duration.Seconds()))
43	case duration < time.Hour:
44		return fmt.Sprintf("%d minutes ago", int(duration.Minutes()))
45	case duration < time.Hour*24:
46		return fmt.Sprintf("%d hours ago", int(duration.Hours()))
47	case duration < time.Hour*24*7:
48		return fmt.Sprintf("%d days ago", int(duration.Hours()/24))
49	case duration < time.Hour*24*30:
50		return fmt.Sprintf("%d weeks ago", int(duration.Hours()/(24*7)))
51	case duration < time.Hour*24*365:
52		return fmt.Sprintf("%d months ago", int(duration.Hours()/(24*30)))
53	default:
54		return fmt.Sprintf("%d years ago", int(duration.Hours()/(24*365)))
55	}
56}

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 7

Tags 106

↑↓ moveenter openesc close