From 36327941782184a4ac92526275192fd4bab193f2 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 9 Aug 2022 23:40:04 -0500 Subject: Rewrite mklesskey to fix #13 --- bollux | 75 ++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/bollux b/bollux index 08d2038..21d2770 100755 --- a/bollux +++ b/bollux @@ -1181,31 +1181,66 @@ less_prompt_escape() { # less_prompt_escape STRING printf '\n' } -# generate a lesskey(1) file for custom keybinds +## Generate a lesskey(1) file for custom keybinds +# After less 582, less itself can read lesskey configuration files, rendering +# the lesskey *program* deprecated. The exact message is, apparently, this: +# +# NOTE: lesskey is deprecated. +# It is no longer necessary to run lesskey, +# when using less version 582 and later. +# +# Now I don't have less 582 available on my machine (Debian of course!), so I'm +# relying on a report from 'bencollver' on tildegit. (Thanks for the report, +# ben!) +# +# That being said, this may not work. *Please test!* --- acdw 2022-08-09 mklesskey() { # mklesskey if [[ -f "$BOLLUX_CUSTOM_LESSKEY" ]]; then log d "Using custom lesskey: '$BOLLUX_CUSTOM_LESSKEY'" BOLLUX_LESSKEY="${BOLLUX_CUSTOM_LESSKEY}" - elif [[ -f "$BOLLUX_LESSKEY" ]]; then - log d "Found lesskey: '$BOLLUX_LESSKEY'" + return + fi + + less_version="$(less --version | awk '{print $2;exit;}')" + lesskey_ft="$(file -i "$BOLUX_LESSKEY")" + lesskey_make=false + + if [[ "$lesskey_ft" =~ .*application.* && less_version -lt 582 ]] || + [[ "$lesskey_ft" =~ .*text.* && less_version -ge 582 ]]; then + mv "$BOLLUX_LESSKEY" "${BOLLUX_LESSKEY}.bak" + log e "Moved incompatible lesskey '$BOLLUX_LESSKEY' to '${BOLLUX_LESSKEY}.bak'." + lesskey_make=true + fi + + if [[ ! -f "$BOLLUX_LESSKEY" ]]; then + lesskey_make=true + fi + + if "$lesskey_make"; then + log d "Generating lesskey..." + cat >/tmp/bollux_lesskey <<-EOF + #command + ${KEY_OPEN} quit 0 # 48 open a link + ${KEY_GOTO} quit 1 # 49 goto a url + ${KEY_BACK} quit 2 # 50 back + ${KEY_FORWARD} quit 3 # 51 forward + ${KEY_REFRESH} quit 4 # 52 re-request / download + ${KEY_GOTO_FROM} quit 5 # 53 goto a url (pre-filled) + ${KEY_CYCLE_PRE} quit 6 # 54 cycle T_PRE_DISPLAY and refresh + # other keybinds + \\40 forw-screen-force + h left-scroll + l right-scroll + ? status # 'status' will show a little help thing. + = noaction + EOF + if ((less_version >= 582)); then + mv /tmp/bollux_lesskey "$BOLLUX_LESSKEY" + else + lesskey -o "$BOLLUX_LESSKEY" /tmp/bollux_lesskey + fi else - log d "Generating lesskey: '$BOLLUX_LESSKEY'" - lesskey -o "$BOLLUX_LESSKEY" - <