about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]bollux59
1 files changed, 39 insertions, 20 deletions
diff --git a/bollux b/bollux index a57e060..c910cd5 100644..100755 --- a/bollux +++ b/bollux
@@ -38,8 +38,8 @@
38# Code: 38# Code:
39 39
40# Program information 40# Program information
41PRGN="${0##*/}" # Easiest way to get the script name 41PRGN="${0##*/}" # Easiest way to get the script name
42VRSN=0.4.1 # I /try/ to follow semver? IDK. 42VRSN=0.4.1 # I /try/ to follow semver? IDK.
43 43
44# Print a useful help message (`bollux -h'). 44# Print a useful help message (`bollux -h').
45bollux_usage() { 45bollux_usage() {
@@ -238,12 +238,12 @@ bollux_config() {
238 : "${BOLLUX_URL:=}" # start url 238 : "${BOLLUX_URL:=}" # start url
239 : "${BOLLUX_BYEMSG:=See You Space Cowboy ...}" # bye message 239 : "${BOLLUX_BYEMSG:=See You Space Cowboy ...}" # bye message
240 ## lesskeys 240 ## lesskeys
241 : "${KEY_OPEN:=o}" # prompt for a link to open 241 : "${KEY_OPEN:=o}" # prompt for a link to open
242 : "${KEY_GOTO:=g}" # prompt for a page to 'goto' 242 : "${KEY_GOTO:=g}" # prompt for a page to 'goto'
243 : "${KEY_GOTO_FROM:=G}" # goto a page with current prefilled 243 : "${KEY_GOTO_FROM:=G}" # goto a page with current prefilled
244 : "${KEY_BACK:='['}" # go back in the history 244 : "${KEY_BACK:='['}" # go back in the history
245 : "${KEY_FORWARD:=']'}" # go forward in the history 245 : "${KEY_FORWARD:=']'}" # go forward in the history
246 : "${KEY_REFRESH:=r}" # refresh the page 246 : "${KEY_REFRESH:=r}" # refresh the page
247 : "${KEY_CYCLE_PRE:=p}" # cycle T_PRE_DISPLAY 247 : "${KEY_CYCLE_PRE:=p}" # cycle T_PRE_DISPLAY
248 : "${BOLLUX_CUSTOM_LESSKEY:=$BOLLUX_CONF_DIR/bollux.lesskey}" 248 : "${BOLLUX_CUSTOM_LESSKEY:=$BOLLUX_CONF_DIR/bollux.lesskey}"
249 ## files 249 ## files
@@ -253,9 +253,9 @@ bollux_config() {
253 : "${BOLLUX_PAGESRC:=$BOLLUX_DATADIR/pagesrc}" # where to save source 253 : "${BOLLUX_PAGESRC:=$BOLLUX_DATADIR/pagesrc}" # where to save source
254 BOLLUX_HISTFILE="$BOLLUX_DATADIR/history" # where to save history 254 BOLLUX_HISTFILE="$BOLLUX_DATADIR/history" # where to save history
255 ## typesetting 255 ## typesetting
256 : "${T_MARGIN:=4}" # left and right margin 256 : "${T_MARGIN:=4}" # left and right margin
257 : "${T_WIDTH:=0}" # width of the view port 257 : "${T_WIDTH:=0}" # width of the view port
258 # 0 = get term width 258 # 0 = get term width
259 : "${T_PRE_DISPLAY:=both,pre,alt}" # how to view PRE blocks 259 : "${T_PRE_DISPLAY:=both,pre,alt}" # how to view PRE blocks
260 # colors -- these will be wrapped in \e[ __ m 260 # colors -- these will be wrapped in \e[ __ m
261 C_RESET='\e[0m' # reset 261 C_RESET='\e[0m' # reset
@@ -270,10 +270,9 @@ bollux_config() {
270 : "${C_QUOTE:=3}" # quote formatting 270 : "${C_QUOTE:=3}" # quote formatting
271 : "${C_PRE:=0}" # preformatted text formatting 271 : "${C_PRE:=0}" # preformatted text formatting
272 ## state 272 ## state
273 UC_BLANK=':?:' # internal use only, should be non-URL chars 273 UC_BLANK=':?:' # internal use only, should be non-URL chars
274} 274}
275 275
276
277# Load a URL. 276# Load a URL.
278# 277#
279# I was feeling fancy when I named this function -- a more descriptive name 278# I was feeling fancy when I named this function -- a more descriptive name
@@ -388,11 +387,11 @@ usplit() { # usplit NAME:ARRAY URL:STRING
388 # below performs a reverse lookup on the name to get the actual data. 387 # below performs a reverse lookup on the name to get the actual data.
389 # shellcheck disable=2034 388 # shellcheck disable=2034
390 local url="${BASH_REMATCH[0]}" \ 389 local url="${BASH_REMATCH[0]}" \
391 scheme="${BASH_REMATCH[2]}" \ 390 scheme="${BASH_REMATCH[2]}" \
392 authority="${BASH_REMATCH[4]}" \ 391 authority="${BASH_REMATCH[4]}" \
393 path="${BASH_REMATCH[5]}" \ 392 path="${BASH_REMATCH[5]}" \
394 query="${BASH_REMATCH[7]}" \ 393 query="${BASH_REMATCH[7]}" \
395 fragment="${BASH_REMATCH[9]}" 394 fragment="${BASH_REMATCH[9]}"
396 395
397 # 0=url 1=scheme 2=authority 3=path 4=query 5=fragment 396 # 0=url 1=scheme 2=authority 3=path 4=query 5=fragment
398 local i=1 c 397 local i=1 c
@@ -407,6 +406,7 @@ usplit() { # usplit NAME:ARRAY URL:STRING
407 printf -v "$1[0]" '%s' "$url" 406 printf -v "$1[0]" '%s' "$url"
408} 407}
409 408
409# Join a URL array (NAME) back into a string.
410ujoin() { # ujoin NAME:ARRAY 410ujoin() { # ujoin NAME:ARRAY
411 local -n U="$1" 411 local -n U="$1"
412 412
@@ -431,9 +431,28 @@ ujoin() { # ujoin NAME:ARRAY
431 log d "${U[0]}" 431 log d "${U[0]}"
432} 432}
433 433
434ucdef() { [[ "${!1}" != "$UC_BLANK" ]]; } # ucdef NAME 434# Three small utility functions for dealing with URL components.
435ucblank() { [[ -z "${!1}" ]]; } # ucblank NAME 435#
436ucset() { # ucset NAME VALUE 436# `ucdef' checks whether a URL component is blank or not -- if a component
437# doesn't exist, `usplit' writes $UC_BLANK there instead (which is :?: by
438# default, though it really doesn't matter much *what* it is, as long as it's
439# not going to really be in a URL). I tried really hard to differentiate an
440# unset array element from a simply empty one, but like, as far as I could tell,
441# you can't do that in Bash.
442ucdef() { # ucdef NAME
443 [[ "${!1}" != "$UC_BLANK" ]]
444}
445
446# `ucblank' determines whether a URL component is blank (""), as opposed to
447# undefined.
448ucblank() { # ucblank NAME
449 [[ -z "${!1}" ]]
450}
451
452# `ucset' sets one component of a URL array and setting the 0th element to the
453# new full URL. Use it instead of directly setting the array element with U[x],
454# because U[0] will fall out of sync with the rest of the contents.
455ucset() { # ucset NAME VALUE
437 run eval "${1}='$2'" 456 run eval "${1}='$2'"
438 run ujoin "${1/\[*\]/}" 457 run ujoin "${1/\[*\]/}"
439} 458}