Specifying environment variables in .lesskey


One day while I was fooling with my `less` pager settings, I came across a fancy prompt string posted to the darwinos-users mailing list: re: less modifications. I added it to my `.lesskey` file, yielding:

#env LESS = -i --prompt="%f (%pb%, %lmth line, %L lines)$"

After I executed `lesskey` to apply the new settings to `.less`, I started seeing error messages like these whenever I tried to use the pager:

  • `-” must be followed by 1 or 2 chars Missing filename (“less –help” for help)`
  • `There is no -’ option (“less –help” for help)`

It turns out that the problem is with the quote characters. Unlike `bash`, you don’t have to worry about `lesskey` interpreting the `$` or `%` characters. Thus, you don’t need to “protect” them with quotes.

Removing the quotes fixed the problem and now `less` tells me where I’m at in the file in terms of percentage, line number, and total lines: `/etc/passwd (68 14th line, 33 lines)`


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!