|
39 | 39 | # If undefined, its value is assumed to be `$XDG_DATA_HOME/dasht/docsets/` |
40 | 40 | # or, if `XDG_DATA_HOME` is undefined, `$HOME/.local/share/dasht/docsets/`. |
41 | 41 | # |
| 42 | +# `DASHT_CACHE_DIR` |
| 43 | +# Defines the filesystem location where download links are cached. |
| 44 | +# If undefined, its value is assumed to be `$XDG_CACHE_HOME/dasht/` |
| 45 | +# or, if `XDG_CACHE_HOME` is also undefined, `$HOME/.cache/dasht/`. |
| 46 | +# |
42 | 47 | # ## SEE ALSO |
43 | 48 | # |
44 | 49 | # dasht-docsets-extract(1), dasht-docsets-update(1), dasht-docsets-remove(1), |
|
52 | 57 | # Distributed under the terms of the ISC license (see the LICENSE file). |
53 | 58 |
|
54 | 59 | : ${DASHT_DOCSETS_DIR:=${XDG_DATA_HOME:-$HOME/.local/share}/dasht/docsets} |
| 60 | +: ${DASHT_CACHE_DIR:=${XDG_CACHE_HOME:-$HOME/.cache}/dasht} |
55 | 61 |
|
56 | 62 | test "$1" = '-f' -o "$1" = '--force' && force=1 && shift || unset force |
57 | 63 |
|
58 | | -# cache the docset download links page to avoid unnecessary network traffic |
59 | | -docset_links_cache="$DASHT_DOCSETS_DIR/docset_links" |
60 | | -wget -T 2 -t 1 -P "$DASHT_DOCSETS_DIR" -N https://kapeli.com/docset_links || |
61 | | -test -s "$docset_links_cache" |
| 64 | +# cache the docset download links list to avoid unnecessary network traffic |
| 65 | +cache() { |
| 66 | + url=$1 |
| 67 | + file="$DASHT_CACHE_DIR/${url##*/}" |
| 68 | + wget -T 2 -t 1 -P "${file%/*}" -N "$url" || test -s "$file" |
| 69 | + echo "$file" |
| 70 | +} |
| 71 | +master_url=https://api.github.com/repos/Kapeli/feeds/git/refs/heads/master |
| 72 | +master_cache=$(cache "$master_url") |
| 73 | +master_sha=$(sed -n 's/"sha"://p' "$master_cache" | tr -d '":, ') |
| 74 | +tree_url="https://api.github.com/repos/Kapeli/feeds/git/trees/$master_sha" |
| 75 | +tree_cache=$(cache "$tree_url") |
62 | 76 |
|
63 | | -# extract and filter installable docset names from the download links page |
| 77 | +# extract and filter installable docset names from the download links list |
64 | 78 | set -- $( |
65 | | - sed -n 's|.*/\([^/]*\)\.tgz.*|\1|p' "$docset_links_cache" | |
| 79 | + sed -n 's/"path"://p' "$tree_cache" | tr -d '":, ' | sed -n 's/.xml$//p' | |
66 | 80 | sort -u | |
67 | 81 | grep -E -i "$(IFS='|'; echo "$*")" | |
68 | 82 | sed "$(dasht-docsets | awk '{ print "/^" $0 "$/d" }')" # exclude installed |
|
0 commit comments