guix-channel

A channel for the Guix package manager

git clone https://git.8pit.net/guix-channel.git

 1From 29df8734fdc342f5ffb626f1636e1e0b4f72c1ed Mon Sep 17 00:00:00 2001
 2From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
 3Date: Thu, 13 Nov 2025 08:36:29 +0100
 4Subject: [PATCH] Don't print the full ksh binary name in error messages
 5
 6This results in much nicer to read error messages on Guix where
 7argv[0] will be a lengthy GNU store path with which we don't want
 8to prefix every error message.
 9
10Note that for login shell's (e.g., as created by login(8) or sshd), the
11argv[0] will be `-ksh` and the error message will be readable. However,
12for non-login shell's (e.g., as created by terminal emulators) argv[0]
13will be the full binary path.
14
15---
16 io.c | 23 +++++++++++++++++++++--
17 1 file changed, 21 insertions(+), 2 deletions(-)
18
19diff --git a/io.c b/io.c
20index 1ea1978..d9d9b3d 100644
21--- a/io.c
22+++ b/io.c
23@@ -17,6 +17,22 @@
24 
25 static int initio_done;
26 
27+/*
28+ * GNU's version of basename(3) from string.h which does *not* modify it's
29+ * input but returns an empty string when path has a trailing '/' or is '/'.
30+ */
31+static const char*
32+basename_const(const char *path)
33+{
34+	char *sep;
35+
36+	if ((sep = (strrchr(path, '/')))) {
37+		return sep+1;
38+	} else {
39+		return path;
40+	}
41+}
42+
43 /*
44  * formatted output functions
45  */
46@@ -126,8 +142,11 @@ error_prefix(int fileline)
47 {
48 	/* Avoid foo: foo[2]: ... */
49 	if (!fileline || !source || !source->file ||
50-	    strcmp(source->file, kshname) != 0)
51-		shf_fprintf(shl_out, "%s: ", kshname + (*kshname == '-'));
52+	    strcmp(source->file, kshname) != 0) {
53+		const char *kshbasename = basename_const(kshname);
54+		shf_fprintf(shl_out, "%s: ", kshbasename + (*kshbasename == '-'));
55+	}
56+
57 	if (fileline && source && source->file != NULL) {
58 		shf_fprintf(shl_out, "%s[%d]: ", source->file,
59 		    source->errline > 0 ? source->errline : source->line);