main 7a3b92c

lib.sh RawHistoryFolder

1# shellcheck shell=bash disable=SC2034
2# Shared helpers for the bundled modules. Source this file: . "$(dirname "$0")/lib.sh"
3#
4# The bar gives every script its colors, each as #rrggbb, so a script never
5# hard-codes one:
6#   NEFERBAR_BACKGROUND  the bar's own background
7#   NEFERBAR_FOREGROUND  the bar's text color
8#   NEFERBAR_ACCENT      the highlight color: bar.accent in the config picks
9#                        which of the 16 theme colors it is
10#   NEFERBAR_COLOR0..15  the theme's 16 ANSI colors
11
12: "${NEFERBAR_BACKGROUND:=#26263a}" "${NEFERBAR_FOREGROUND:=#cdd6f4}"
13: "${NEFERBAR_COLOR0:=#45475a}" "${NEFERBAR_COLOR2:=#a6e3a1}" "${NEFERBAR_COLOR3:=#f9e2af}"
14: "${NEFERBAR_COLOR4:=#89b4fa}" "${NEFERBAR_COLOR15:=#a6adc8}"
15: "${NEFERBAR_ACCENT:=$NEFERBAR_COLOR4}"
16
17RESET=$'\e[0m' BOLD=$'\e[1m'
18
19# Nerd Font icons as raw UTF-8 bytes. Unlike \u escapes, these do not depend on
20# the locale of the process that runs the script.
21ICON_DOT=$'\xef\x84\x91'     # U+F111 circle
22ICON_STASH=$'\xef\x86\x87'   # U+F187 archive
23ICON_APP=$'\xef\x8b\x90'     # U+F2D0 window
24
25# rgb "#rrggbb" -> "r;g;b"
26rgb() {
27	local h=${1#\#}
28	printf '%d;%d;%d' "0x${h:0:2}" "0x${h:2:2}" "0x${h:4:2}"
29}
30fg() { printf '\e[38;2;%sm' "$(rgb "$1")"; }
31bg() { printf '\e[48;2;%sm' "$(rgb "$1")"; }
32
33# mix "#a" "#b" PERCENT -> "#rrggbb", PERCENT of the way from a to b
34mix() {
35	local a=${1#\#} b=${2#\#} p=$3 i out=#
36	for i in 0 2 4; do
37		out+=$(printf '%02x' $(((0x${a:i:2} * (100 - p) + 0x${b:i:2} * p) / 100)))
38	done
39	printf '%s' "$out"
40}
41
42# fade FROM TO -> four blank cells that blend FROM into TO
43fade() {
44	local i
45	for i in 20 40 60 80; do printf '%s ' "$(bg "$(mix "$1" "$2" "$i")")"; done
46}
47
48BAR=$NEFERBAR_BACKGROUND
49ACCENT=$NEFERBAR_ACCENT
50DIM=$(mix "$BAR" "$NEFERBAR_FOREGROUND" 45)
51
52# ink "#accent" -> the text color for a block of that color: the theme's black
53# on a light accent, its white on a dark one.
54ink() {
55	local h=${1#\#}
56	if (((0x${h:0:2} * 299 + 0x${h:2:2} * 587 + 0x${h:4:2} * 114) / 1000 > 140)); then
57		printf '%s' "$NEFERBAR_COLOR0"
58	else
59		printf '%s' "$NEFERBAR_COLOR15"
60	fi
61}
62
63# state_changed_loop CMD... runs CMD now and again whenever $NEFERWL_STATE
64# (NeferWL's state file) changes. NeferWL replaces the file on every change, so
65# a newer modification time is enough, and "read -t" waits without forking.
66state_changed_loop() {
67	local stamp tick
68	stamp=$(mktemp) && trap 'rm -f "$stamp"' EXIT
69	exec {tick}<> <(:)
70	"$@"
71	touch -r "$NEFERWL_STATE" "$stamp" 2>/dev/null
72	while read -r -t 0.1 -u "$tick" || true; do
73		if [[ $NEFERWL_STATE -nt $stamp ]]; then
74			touch -r "$NEFERWL_STATE" "$stamp"
75			"$@"
76		fi
77	done
78}

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 5

Tags 4

↑↓ moveenter openesc close