@@ -54,6 +54,7 @@ static void printHelpFlag(const char* name) {
5454 "-C --no-color Use a monochrome color scheme\n"
5555 "-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
5656 "-F --filter=FILTER Show only the commands matching the given filter\n"
57+ "-S --state=STATESCHARS Show only the states matching the given states\n"
5758 "-h --help Print this help screen\n"
5859 "-H --highlight-changes[=DELAY] Highlight new and old processes\n" , name );
5960#ifdef HAVE_GETMOUSE
@@ -78,6 +79,7 @@ static void printHelpFlag(const char* name) {
7879typedef struct CommandLineSettings_ {
7980 Hashtable * pidMatchList ;
8081 char * commFilter ;
82+ char * stateFilter ;
8183 uid_t userId ;
8284 int sortKey ;
8385 int delay ;
@@ -98,6 +100,7 @@ static CommandLineStatus parseArguments(int argc, char** argv, CommandLineSettin
98100 * flags = (CommandLineSettings ) {
99101 .pidMatchList = NULL ,
100102 .commFilter = NULL ,
103+ .stateFilter = NULL ,
101104 .userId = (uid_t )- 1 , // -1 is guaranteed to be an invalid uid_t (see setreuid(2))
102105 .sortKey = 0 ,
103106 .delay = -1 ,
@@ -128,6 +131,7 @@ static CommandLineStatus parseArguments(int argc, char** argv, CommandLineSettin
128131 {"tree" , no_argument , 0 , 't' },
129132 {"pid" , required_argument , 0 , 'p' },
130133 {"filter" , required_argument , 0 , 'F' },
134+ {"state" , required_argument , 0 , 'S' },
131135 {"highlight-changes" , optional_argument , 0 , 'H' },
132136 {"readonly" , no_argument , 0 , 128 },
133137 PLATFORM_LONG_OPTIONS
@@ -136,7 +140,7 @@ static CommandLineStatus parseArguments(int argc, char** argv, CommandLineSettin
136140
137141 int opt , opti = 0 ;
138142 /* Parse arguments */
139- while ((opt = getopt_long (argc , argv , "hVMCs:td:n:u::Up:F:H::" , long_opts , & opti ))) {
143+ while ((opt = getopt_long (argc , argv , "hVMCs:td:n:u::Up:F:H::S: " , long_opts , & opti ))) {
140144 if (opt == EOF )
141145 break ;
142146
@@ -255,6 +259,33 @@ static CommandLineStatus parseArguments(int argc, char** argv, CommandLineSettin
255259 }
256260 free_and_xStrdup (& flags -> commFilter , optarg );
257261 break ;
262+
263+ case 'S' :
264+ assert (optarg );
265+ if (optarg [0 ] == '\0' ) {
266+ fprintf (stderr , "Error: state filter cannot be empty.\n" );
267+ return STATUS_ERROR_EXIT ;
268+ }
269+
270+ for (char * c = optarg ; * c != '\0' ; c ++ ) {
271+ bool valid = false;
272+
273+ for (ProcessState s = UNKNOWN ; s <= SLEEPING ; s ++ ) {
274+ if (* c == processStateChar (s )) {
275+ valid = true;
276+ break ;
277+ }
278+ }
279+
280+ if (!valid ) {
281+ fprintf (stderr , "Error: invalid state filter value \"%s\".\n" , optarg );
282+ return STATUS_ERROR_EXIT ;
283+ }
284+ }
285+
286+ free_and_xStrdup (& flags -> stateFilter , optarg );
287+ break ;
288+
258289 case 'H' : {
259290 const char * delay = optarg ;
260291 if (!delay && optind < argc && argv [optind ] != NULL &&
@@ -382,6 +413,9 @@ int CommandLine_run(int argc, char** argv) {
382413 .hideSelection = false,
383414 .hideMeters = false,
384415 };
416+ if (flags .stateFilter ) {
417+ free_and_xStrdup (& settings -> stateFilter , flags .stateFilter );
418+ }
385419
386420 MainPanel_setState (panel , & state );
387421 if (flags .commFilter )
0 commit comments