about summary refs log tree commit diff
diff options
context:
space:
mode:
authormhmdanas <triallax@tutanota.com>2023-03-10 21:10:16 +0000
committerLeah Neukirchen <leah@vuxu.org>2023-03-18 19:34:25 +0100
commitd957f7cf9359b426d5b0338bcdd1c778f6e06780 (patch)
tree5214ee781b38239680435620c4fc0526a9cf0eb3
parent97eb26d2dd30d36a811feefb3acaf49c4824c837 (diff)
downloadxtools-d957f7cf9359b426d5b0338bcdd1c778f6e06780.tar.gz
xtools-d957f7cf9359b426d5b0338bcdd1c778f6e06780.tar.xz
xtools-d957f7cf9359b426d5b0338bcdd1c778f6e06780.zip
Add xchangelog command
I didn't make the other changes to the README myself, they were simply
done when I ran `make README`.
-rw-r--r--README3
-rw-r--r--_xtools1
-rwxr-xr-xxchangelog46
-rw-r--r--xtools.12
4 files changed, 52 insertions, 0 deletions
diff --git a/README b/README
index ae78e4a..5e8520c 100644
--- a/README
+++ b/README
@@ -18,6 +18,9 @@ COMMANDS
      xbump pkgname [git commit options]
         – git commit a new package or package update
 
+     xchangelog template | pkgname
+        – open package changelog
+
      xcheckmypkgs [email]
         – check your packages for updates
 
diff --git a/_xtools b/_xtools
index 3a52516..f548f91 100644
--- a/_xtools
+++ b/_xtools
@@ -136,6 +136,7 @@ _xtools() {
 		xbuildbarf) _xtools_one_arch "$@";;
 		xbulk) _xbulk "$@";;
 		xbump) _xtools_one_template "$@";;
+		xchangelog) _xtools_one_template "$@";;
 		xcheckrestart) _xcheckrestart "$@";;
 		xdbg) _xtools_just_packages "$@";;
 		xdiff) _xdiff "$@";;
diff --git a/xchangelog b/xchangelog
new file mode 100755
index 0000000..e97cdf0
--- /dev/null
+++ b/xchangelog
@@ -0,0 +1,46 @@
+#!/bin/bash
+# xchangelog PKGNAME - open package changelog
+
+XBPS_DISTDIR=$(xdistdir) || exit 1
+
+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
+	curl -s -- "$changelog"
+elif curl -sI -w "%{content_type}" -o /dev/null -- "$changelog" | grep -i "^text/plain"; then
+	if [ -n "$PAGER" ]; then
+		curl -s -- "$changelog" | "$PAGER"
+	elif type less >/dev/null; then
+		curl -s -- "$changelog" | less
+	else
+		curl -s -- "$changelog"
+	fi
+else
+	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
+fi
diff --git a/xtools.1 b/xtools.1
index 7a2fb90..1b76740 100644
--- a/xtools.1
+++ b/xtools.1
@@ -24,6 +24,8 @@ keep going on errors
 .El
 .It Nm xbump Ar pkgname Op Ar git\ commit\ options
 .Nd git commit a new package or package update
+.It Nm xchangelog Ar template | pkgname
+.Nd open package changelog
 .It Nm xcheckmypkgs Op Ar email
 .Nd check your packages for updates
 .It Nm xcheckrestart Op Fl v