astro

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.clttr.info/astro.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit a1cae9b4dc2bc8fbda9649f8dd7109fa22b57ef3
parent 1a3110090d7bd1d99c64c85bda63b61161493837
Author: Brian Mayer <bleemayer@gmail.com>
Date:   Sun, 19 Dec 2021 12:52:05 -0300

Merge pull request #12 from guzzisti/main

make cachehome configurable
Diffstat:
MREADME.md | 7++++++-
Mastro | 52++++++++++++++++++++++++++++------------------------
2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md @@ -54,9 +54,14 @@ More coming. You can setup a config file at `~/.config/astro/astro.conf` to configure *astro* the way you like. -The file uses a simple `key=value` style, see the complete example for the default values below. The `style-` keys must be ANSI style codes. +The file uses a simple `key=value` style, see the complete example for the default values below. + +**hints:** +* `astro` will be appended to `cachehome`, the directory must be writable for your user. +* The `style-` keys must be ANSI style codes. ``` +cachehome=~/.cache/ margin=8 homepage=gemini.circumlunar.space style-header1=35;4;1 diff --git a/astro b/astro @@ -35,7 +35,7 @@ usage() { } version() { - echo "astro 0.10.0" + echo "astro 0.14.0" echo "Copyright (C) 2021 Brian Mayer." echo "License MIT: MIT License <https://opensource.org/licenses/MIT>" echo "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND," @@ -113,12 +113,13 @@ fetch() { fi echo "$1://$2:$3/$4$5" | eval openssl s_client \ - -connect "$2:$3" $certfile -crlf -quiet \ + -connect "$2:$3" "$certfile" -crlf -quiet \ -ign_eof 2> /dev/null | { # First line is status and meta information read -r status meta meta="$(echo "$meta" | tr -d '\r')" + # shellcheck disable=SC2030 [ "$debug" ] && echo "Response header: $status $meta" >&2 && sleep 1 # Validate @@ -192,7 +193,7 @@ fetch() { # Success [ "$debug" ] && echo "Success, reading body" - [ -f "$cachedir/links.txt" ] && rm "$cachedir/links.txt" + [ -f "$linksfile" ] && rm "$linksfile" # Set charset charset="$(echo "$meta" | grep -i "charset=" | sed -e 's/.*charset=\([^;]\+\).*/\1/Ig')" @@ -222,7 +223,7 @@ fetch() { "> "*) sty=" $sty_quote" && line="$(echo "$line" | cut -c 3-)" ;; "=>"*) link="$(echo "$line" | sed -e 's/^=> *\(\S\+\)\(\s*.*\)/\1 \2/g')" - echo "$link" >> "$cachedir/links.txt" + echo "$link" >> "$linksfile" # shellcheck disable=SC2086 line="$(echo $link | cut -d' ' -f2-)" @@ -259,10 +260,10 @@ fetch() { 50) url="$1://$2:$3/$4" ;; 51) # Follow link - cat -n "$cachedir/links.txt" + cat -n "$linksfile" printf "Enter link number: " read -r i <&1 - url="$(sed "${i}q;d" "$cachedir/links.txt" | cut -d' ' -f1)" + url="$(sed "${i}q;d" "$linksfile" | cut -d' ' -f1)" ;; 52) url="$(getprevious)" ;; 53) url="$homepage"; shift $# ;; @@ -313,10 +314,27 @@ bookmarkfile="$confighome/astro/bookmarks" certdir="$confighome/astro/certs" mkdir -p "$certdir" -cachehome=${XDG_CACHE_HOME:-$HOME/.cache} +# Configuration step +if [ -e "$configfile" ] +then + cachehome="$(grep cachehome "$configfile" | cut -d '=' -f 2,3)" + margin="$(grep margin "$configfile" | cut -d '=' -f 2,3)" + homepage="$(grep homepage "$configfile" | cut -d '=' -f 2,3)" + sty_header1="$(grep style-header1 "$configfile" | cut -d '=' -f 2-)" + sty_header2="$(grep style-header2 "$configfile" | cut -d '=' -f 2-)" + sty_header3="$(grep style-header3 "$configfile" | cut -d '=' -f 2-)" + sty_quote="$(grep style-quote "$configfile" | cut -d '=' -f 2-)" + sty_linkb="$(grep style-link-bullet "$configfile" | cut -d '=' -f 2-)" + sty_linkt="$(grep style-link-text "$configfile" | cut -d '=' -f 2-)" + sty_listb="$(grep style-list-bullet "$configfile" | cut -d '=' -f 2-)" + sty_listt="$(grep style-list-text "$configfile" | cut -d '=' -f 2-)" +fi + +[ -z "$cachehome" ] && cachehome=${XDG_CACHE_HOME:-$HOME/.cache} cachedir="$cachehome/astro" mkdir -p "$cachedir" histfile="$cachedir/history" +linksfile="$cachedir/links" # move old bookmark file to new location if [ -f "$cachedir/bookmarks" ] && [ ! -f "$bookmarkfile" ] @@ -327,7 +345,7 @@ fi LESSKEY="$confighome/astro/less.keys" # Restore terminal -trap "tput rmcup && rm $histfile; exit" EXIT INT HUP +trap 'tput rmcup && rm $histfile $linksfile; exit' EXIT INT HUP # This is the final binary form, to save space, it corresponds to: # o (49): go to a URL @@ -340,21 +358,6 @@ trap "tput rmcup && rm $histfile; exit" EXIT INT HUP [ -n "$LESSKEY" ] && echo "AE0rR2MjAG8AmDEAcgCYMgBnAJgzAGIAmDQASACYNQBtAJg2AE0AmDcAZQAAdgAAeEVuZA==" | \ base64 -d > "$LESSKEY" -# Configuration step -if [ -e "$configfile" ] -then - margin="$(grep margin "$configfile" | cut -d '=' -f 2,3)" - homepage="$(grep homepage "$configfile" | cut -d '=' -f 2,3)" - sty_header1="$(grep style-header1 "$configfile" | cut -d '=' -f 2-)" - sty_header2="$(grep style-header2 "$configfile" | cut -d '=' -f 2-)" - sty_header3="$(grep style-header3 "$configfile" | cut -d '=' -f 2-)" - sty_quote="$(grep style-quote "$configfile" | cut -d '=' -f 2-)" - sty_linkb="$(grep style-link-bullet "$configfile" | cut -d '=' -f 2-)" - sty_linkt="$(grep style-link-text "$configfile" | cut -d '=' -f 2-)" - sty_listb="$(grep style-list-bullet "$configfile" | cut -d '=' -f 2-)" - sty_listt="$(grep style-list-text "$configfile" | cut -d '=' -f 2-)" -fi - # Default values [ -z "$margin" ] && margin=8 [ -z "$homepage" ] && homepage="gemini.circumlunar.space/" @@ -377,7 +380,8 @@ sty_linkt="\\033[${sty_linkt}m" sty_listb="\\033[${sty_listb}m" sty_listt="\\033[${sty_listt}m" -[ -e "$debug" ] && { +# shellcheck disable=SC2031 +[ "$debug" ] && { echo "Starting with ${args:-$homepage}" echo " - margin: $margin" }