Closed baizmandesign closed 9 months ago
Hey @baizmandesign!
Here's my question: can I pipe the output to a pager and still retain the nice tabular formatting?
Here's where the switch happens:
You can manipulate the behavior with the SHELL_PIPED
environment variable:
$ SHELL_PIPE=0 wp user list | less
+----+------------+--------------+---------------------+---------------------+----------------------+
| ID | user_login | display_name | user_email | user_registered | roles |
+----+------------+--------------+---------------------+---------------------+----------------------+
| 1 | daniel | daniel | daniel@handbuilt.co | 2023-07-24 15:03:34 | administrator,author |
+----+------------+--------------+---------------------+---------------------+----------------------+
Here's a bit more detail: https://github.com/wp-cli/wp-cli/blob/e5164148f83acfea852c60e3c5a7fdcfe5b46803/php/utils.php#L1222-L1239
This is great, thanks @danielbachhuber! For anyone else who finds this in the future, the environment variable is documented here:
https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-ispiped/
Hi there,
This may be a question rather than a feature request. (Or, if I can build this, then consider it a proposal for a new feature.)
When running commands that generate long lists—for example,
wp user list
on a site with more than a couple dozen users—I like to pipe the output to a pager such asless
. But when I do that, all of the nice tabular formatting gets stripped and the resultant text is much harder to read. I understand why this is the default behavior: it becomes much easier to feed the output to a command likeawk
. Makes sense to me.Here's my question: can I pipe the output to a pager and still retain the nice tabular formatting?
An example command that is not piped:
The same example command when piped to
less
:("(END)" is output from
less
.) As you can see, it becomes very difficult to match columns and values.I'm imagining a new flag—perhaps a global flag that can be used with any command?—to retain the original tabular formatting:
What do you think?