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

Re: \b character escapes in CLI usage

From
Jeff King <peff@peff.net>
Date
Feb 26, 2025, 22:06 UTC
Message-ID
<20250226220628.GA600528@coredump.intra.peff.net>
In-Reply-To
<CAO_smVjC=CWeAEjZjr9PPuBTkyYus59o_J9hfnpJCB-AsBE0HA@mail.gmail.com>
On Wed, Feb 26, 2025 at 08:38:15AM -0800, Kyle Lippincott wrote:
Show 21 quoted lines
> > In modern versions of less you can get around it with:
> >
> >   LESS="-U --proc-tab"
> >
> > or:
> >
> >   LESS="--PROC-BACKSPACE"
> >
> > but those are new in less 632, from the last year or two. So I don't
> > think we can rely on it in our default variable, but people with recent
> > versions of less should consider setting it.
> 
> From another issue (https://github.com/gwsw/less/issues/557) I learned
> you can do this:
> 
> LESSKEY_CONTENT='#env;#version>=632 LESS=${LESS} --PROC-BACKSPACE'
> 
> I haven't tested it yet, but that might be a decent solution? I don't
> know how composable those are; e.g. if you wanted both
> --PROC-BACKSPACE on >=632 and --no-poll on >=670, I'm *assuming* you
> can do that, but I don't know what the syntax looks like.

Thanks for the pointer, I didn't know about that. I think it is fully composable, as the "#version" conditional just applies to one line. So:

  LESSKEY_CONTENT='#env;#version>=632 LESS=${LESS} --PROC-BACKSPACE;#version >=670 LESS=${LESS} --no-poll'

However, I couldn't get even the basic version to work. Turns out that LESSKEY_CONTENT was added in 645, and I'm running 643 from Debian unstable).

So it kind-of works for our case if we make 645 the minimum (and don't help versions between 632 and 645 at all). I think we could get even hackier to support old versions like:

  # probably would be $prefix/share/git/lesskey in a real install
  fn=/tmp/lesskey
  {
	echo "#env"
	echo "#version >= 632 LESS=${LESS} --PROC-BACKSPACE"
  } >"$fn"
  # This works back to less 582. Before that we have to compile it to a
  # binary format with "lesskey" and point to it with $LESSKEY.
  LESSKEYIN=$fn git log

I guess we'd also need to put more details into setup_pager_env(). Right now its logic is just "do not set $FOO if $FOO is already set". But we'd probably want rules like "if $LESS is set, do not try to override it with $LESSKEY_CONTENT".

I'm inclined to punt on it for a while. People can set up $LESS themselves based on what they have available, and once these features have been around for a while, we might then consider adding them to our defaults.

-Peff
Previous: Kyle LippincottNext: Junio C Hamano
Message 6 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.