-
Notifications
You must be signed in to change notification settings - Fork 59
/
xchangelog
executable file
·62 lines (55 loc) · 1.27 KB
/
xchangelog
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
#!/bin/bash
# xchangelog PKGNAME - open package changelog
XBPS_DISTDIR=$(xdistdir) || exit 1
FILTER=cat
pkg=$1
[ -z "$pkg" ] && pkg=$(basename "$PWD")
if [ -f "$pkg" ]; then
template="$pkg"
elif [ -f "$pkg/template" ]; then
template="$pkg/template"
elif [ -f "$XBPS_DISTDIR/srcpkgs/$pkg/template" ]; then
template="$XBPS_DISTDIR/srcpkgs/$pkg/template"
else
echo "No such template: $pkg" >&2
exit 1
fi
. "$template"
if [ -z "$changelog" ]; then
echo "No changelog defined in template" >&2
exit 1
fi
if [ -t 1 ]; then
if type less >/dev/null; then
: "${PAGER:=less -r}"
fi
content_type="$(curl -sLI -w "%{content_type}" -o /dev/null -- "$changelog")"
case "$content_type" in
"text/plain"*)
if [[ "$changelog" = *".md" ]] && type mdcat >/dev/null; then
FILTER="mdcat"
elif [[ "$changelog" = *".rst" ]] && type rst2ansi >/dev/null; then
FILTER="rst2ansi"
fi
;;
"text/markdown"*)
if type mdcat >/dev/null; then
FILTER="mdcat"
fi
;;
*)
if type xdg-open >/dev/null; then
xdg-open "$changelog"
elif [ -n "$BROWSER" ]; then
"$BROWSER" "$changelog"
else
echo 'Cannot open changelog in web browser, please install xdg-open or define $BROWSER' >&2
exit 1
fi
exit 0
;;
esac
else
: "${PAGER:=cat}"
fi
curl -sL -- "$changelog" | $FILTER | $PAGER