about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xbollux29
1 files changed, 22 insertions, 7 deletions
diff --git a/bollux b/bollux index 7ed4ae1..68eade9 100755 --- a/bollux +++ b/bollux
@@ -113,6 +113,8 @@ bollux_config() {
113 : "${BOLLUX_LESSKEY:=/tmp/bollux-lesskey}" # where to store binds 113 : "${BOLLUX_LESSKEY:=/tmp/bollux-lesskey}" # where to store binds
114 : "${BOLLUX_PAGESRC:=/tmp/bollux-src}" # where to save the page source 114 : "${BOLLUX_PAGESRC:=/tmp/bollux-src}" # where to save the page source
115 : "${BOLLUX_URL:=}" # start url 115 : "${BOLLUX_URL:=}" # start url
116 : "${BOLLUX_DATADIR:=${XDG_DATA_DIR:-$HOME/.local/share}/bollux}"
117 BOLLUX_HISTFILE="$BOLLUX_DATADIR/history" # where to store the history
116 ## typesetting 118 ## typesetting
117 : "${T_MARGIN:=4}" # left and right margin 119 : "${T_MARGIN:=4}" # left and right margin
118 : "${T_WIDTH:=0}" # width of the viewport -- 0 = get term width 120 : "${T_WIDTH:=0}" # width of the viewport -- 0 = get term width
@@ -323,15 +325,26 @@ handle_response() {
323 case "$code" in 325 case "$code" in
324 1*) 326 1*)
325 REDIRECTS=0 327 REDIRECTS=0
326 run history_append "$URL" 328 run history_append "$URL" "$meta"
327 run prompt "$meta" QUERY 329 run prompt "$meta" QUERY
328 # shellcheck disable=2153 330 # shellcheck disable=2153
329 run blastoff "?$QUERY" 331 run blastoff "?$QUERY"
330 ;; 332 ;;
331 2*) 333 2*)
332 REDIRECTS=0 334 REDIRECTS=0
333 run history_append "$URL" 335 # read ahead to find a title
334 run display "$meta" 336 while read -r; do
337 printf -v pretitle "%s\n" "$REPLY"
338 if [[ "$REPLY" =~ ^#[[:space:]]*(.*) ]]; then
339 title="${BASH_REMATCH[1]}"
340 break
341 fi
342 done
343 run history_append "$URL" "$title"
344 {
345 printf '%s' "$pretitle"
346 while read -r; do printf '%s\n' "$REPLY"; done
347 } | run display "$meta"
335 ;; 348 ;;
336 3*) 349 3*)
337 ((REDIRECTS += 1)) 350 ((REDIRECTS += 1))
@@ -653,12 +666,14 @@ download() {
653history_init() { 666history_init() {
654 declare -a HISTORY # history is kept in an array 667 declare -a HISTORY # history is kept in an array
655 HN=0 # position of history in the array 668 HN=0 # position of history in the array
669 run mkdir -p "${BOLLUX_HISTFILE%/*}"
656} 670}
657 671
658history_append() { # history_append URL 672history_append() { # history_append URL TITLE
659 BOLLUX_URL="$1" 673 BOLLUX_URL="$1"
674 # date/time, url, title (best guess)
675 run printf '%(%FT%T)T\t%s\t%s\n' -1 "$1" "$2" >>"$BOLLUX_HISTFILE"
660 HISTORY[$HN]="$BOLLUX_URL" 676 HISTORY[$HN]="$BOLLUX_URL"
661 log d "HN=$HN HISTORY: ${HISTORY[*]}"
662 ((HN += 1)) 677 ((HN += 1))
663} 678}
664 679
@@ -670,7 +685,7 @@ history_back() {
670 log e "Beginning of history." 685 log e "Beginning of history."
671 return 1 686 return 1
672 fi 687 fi
673 blastoff "${HISTORY[$HN]}" 688 run blastoff "${HISTORY[$HN]}"
674} 689}
675history_forward() { 690history_forward() {
676 log d "HN=$HN" 691 log d "HN=$HN"
@@ -679,7 +694,7 @@ history_forward() {
679 log e "End of history." 694 log e "End of history."
680 return 1 695 return 1
681 fi 696 fi
682 blastoff "${HISTORY[$HN]}" 697 run blastoff "${HISTORY[$HN]}"
683} 698}
684 699
685if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then 700if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then