Skip to content

Commit 40c4bef

Browse files
committed
GH-23: Kapeli moved docset download links into Git
zealdocs/zeal#294 (comment)
1 parent 7de669c commit 40c4bef

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ which defines the filesystem location where your [Dash] docsets are installed.
135135
If undefined, its value is assumed to be `$XDG_DATA_HOME/dasht/docsets/` or,
136136
if `XDG_DATA_HOME` is also undefined, `$HOME/.local/share/dasht/docsets/`.
137137

138+
You may optionally configure the `DASHT_CACHE_DIR` environment variable,
139+
which defines the filesystem location where download links are cached.
140+
If undefined, its value is assumed to be `$XDG_CACHE_HOME/dasht/`
141+
or, if `XDG_CACHE_HOME` is also undefined, `$HOME/.cache/dasht/`.
142+
138143
## Development
139144

140145
If you make changes to the embedded manual pages found in the comment headers

bin/dasht-docsets-install

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
# If undefined, its value is assumed to be `$XDG_DATA_HOME/dasht/docsets/`
4040
# or, if `XDG_DATA_HOME` is undefined, `$HOME/.local/share/dasht/docsets/`.
4141
#
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+
#
4247
# ## SEE ALSO
4348
#
4449
# dasht-docsets-extract(1), dasht-docsets-update(1), dasht-docsets-remove(1),
@@ -52,17 +57,26 @@
5257
# Distributed under the terms of the ISC license (see the LICENSE file).
5358

5459
: ${DASHT_DOCSETS_DIR:=${XDG_DATA_HOME:-$HOME/.local/share}/dasht/docsets}
60+
: ${DASHT_CACHE_DIR:=${XDG_CACHE_HOME:-$HOME/.cache}/dasht}
5561

5662
test "$1" = '-f' -o "$1" = '--force' && force=1 && shift || unset force
5763

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")
6276

63-
# extract and filter installable docset names from the download links page
77+
# extract and filter installable docset names from the download links list
6478
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' |
6680
sort -u |
6781
grep -E -i "$(IFS='|'; echo "$*")" |
6882
sed "$(dasht-docsets | awk '{ print "/^" $0 "$/d" }')" # exclude installed

man/man1/dasht-docsets-install.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Forces the operation by overriding the interactive confirmation prompt.
3232
Defines the filesystem location where your Dash \[la]https://kapeli.com/dash\[ra] docsets are installed.
3333
If undefined, its value is assumed to be \fB\fC$XDG_DATA_HOME/dasht/docsets/\fR
3434
or, if \fB\fCXDG_DATA_HOME\fR is undefined, \fB\fC$HOME/.local/share/dasht/docsets/\fR\&.
35+
.TP
36+
\fB\fCDASHT_CACHE_DIR\fR
37+
Defines the filesystem location where download links are cached.
38+
If undefined, its value is assumed to be \fB\fC$XDG_CACHE_HOME/dasht/\fR
39+
or, if \fB\fCXDG_CACHE_HOME\fR is also undefined, \fB\fC$HOME/.cache/dasht/\fR\&.
3540
.SH SEE ALSO
3641
.PP
3742
.BR dasht-docsets-extract (1),

0 commit comments

Comments
 (0)