]> granicus.if.org Git - procps-ng/commitdiff
top: extend command line sort field override provision
authorJim Warner <james.warner@comcast.net>
Thu, 20 Dec 2012 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@enc.com.au>
Sat, 22 Dec 2012 06:11:34 +0000 (17:11 +1100)
In a effort to anticipate a potential future wishlist,
the recent '-o' sort override command line switch will
now support an override of the sort direction as well.

By prepending a '+' or '-' to any valid field name the
user will be able to guarantee a specific desired sort
direction. The '+' forces a high-to-low (normal) order
while a '-' reverses that to yield a low-to-high sort.

Without this addition users would be left to the mercy
of whatever was last specified for Curwin as reflected
in the rcfile or top's default of a high-to-low order.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.1
top/top.c

index 9f86cb0c802f428654f3ff498268e2766339d891..bce1e00ff295707b0f97ca90aa7c59d24160ffd3 100644 (file)
--- a/top/top.1
+++ b/top/top.1
@@ -306,6 +306,9 @@ produce before ending.
 \-\fBo\fR :\fI Override-sort-field\fR as:\fB\ \ \-o fieldname \fR
 Specifies the name of the field on which tasks will be sorted, independent
 of what is reflected in the configuration file.
+You can prepend a '+' or '\-' to the field name to also override the sort direction.
+A leading '+' will force sorting high to low, whereas a '\-' will ensure a low to high
+ordering.
 
 This option exists primarily to support automated/scripted batch mode
 operation.
index e1715d7bcd466428cf903a43e11d5315a90b031b..c17d93fc65dcdf1677f44ed9fa5a79da0de9091d 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -3291,6 +3291,8 @@ static void parse_args (char **args) {
                if (cp[1]) cp++;
                else if (*args) cp = *args++;
                else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
+               if (*cp == '+') { SETw(Curwin, Qsrt_NORMAL); ++cp; }
+               else if (*cp == '-') { OFFw(Curwin, Qsrt_NORMAL); ++cp; }
                for (i = 0; i < P_MAXPFLGS; i++)
                   if (!STRCMP(cp, N_col(i))) break;
                if (i == P_MAXPFLGS)