Skip to content

Commit 1f3e3d0

Browse files
committed
notify user when no docsets installed for searching
1 parent 5be71a8 commit 1f3e3d0

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

bin/dasht

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
# 44
5454
# No results were found.
5555
#
56+
# 45
57+
# No docsets were installed for searching.
58+
#
5659
# ## SEE ALSO
5760
#
5861
# w3m(1), dasht-query-html(1), dasht-docsets(1), [Dash]
@@ -64,10 +67,22 @@
6467
# Written in 2016 by Suraj N. Kurapati <https://github.com/sunaku/dasht>
6568
# Distributed under the terms of the ISC license (see the LICENSE file).
6669

70+
if test $# -gt 0; then
71+
pattern=$1
72+
shift
73+
fi
74+
75+
count=$(dasht-docsets "$@" | wc -l)
76+
if test $count -eq 0; then
77+
# notify user when no docsets are installed so they can go install them
78+
echo "dasht: '$*' docsets not installed so '$pattern' not searched" >&2
79+
exit 45
80+
fi
81+
6782
trap 'exit 44' USR1 # exit with a nonzero status when no results are found
68-
if ! dasht-query-html "$@"; then
83+
if ! dasht-query-html "$pattern" "$@"; then
6984
# notify user when no results are found so they can refine their search
70-
pat=$1; shift; echo "dasht: '$pat' not found in ${*:-any} docsets" >&2
85+
echo "dasht: '$pattern' not found in $count docsets matching '${*:-.*}'" >&2
7186

7287
# emulate pipefail (which POSIX lacks) by killing off the w3m(1) process
7388
# below (which starts up simultaneously alongside this pipeline segment)

bin/dasht-server-http

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,13 @@ cat <<HEADER
181181
<br>
182182
HEADER
183183

184-
dasht-query-html "$query" $docsets ||
185-
echo "<h1><i>$query_html</i> not found in ${docsets_html:-any} docsets</h1>"
184+
if test $1 -eq 0; then
185+
# notify user when no docsets are installed so they can go install them
186+
echo "<h1><i>${docsets_html}</i> docsets not installed so <i>$query_html</i> not searched</h1>"
187+
elif ! dasht-query-html "$query" $docsets; then
188+
# notify user when no results are found so they can refine their search
189+
echo "<h1><i>$query_html</i> not found in $1 docsets matching <i>${docsets_html:-.*}</i></h1>"
190+
fi
186191

187192
cat <<FOOTER
188193
</body>

man/man1/dasht.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ or, if \fB\fCXDG_DATA_HOME\fR is undefined, \fB\fC$HOME/.local/share/dasht/docse
4747
.TP
4848
44
4949
No results were found.
50+
.TP
51+
45
52+
No docsets were installed for searching.
5053
.SH SEE ALSO
5154
.PP
5255
.BR w3m (1),

0 commit comments

Comments
 (0)