Feature request: Short time units
I patched my local procps-ng to use shortened time units, like y
instead of year(s)
, w
instead of week(s)
and so on. I did this as I want to show uptime
in my WM bar.
My local patch looks like this:
--- a/proc/whattime.c 2019-10-27 12:32:58.347231010 +0100
+++ b/proc/whattime.c 2021-01-04 22:54:30.997747773 +0100
@@ -76,8 +76,8 @@
else
updays = (int) uptime_secs / (60*60*24);
- strcat (buf, "up ");
- pos += 3;
+ //strcat (buf, "up ");
+ //pos += 3;
if (!human_readable) {
if (updays)
@@ -124,32 +124,32 @@
}
if (upyears) {
- pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", upyears,
- upyears > 1 ? "years" : "year");
+ pos += sprintf(buf + pos, "%s%d%s", comma > 0 ? ", " : "", upyears,
+ upyears > 1 ? "y" : "y");
comma += 1;
}
if (upweeks) {
- pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", upweeks,
- upweeks > 1 ? "weeks" : "week");
+ pos += sprintf(buf + pos, "%s%d%s", comma > 0 ? ", " : "", upweeks,
+ upweeks > 1 ? "w" : "w");
comma += 1;
}
if (updays) {
- pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", updays,
- updays > 1 ? "days" : "day");
+ pos += sprintf(buf + pos, "%s%d%s", comma > 0 ? ", " : "", updays,
+ updays > 1 ? "d" : "d");
comma += 1;
}
if (uphours) {
- pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", uphours,
- uphours > 1 ? "hours" : "hour");
+ pos += sprintf(buf + pos, "%s%d%s", comma > 0 ? ", " : "", uphours,
+ uphours > 1 ? "h" : "h");
comma += 1;
}
if (upminutes || (!upminutes && uptime_secs < 60)) {
- pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", upminutes,
- upminutes != 1 ? "minutes" : "minute");
+ pos += sprintf(buf + pos, "%s%d%s", comma > 0 ? ", " : "", upminutes,
+ upminutes != 1 ? "m" : "m");
comma += 1;
}
}
I'm looking to upstream this, as I want to get rid of patching it. Would you be interested in a MR for that? Of course I would rework it to be nice, with some flag (-S
[capital S], --short
?)