Enable customization of keybindings
This commit is contained in:
parent
d3689c74b0
commit
4feffa0704
63
bollux
63
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" - <<END
|
||||
#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
|
||||
END
|
||||
else
|
||||
log d "Found lesskey: '$BOLLUX_LESSKEY'"
|
||||
fi
|
||||
}
|
||||
|
||||
# normalize files
|
||||
|
@ -1081,6 +1103,9 @@ bollux_init() {
|
|||
declare -a HISTORY # history is kept in an array
|
||||
HN=0 # position of history in the array
|
||||
run mkdir -p "${BOLLUX_HISTFILE%/*}"
|
||||
# Remove $BOLLUX_LESSKEY and re-generate keybindings (to catch rebinds)
|
||||
run rm "$BOLLUX_LESSKEY"
|
||||
mklesskey
|
||||
}
|
||||
|
||||
# clean up on exit
|
||||
|
|
Loading…
Reference in New Issue