|
|
I don't particularily like this. I think you should use the option "ww".
-w Use 132 columns to display information, instead of the default,
which is the window size. If the -w option is specified more
than once, ps will use as many columns as necessary without re-
gard for window size.
As in, this is already a solved problem.
> A month or so ago I suggested a patch to make ps(1) ignore the
> terminal width when outputting to a pipe - the primary goal was to
> make it easier to grep for particular processes and also make some
> scripts behave consistantly not matter what the size of the terminal
> is.
>
> A couple of suggestions were made - use isatty(3) instead of checking
> if stdout is a pipe (which made the patch smaller and more
> generalized), and also to update the manual page as well (thanks for
> the reminder Theo).
>
> Here I present take 2.
> Please let me know what you think.
>
> diff -ru /home/evan/bin/ps/ps.1 bin/ps/ps.1
> --- /home/evan/bin/ps/ps.1 Sun Jul 20 12:35:33 2008
> +++ bin/ps/ps.1 Sun Jul 20 12:36:11 2008
> @@ -167,10 +167,12 @@
> .Dq /dev/drum .
> .It Fl w
> Use 132 columns to display information, instead of the default, which
> -is the window size.
> +is the window width if displaying to a terminal.
> If the
> .Fl w
> -option is specified more than once,
> +option is specified more than once or
> +.Nm
> +is not displaying to a terminal,
> .Nm
> will use as many columns as necessary without regard for window size.
> .It Fl x
> diff -ru /home/evan/bin/ps/ps.c bin/ps/ps.c
> --- /home/evan/bin/ps/ps.c Sun Jul 20 12:35:33 2008
> +++ bin/ps/ps.c Sun Jul 20 12:36:20 2008
> @@ -117,13 +117,16 @@
> char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
> size_t size;
>
> - if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
> - ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
> - ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) ||
> - ws.ws_col == 0)
> - termwidth = 79;
> + if (isatty(STDOUT_FILENO))
> + if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
> + ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
> + ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) ||
> + ws.ws_col == 0)
> + termwidth = 79;
> + else
> + termwidth = ws.ws_col - 1;
> else
> - termwidth = ws.ws_col - 1;
> + termwidth = UNLIMITED;
>
> if (argc > 1)
> argv[1] = kludge_oldps_options(argv[1]);
|
|