From 4feffa0704aea5ce4ca11220949090318c2d2c3d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 1 Mar 2021 17:31:51 -0600 Subject: Enable customization of keybindings --- bollux | 63 ++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/bollux b/bollux index c3be520..9e8d6ce 100644 --- a/bollux +++ b/bollux @@ -137,6 +137,15 @@ bollux_config() { : "${BOLLUX_PROTO:=gemini}" # default protocol : "${BOLLUX_URL:=}" # start url : "${BOLLUX_BYEMSG:=See You Space Cowboy ...}" # bye message + ## lesskeys + : "${KEY_OPEN:=o}" # prompt for a link to open + : "${KEY_GOTO:=g}" # prompt for a page to 'goto' + : "${KEY_GOTO_FROM:=G}" # goto a page with current prefilled + : "${KEY_BACK:='['}" # go back in the history + : "${KEY_FORWARD:=']'}" # go forward in the history + : "${KEY_REFRESH:=r}" # refresh the page + : "${KEY_CYCLE_PRE:=p}" # cycle T_PRE_DISPLAY + : "${BOLLUX_CUSTOM_LESSKEY:=${XDG_CONFIG_HOME:-$HOME/.config}/bollux/bollux.lesskey}" ## files : "${BOLLUX_DATADIR:=${XDG_DATA_HOME:-$HOME/.local/share}/bollux}" : "${BOLLUX_DOWNDIR:=.}" # where to save downloads @@ -689,8 +698,13 @@ display() { # display METADATA [TITLE] set_title "$title${title:+ - }bollux" # render ANSI color escapes and don't wrap pre-formatted blocks less_cmd=(less -RS) - mklesskey "$BOLLUX_LESSKEY" && less_cmd+=(-k "$BOLLUX_LESSKEY") - local helpline="o:open, g/G:goto, [:back, ]:forward, r:refresh" + mklesskey && less_cmd+=(-k "$BOLLUX_LESSKEY") + local helpline="${KEY_OPEN}:open, " + helpline+="${KEY_GOTO}/" + helpline+="${KEY_GOTO_FROM}:goto, " + helpline+="${KEY_BACK}:back, " + helpline+="${KEY_FORWARD}:forward, " + helpline+="${KEY_REFRESH}:refresh" less_cmd+=( # 'status'line -Pm"$(less_prompt_escape "$BOLLUX_URL") - bollux$" @@ -735,23 +749,31 @@ less_prompt_escape() { # less_prompt_escape STRING } # generate a lesskey(1) file for custom keybinds -mklesskey() { # mklesskey FILENAME - lesskey -o "$1" - <<-\END - #command - o quit 0 # 48 open a link - g quit 1 # 49 goto a url - [ quit 2 # 50 back - ] quit 3 # 51 forward - r quit 4 # 52 re-request / download - G quit 5 # 53 goto a url (pre-filled) - p 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 - END +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 "Generating lesskey: '$BOLLUX_LESSKEY'" + lesskey -o "$BOLLUX_LESSKEY" - <