Jq: Indent with tabs

Created on 29 May 2015  Â·  8Comments  Â·  Source: stedolan/jq

Hey,

A very minor feature request, but would it be possible to get pretty printed output indented by tabs and not spaces? If necessary, configurable. Tab width tends to be user configurable everywhere, but using spaces assume a particular width preference and eyesight ability. ;-)

Thanks!

feature request

All 8 comments

An option to use a given number of spaces is doable. I don't care for an option to use tabs.

Actually, indentation by 2 spaces is pretty hardcoded. Changing it is possible, of course, but not something I'm inclined to do at this time. I would consider a PR.

While an alternative, I don't think adding an option to set the number of spaces to jq is the right approach. An appropriate tab stop is a presentation issue better solved a level higher — either in the terminal or text editor. Just like we set TZ or font size in the environment. ;-)

Another solution would be --indent "\t". That would handle everyone.

A workaround till then, for the record, is

jq . | unexpand -t2

I could see using an env var for this, but I won't switch jq to using tabs by default, much less as the only setting. @stedolan likes 2-space indents, and I've grown accustomed to them :) I suspect if he were to voice an opinion, it'd be to keep things as-is, or maybe use an env var.

I don't change the tabstop myself. You're the first person I know who does it (though I've heard that others do it, I'd never heard from someone who does do it). I did just learn that one can set the hard tab stops in most terminals (huh!)... I was about to point out that the terminal emulators I use don't have that option, and then I realized it must be a terminfo escape, and sure enough it is, and there's even a tabs(1) command to set the stops. Sadly I can't just set the tabstop in the terminal, I also have to tell apps like vim. How do you manage code with styles that set max line length at 79 columns? I think it must be confusing. But maybe you can convince me of the value of this lifestyle choice :)?

As for unexpand... that's dangerous, because it will change whitespace in strings. At least tabs (and newlines, and...) in strings must be escaped, so the opposite would be OK (if jq were using tabs for indentation, which it isn't).

I agree having it customizable would be the best. It's hard to post-process because you don't want to mess with whitespace in the output. It would be awesome if it could be any number of spaces or tabs.

Ah, damn, indeed, the BSD version of unexpand kills tabs inside a line even if -a is _not_ given.
The GNU version, fortunately, has a --first-only to override its -t2 option, making the correct workaround to:

jq . | unexpand -t2 --first-only

Fixed with 24a5e5b.

Thanks so much! This is awesome.
On Jun 3, 2015 9:23 PM, "Nico Williams" [email protected] wrote:

Fixed with 24a5e5b
https://github.com/stedolan/jq/commit/24a5e5b1b184f4d941868895486a73e24b9cb85b
.

—
Reply to this email directly or view it on GitHub
https://github.com/stedolan/jq/issues/800#issuecomment-108671211.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kelchy picture kelchy  Â·  4Comments

rclod picture rclod  Â·  4Comments

ve3ied picture ve3ied  Â·  4Comments

mcandre picture mcandre  Â·  3Comments

kaihendry picture kaihendry  Â·  4Comments