commit 4e97657f6c93beac2491ea03a961ee05d3756dfa
parent 1a3110090d7bd1d99c64c85bda63b61161493837
Author: René Wagner <rwa@clttr.info>
Date: Fri, 17 Dec 2021 16:53:39 +0100
make cachehome configurable
allow users to configure their cache home to move
it out of their default cache in their user profile.
This might especially be usefull to move the cache
to a memory-backed tmpfs or similar.
Diffstat:
M | README.md | | | 7 | ++++++- |
M | astro | | | 44 | +++++++++++++++++++++++--------------------- |
2 files changed, 29 insertions(+), 22 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
@@ -192,7 +192,7 @@ fetch() {
# Success
[ "$debug" ] && echo "Success, reading body"
- [ -f "$cachedir/links.txt" ] && rm "$cachedir/links.txt"
+ [ -f "$linkfile" ] && rm "$linkfile"
# Set charset
charset="$(echo "$meta" | grep -i "charset=" | sed -e 's/.*charset=\([^;]\+\).*/\1/Ig')"
@@ -222,7 +222,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" >> "$linkfile"
# shellcheck disable=SC2086
line="$(echo $link | cut -d' ' -f2-)"
@@ -259,10 +259,10 @@ fetch() {
50) url="$1://$2:$3/$4" ;;
51)
# Follow link
- cat -n "$cachedir/links.txt"
+ cat -n "$linkfile"
printf "Enter link number: "
read -r i <&1
- url="$(sed "${i}q;d" "$cachedir/links.txt" | cut -d' ' -f1)"
+ url="$(sed "${i}q;d" "$linkfile" | cut -d' ' -f1)"
;;
52) url="$(getprevious)" ;;
53) url="$homepage"; shift $# ;;
@@ -313,10 +313,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"
+linkfile="$cachedir/links"
# move old bookmark file to new location
if [ -f "$cachedir/bookmarks" ] && [ ! -f "$bookmarkfile" ]
@@ -327,7 +344,7 @@ fi
LESSKEY="$confighome/astro/less.keys"
# Restore terminal
-trap "tput rmcup && rm $histfile; exit" EXIT INT HUP
+trap "tput rmcup && rm $histfile $linkfile; exit" EXIT INT HUP
# This is the final binary form, to save space, it corresponds to:
# o (49): go to a URL
@@ -340,21 +357,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/"