summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-03-09 19:27:15 -0400
committerJune McEnroe <june@causal.agency>2020-03-09 20:01:30 -0400
commit94fb742a93db0c57b0f2cb42c04d55df425d4286 (patch)
treecd1a1142992f7a6356edbed3591467b4c9ee40c0
parentShorten $HOME to ~ in prompt expansion (diff)
downloadsrc-94fb742a93db0c57b0f2cb42c04d55df425d4286.tar.gz
src-94fb742a93db0c57b0f2cb42c04d55df425d4286.zip
Add \? exit status prompt expansion
-rw-r--r--bin/1sh/1sh.12
-rw-r--r--bin/1sh/parser.c12
2 files changed, 14 insertions, 0 deletions
diff --git a/bin/1sh/1sh.1 b/bin/1sh/1sh.1
index 9bbd881b..d72a87c7 100644
--- a/bin/1sh/1sh.1
+++ b/bin/1sh/1sh.1
@@ -1427,6 +1427,8 @@ This system's hostname.
 The final component of the current working directory.
 .It Li \ew
 The entire path of the current working directory.
+.It Li \e?
+Exit status if it is non-zero, empty string otherwise.
 .It Li \e$
 Superuser status.
 .Dq Li "$ "
diff --git a/bin/1sh/parser.c b/bin/1sh/parser.c
index 3f73220f..1038aa43 100644
--- a/bin/1sh/parser.c
+++ b/bin/1sh/parser.c
@@ -2039,6 +2039,18 @@ expandprompt(const char *fmt) {
 				break;
 
 				/*
+				 * Exit status if non-zero.
+				 */
+			case '?':
+				if (exitstatus != 0) {
+					snprintf(&ps[i], PROMPTLEN - i, "%d", exitstatus);
+					while (ps[i] != '\0')
+						i++;
+				}
+				i--;
+				break;
+
+				/*
 				 * Superuser status.
 				 *
 				 * '$' for normal users, '#' for root.