about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-08-09 23:40:04 -0500
committerCase Duckworth2022-08-09 23:40:04 -0500
commit36327941782184a4ac92526275192fd4bab193f2 (patch)
tree72608c4405544de2d4dbc8bbe9b6d1ce9ee19fbf
parentFix download method (diff)
downloadbollux-36327941782184a4ac92526275192fd4bab193f2.tar.gz
bollux-36327941782184a4ac92526275192fd4bab193f2.zip
Rewrite mklesskey to fix #13
-rwxr-xr-xbollux75
1 files 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
1181 printf '\n' 1181 printf '\n'
1182} 1182}
1183 1183
1184# generate a lesskey(1) file for custom keybinds 1184## Generate a lesskey(1) file for custom keybinds
1185# After less 582, less itself can read lesskey configuration files, rendering
1186# the lesskey *program* deprecated. The exact message is, apparently, this:
1187#
1188# NOTE: lesskey is deprecated.
1189# It is no longer necessary to run lesskey,
1190# when using less version 582 and later.
1191#
1192# Now I don't have less 582 available on my machine (Debian of course!), so I'm
1193# relying on a report from 'bencollver' on tildegit. (Thanks for the report,
1194# ben!)
1195#
1196# That being said, this may not work. *Please test!* --- acdw 2022-08-09
1185mklesskey() { # mklesskey 1197mklesskey() { # mklesskey
1186 if [[ -f "$BOLLUX_CUSTOM_LESSKEY" ]]; then 1198 if [[ -f "$BOLLUX_CUSTOM_LESSKEY" ]]; then
1187 log d "Using custom lesskey: '$BOLLUX_CUSTOM_LESSKEY'" 1199 log d "Using custom lesskey: '$BOLLUX_CUSTOM_LESSKEY'"
1188 BOLLUX_LESSKEY="${BOLLUX_CUSTOM_LESSKEY}" 1200 BOLLUX_LESSKEY="${BOLLUX_CUSTOM_LESSKEY}"
1189 elif [[ -f "$BOLLUX_LESSKEY" ]]; then 1201 return
1190 log d "Found lesskey: '$BOLLUX_LESSKEY'" 1202 fi
1203
1204 less_version="$(less --version | awk '{print $2;exit;}')"
1205 lesskey_ft="$(file -i "$BOLUX_LESSKEY")"
1206 lesskey_make=false
1207
1208 if [[ "$lesskey_ft" =~ .*application.* && less_version -lt 582 ]] ||
1209 [[ "$lesskey_ft" =~ .*text.* && less_version -ge 582 ]]; then
1210 mv "$BOLLUX_LESSKEY" "${BOLLUX_LESSKEY}.bak"
1211 log e "Moved incompatible lesskey '$BOLLUX_LESSKEY' to '${BOLLUX_LESSKEY}.bak'."
1212 lesskey_make=true
1213 fi
1214
1215 if [[ ! -f "$BOLLUX_LESSKEY" ]]; then
1216 lesskey_make=true
1217 fi
1218
1219 if "$lesskey_make"; then
1220 log d "Generating lesskey..."
1221 cat >/tmp/bollux_lesskey <<-EOF
1222 #command
1223 ${KEY_OPEN} quit 0 # 48 open a link
1224 ${KEY_GOTO} quit 1 # 49 goto a url
1225 ${KEY_BACK} quit 2 # 50 back
1226 ${KEY_FORWARD} quit 3 # 51 forward
1227 ${KEY_REFRESH} quit 4 # 52 re-request / download
1228 ${KEY_GOTO_FROM} quit 5 # 53 goto a url (pre-filled)
1229 ${KEY_CYCLE_PRE} quit 6 # 54 cycle T_PRE_DISPLAY and refresh
1230 # other keybinds
1231 \\40 forw-screen-force
1232 h left-scroll
1233 l right-scroll
1234 ? status # 'status' will show a little help thing.
1235 = noaction
1236 EOF
1237 if ((less_version >= 582)); then
1238 mv /tmp/bollux_lesskey "$BOLLUX_LESSKEY"
1239 else
1240 lesskey -o "$BOLLUX_LESSKEY" /tmp/bollux_lesskey
1241 fi
1191 else 1242 else
1192 log d "Generating lesskey: '$BOLLUX_LESSKEY'" 1243 log d "Lesskey found: $BOLLUX_LESSKEY"
1193 lesskey -o "$BOLLUX_LESSKEY" - <<END
1194#command
1195${KEY_OPEN} quit 0 # 48 open a link
1196${KEY_GOTO} quit 1 # 49 goto a url
1197${KEY_BACK} quit 2 # 50 back
1198${KEY_FORWARD} quit 3 # 51 forward
1199${KEY_REFRESH} quit 4 # 52 re-request / download
1200${KEY_GOTO_FROM} quit 5 # 53 goto a url (pre-filled)
1201${KEY_CYCLE_PRE} quit 6 # 54 cycle T_PRE_DISPLAY and refresh
1202# other keybinds
1203\\40 forw-screen-force
1204h left-scroll
1205l right-scroll
1206? status # 'status' will show a little help thing.
1207= noaction
1208END
1209 fi 1244 fi
1210} 1245}
1211 1246