Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When should I use the lesskey config file? #492

Closed
SPiCaRiA opened this issue Mar 23, 2024 · 2 comments
Closed

When should I use the lesskey config file? #492

SPiCaRiA opened this issue Mar 23, 2024 · 2 comments

Comments

@SPiCaRiA
Copy link

Hi, thank you for your work and apologize if this is not a prope place for my question (but I really coudn't find an answer).

This is what I have for now. But it really looks redundant and I start having the question about the benefits of using lesskey config file compared to directly setting env vars (e.g. LESS) in my shell config file, especially when I want the backward compatibility and do tons of version check.

In .zshrc:

export LESSKEYIN="$XDG_CONFIG_HOME/less/lesskey"
_less_ver="$(less --version | awk '{print $2;exit}') "
if (( _less_ver < 582 )); then
  # Older less versions can't read lesskey source file and need to compile
  # it with lesskey. See `man lesskey` - SCOPE.
  export LESSKEY="$(dirname $LESSKEYIN)/lesskey.bin"
  ! [[ -e "$LESSKEY" ]] && \
    lesskey -o "$LESSKEY" "$LESSKEYIN" 2>/dev/null
fi

# The `--no-vbell` option only works in less version >= 615, set termcap 
# instead.
# See: https://github.com/gwsw/less/compare/v614...v615
# An empty string doesn't work, but we can set it to any sequence that does
# nothing.
# See: https://github.com/gwsw/less/issues/304#issuecomment-1318094196
(( _less_ver < 615 )) && \
  export LESS_TERMCAP_vb='\x7F'

unset _less_ver

In ~/.config/less/lesskey:

#env
LESS = --ignore-case --dumb --QUIET --RAW-CONTROL-CHARS --quit-if-one-screen 

# Conditional configurations only works on less verion >= 594, see `man 
# lesskey`. `+=` syntax only works on less version >= 595.
# See: https://github.com/gwsw/less/compare/v594...v595

#version >= 615 LESS += --no-vbell

# Don't store a history of search and shell commands
LESSHISTFILE = -

Maybe I shouldn't use lesskey file at all if I don't want to remap anything? Any suggestions/explanations are appreciated!

@gwsw
Copy link
Owner

gwsw commented Mar 24, 2024

There's a certain amount of personal preference in choosing whether to define environment variables in your environment or in a lesskey file. It doesn't really matter, but I would make a couple of comments:

If you need to support pre-582 versions then of course you need to run the lesskey program which can only be done outside the lesskey file, as you are doing. But it doesn't hurt to do it in later versions as well; running lesskey is not necessary in recent versions, but it is still supported. So you could remove the check for version < 582.

For efficiency you might want to run lesskey only if the source file is newer than the binary file (using test -nt or something like that).

You could set LESS_TERMCAP_vb unconditionally, in either your environment or in a lesskey file. If you use --no-vbell in less-615 or later, LESS_TERMCAP_vb is ignored so it doesn't matter whether it's set. So you could remove the check for version < 615 before setting it.

I hope this helps.

@SPiCaRiA
Copy link
Author

There's a certain amount of personal preference in choosing whether to define environment variables in your environment or in a lesskey file. It doesn't really matter, but I would make a couple of comments:

If you need to support pre-582 versions then of course you need to run the lesskey program which can only be done outside the lesskey file, as you are doing. But it doesn't hurt to do it in later versions as well; running lesskey is not necessary in recent versions, but it is still supported. So you could remove the check for version < 582.

For efficiency you might want to run lesskey only if the source file is newer than the binary file (using test -nt or something like that).

You could set LESS_TERMCAP_vb unconditionally, in either your environment or in a lesskey file. If you use --no-vbell in less-615 or later, LESS_TERMCAP_vb is ignored so it doesn't matter whether it's set. So you could remove the check for version < 615 before setting it.

I hope this helps.

Thank you so much! These tips really clarify a lot for me, and I believe many others will benefit from seeing this issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants