git/list[1] front-page[2] threads[3] people[4] search[5] about
 

General output formatting (was: Re: \b character escapes in CLI usage)

From
Marc Branchaud <marcnarc@xiplink.com>
Date
Feb 27, 2025, 14:06 UTC
Message-ID
<3a58720f-a572-4e3a-bed1-cc7e8f46e3c7@xiplink.com>
In-Reply-To
<xmqqplj49rul.fsf@gitster.g>
On 2025-02-26 19:03, Junio C Hamano wrote:
Show 13 quoted lines
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
>> I agree this is the right choice in general.  I wonder if we might want
>> some sort of human-readable output option that might escape these that
>> users could use.
>> The output might still be machine-readable, ...
> 
> I wonder if isatty(1) is a good way to say "ah, we are not captured
> in 'foo=$(git blah)' and not feeding somebody in 'git blah |
> somebody', so we do not have to worry about being machine readable".
> If that is a reliable way to tell that we could butcher our output
> for the sake of keeping the terminal state sane, we then can always
> do the C-quote escaping, or even information losing '?' redaction.

Modern practice seems to be moving towards explicit format options to let code that's parsing output directly specify how it wants to see the data. Such options eliminate the need for isatty() heuristics and other guesswork.

For example, the ip command (at least in Ubuntu) accepts -j to format output as JSON. I've found this to be immensely helpful for my scripts.

I'm sure Git scripters would appreciate something similar, perhaps as a global "--format=X" option to "git" itself. isatty() heuristics could still be used when no formatting option is specified (though I suspect in the long run the default will end up being terminal-friendly output).

This would certainly be a large effort, but once the basic pattern is worked out it could be incrementally implemented one command at a time.

		M.
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 15 in “\b character escapes in CLI usage”
  1. Yaakov SmithFeb 25, 2025
  2. Jeff KingFeb 26, 2025
  3. Jeff KingFeb 26, 2025
  4. Junio C HamanoFeb 26, 2025
  5. Kyle LippincottFeb 26, 2025
  6. Jeff KingFeb 26, 2025
  7. Junio C HamanoFeb 26, 2025
  8. brian m. carlsonFeb 26, 2025
  9. Junio C HamanoFeb 26, 2025
  10. Junio C HamanoFeb 27, 2025
  11. General output formatting (was: Re: \b character escapes in CLI usage)Marc Branchaud, Feb 27, 2025
  12. Junio C HamanoFeb 27, 2025
  13. Marc BranchaudFeb 27, 2025
  14. Junio C HamanoFeb 27, 2025
  15. Phillip WoodFeb 27, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.