git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/issues/display
blob: 70f9dcadf539f4e326e69ce029e7f76cc27fff4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash

MYTDIR="$(mktemp -d --tmpdir osissue.XXXXXX)" || exit 1
MYPWD="$(cd "$(dirname "$0")" && pwd)" || exit 2
function ctrl_c {
	if [ ! -z "$MYTDIR" ]; then
		rm -rf "$MYTDIR"
	fi
	exit 130
}
if [ -n "$1" ];then
	FARR="$1"
	if [ ! -e "$FARR" ];then FARR="$FARR.issue";fi
else
	IFS=$'\n'
	FARR=( $(ls *.issue) "issue.blank.1" "issue.blank.2" )
	unset IFS
fi
if [ -r "/etc/os-release" ]; then
	source "/etc/os-release"
fi
if [ -n "$VARIABLE" ]; then
	OSSTR_S="$VARIABLE"
elif [ -n "$PRETTY_NAME" ]; then
	OSSTR_S="$PRETTY_NAME"
else
	OSSTR_S="$(uname -o)"
fi
OSSTR_M="$(uname -m)"
OSSTR_R="$(uname -r)"
OSSTR_N="$(uname -n)"
OSSTR_L="$(tty | sed 's#^/dev/##')"
# see man:agetty(8), ... kinda: we don't have e.g. 4{IFACENAME} anywhere, so we only do the
# argumentless variants
OSSTR_4="$(ip -4 -o address show nomaster primary scope global up | head -n 1 | awk '{print $4}' | awk -F/ '{print $1}')"
if [ -z "$OSSTR_4" ]; then
	OSSTR_4="$(getent ahostsv4 "$(hostname -s)" | head -n1 | awk '{print $1}')"
	if [ -z "$OSSTR_4" ]; then OSSTR_4="127.0.0.1"; fi
fi
OSSTR_6="$(ip -6 -o address show nomaster primary scope global up | head -n 1 | awk '{print $4}' | awk -F/ '{print $1}')"
if [ -z "$OSSTR_6" ]; then
	OSSTR_6="$(getent ahostsv6 "$(hostname -s)" | head -n1 | awk '{print $1}')"
	if [ -z "$OSSTR_6" ]; then
	# this could now be a number of reasons, we act as if IPv6 had been deactivated
		OSSTR_6="::ffff:127.0.1.1"
	fi
fi
(
	cd "$MYPWD" || exit 10
	for issuefile in "${FARR[@]}";do
		cp -p "$issuefile" "${MYTDIR}/" || break
		sed -i "s#\\\\S#$OSSTR_S#;s#\\\\m#$OSSTR_M#;s#\\\\l#$OSSTR_L#" "${MYTDIR}/${issuefile}" &&\
		sed -i "s#\\\\4#$OSSTR_4#;s#\\\\6#$OSSTR_6#" "${MYTDIR}/${issuefile}" &&\
		sed -i "s#\\\\r#$OSSTR_R#;s#\\\\n#$OSSTR_N#" "${MYTDIR}/${issuefile}" || break
		IFS=$'\n'
		FLARR=( $(cat "${MYTDIR}/${issuefile}") )
		unset IFS
		if [ -z "$COLUMNS" ];then
			COLUMNS="$(tput cols)"
			[ -z "$COLUMNS" ] && COLUMNS=20
		fi
		printf "\\033[;1m"
		for ((j=0;j<$COLUMNS;++j)); do printf -- "-"; done
		printf "\\n  %b\\n" "$issuefile"
		for ((j=0;j<$COLUMNS;++j)); do printf -- "-"; done
		printf "\\033[0m\\n"
		printf "%b\\n" "${FLARR[@]}"
	done
)
rm -rf "$MYTDIR"