jj icon indicating copy to clipboard operation
jj copied to clipboard

FR: use filenames instead of pipes for the pager (where appropriate)

Open jyn514 opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. i am running jj cat to see the contents of a file from an old revision. i want to have syntax highlighting, so i set PAGER='bat --color=always'. but bat does not know the data coming from stdin is a rust file, so it doesn't generate syntax highlighting; i have to use PAGER='bat --file-name=cli_util.rs --color=always' explicitly (which means i can't set this persistently in jj.toml).

Describe the solution you'd like write the file to disk before piping it to the pager.

Describe alternatives you've considered

  • special-case bat and pass it --file-name flags
  • decide this use case isn't supported and people should just use flags in PAGER explicitly.

Additional context Add any other context or screenshots about the feature request here.

jyn514 avatar Feb 10 '24 14:02 jyn514

Or have an environment variable hold the current file name, to be used as needed?

I think many tools use a file written to /tmp as when an editor allows you to run your compiler on unsaved changes, or the zip file viewer lets you look in a file in the zip.

joyously avatar Feb 10 '24 15:02 joyously

an environment variable would work, yeah. i'd have to write a little wrapper script that passes it to bat, but that's doable.

jyn514 avatar Feb 10 '24 16:02 jyn514

Or have an environment variable hold the current file name, to be used as needed?

Yes, or substitute a $filename variable like we do for diff editors. Then the user can set their config like this:

ui.pager = ["bat", "--filename", "$filename"]

We already allow passing static environment variables (like we do to less by default). We could allow passing the path that way too, so you could do this:

ui.pager = { command = ["my-ager"], env = { MY_PAGER_FILENAME = "$filename" } }

But there might not be a need for that, so that's probably just a nice to have.

martinvonz avatar Feb 10 '24 16:02 martinvonz