How do I set $LESS invocation options in a lesskey file?

1

1

I'm trying to use less's lesskey-file support, as described in the manpage:

KEY BINDINGS

   You  may define your own less commands by using the program lesskey (1)
   to create a lesskey file.  This file specifies a set  of  command  keys
   and  an  action  associated with each key.  You may also use lesskey to
   change the line-editing keys (see LINE EDITING), and to set environment
   variables. …

Unfortunately, this isn't working for me:

$ mkdir test_lesskey && cd !#:1
$ less --version
less 471 (PCRE regular expressions)
Copyright (C) 1984-2014  Mark Nudelman
$ cat <<-EOF >a_lesskey   
   #env
   LESS=-?
EOF
$ lesskey -o a_dot_less 'a_lesskey'
$ less -FX a_dot_less
^@M+Gc^@^@e^@^@v        ^@LESS^@84-?^@xEnd
$ less --lesskey-file=a_dot_less "~/.profile"

At this point, less is opened normally, instead of printing the less -? usage-text and quitting as expected.

I've experimented with a couple different flags (and formattings), and none of them seem to work as described in the manpage.

The lesskey mechanism overall definitely works; I can define, say, the following:

#command
e     quit

… and less will exit, as expected, if I hit the e key. It's only the environment-variable section that I cannot make work as-expected.

I've tried this on both Arch (pacman -S less) and OS X (brew install less; it's irrelevant on an out-of-the-box OS X, as the OS X less is patched not to include lesskey support.)

ELLIOTTCABLE

Posted 2015-02-19T22:02:03.567

Reputation: 1 207

Answers

1

I use less 458 on OS X 10.8.5 and could reproduce your problem.

-k filename or --lesskey-file=filename don't seem to work with the #env section.

I suggest you use the default paths or variables and file a bug at the developer's website where a problem related also to this option and section was already reported and fixed, see reference 141.

1.61803

Posted 2015-02-19T22:02:03.567

Reputation: 293

I e-mailed the developer, with a link to this thread. We'll see if he has a solution for me! (= – ELLIOTTCABLE – 2015-12-10T03:53:15.953

For now, I simply did as you suggest: Moved the actual keys in the lesskey into ~/.less, compiled them to ~/.lesskey, and then moved all the environment-configuration into my ~/.profile with a caveat that I'm only doing so because it's broken.

– ELLIOTTCABLE – 2015-12-10T03:53:57.457

I already mailed him last month and was told, he'll look into it — I don't see it in the list of known bugs though.
Also, I think you're using the defaults the other way around. lesskey will take ~/.lesskey and output ~/.less. You can also use LESSKEY or LESSKEY_SYSTEM vars. I suggest you check the man page for further details.

– 1.61803 – 2015-12-10T10:38:14.077