-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for using existing Dash.app docsets #53
base: master
Are you sure you want to change the base?
Changes from all commits
1f9d853
a992bec
a5bac0d
83e2a6f
be94464
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/sh -e | ||
# | ||
# # DASHT-DOCSETS-INHERIT 1 2020-05-16 2.4.0 | ||
# | ||
# ## NAME | ||
# | ||
# dasht-docsets-inherit - unpack docsets from Dash.app | ||
# | ||
# ## SYNOPSIS | ||
# | ||
# `dasht-docsets-inherit` [*NAME*...] | ||
# | ||
# ### Examples | ||
# | ||
# `dasht-docsets-inherit` | ||
# Unpack all installed Dash.app docsets. | ||
# | ||
# `dasht-docsets-inherit` sh | ||
# Unpack Dash.app docsets whose names contain "sh". | ||
# | ||
# `dasht-docsets` sh 'c$' | ||
# Unpack Dash.app docsets whose names contain "sh" or end in "c". | ||
# | ||
# ## DESCRIPTION | ||
# | ||
# Unpack specified Dash.app docsets. This is necessary to use the Docsets with | ||
# `dasht`. Docsets are specified by passing one or more name filters as | ||
# arguments, which are matched against docset names. If no filters are | ||
# specified, all docsets are unpacked. Note that `DASHT_USE_DASH_APP` must be | ||
# set to `true` for this script to execute. | ||
# | ||
# ## ENVIRONMENT | ||
# | ||
# `DASHT_USE_DASH_APP` | ||
# Set to "true" to use Dash.app's (MacOS only) docset library. Disables | ||
# docset management commands (install, remove, update). Also changes the | ||
# default `DASHT_DOCSETS_DIR` to "~/Library/Application Support/Dash". | ||
# | ||
# ## EXIT STATUS | ||
# | ||
# 44 | ||
# No results were found. | ||
# 46 | ||
# Command was not executed because `DASHT_USE_DASH_APP` is not set. | ||
# | ||
# ## SEE ALSO | ||
# | ||
# dasht-docsets(1), [Dash] | ||
# | ||
# [Dash]: https://kapeli.com/dash | ||
# | ||
# ## AUTHOR | ||
# | ||
# Written in 2016 by Suraj N. Kurapati <https://github.com/sunaku/dasht> | ||
# Distributed under the terms of the ISC license (refer to README file). | ||
|
||
: ${DASHT_USE_DASH_APP:=false} | ||
if $DASHT_USE_DASH_APP; then | ||
: ${DASHT_DOCSETS_DIR:="$HOME/Library/Application Support/Dash"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the user to set the |
||
else | ||
exit 46 | ||
fi | ||
|
||
# Ensure any docsets we are accessing from the Dash.app library have had their | ||
# documents extracted. Dash.app leaves the documents in the tarball by default. | ||
dasht-docsets "$@" | while read docset; do | ||
for root in "$DASHT_DOCSETS_DIR"/*/*/"$docset".docset; do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think KAPELI_DASH_DIR="$HOME/Library/Application Support/Dash"
# ...
if test -e "$KAPELI_DASH_DIR"; then
for root in "$KAPELI_DASH_DIR"/*/*/"$docset".docset; do
# ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's probably better for you to make the changes, because it seems like we have somewhat different architectural ideas about the interface, and I think if I made just the changes you requested, it would leave the project with a weird mixture-- if you want to move in the requested direction, you'll probably need to adjust some of my other changes as well. So I'll explain the overall design I followed, then you can do what you want with it. When making my changes, this was my thinking: the user is using Similarly, I was also a bit confused by the name It seems to me that your vision is better suited to a system where, rather than having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well said! 💯 You've understood my vision correctly and, thanks to your clear explanation, I now realize that I didn't quite understand your approach in this PR until now. 😅 Let me think more about how to reconcile our different approaches. 🤔 One of the reasons for my knowledge gap is that I don't have access to (and have never actually used) the Dash for macOS app firsthand. So I don't know how Dash organizes its docsets on the filesystem nowadays, other than from a helpful (but now possibly outdated) user-provided tip in #15 (comment). In particular, since you intended to extract Dash's docsets directly within its own internal area (as opposed to dasht's I'm intrigued by the latter possibility 🤓 and am curious to try implementing a very basic, shell scripted version thereof. A direct consequence of this would be that Could you help me understand how Dash organizes its docsets on your system? A simple diagram, such as the output of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad I could clear things up! Since the initial work on this was done close to a year ago, I don't remember everything I learned about Dash.app's internal organization of docsets when I started work on this, but I remember being surprised that I couldn't find extracted versions of the docsets in Dash's saved data. I don't know how it accesses the tarball content, I assumed it uses some library I was unaware of for reading tarballs directly, and since this was a shell script project, I didn't investigate further. Here's an example of the structure of a DocSet as Dash stores it:
And attached is the full output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the detailed report! 🙇 There seems to be a mixture of fully extracted docsets (which is what dasht currently uses) as well as unextracted Could you inspect the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That mixture is there because I use my fork of Here's a link to a tarixIndex.db file, it's a SQLite database (Github won't let me attach this file type directly to the issue). https://file.io/1Lsva6fX1MLA |
||
if ! test -d "${root}/Contents/Resources/Documents"; then | ||
dasht-docsets-extract "$root/Contents/Resources/tarix.tgz" | ||
fi | ||
done | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,11 @@ | |
# If undefined, its value is assumed to be `$XDG_DATA_HOME/dasht/docsets/` | ||
# or, if `XDG_DATA_HOME` is undefined, `$HOME/.local/share/dasht/docsets/`. | ||
# | ||
# `DASHT_USE_DASH_APP` | ||
# Set to "true" to use Dash.app's (MacOS only) docset library. Disables | ||
# docset management commands (install, remove, update). Also changes the | ||
# default `DASHT_DOCSETS_DIR` to "~/Library/Application Support/Dash". | ||
# | ||
# ## EXIT STATUS | ||
# | ||
# 44 | ||
|
@@ -86,7 +91,12 @@ | |
# Written in 2016 by Suraj N. Kurapati <https://github.com/sunaku/dasht> | ||
# Distributed under the terms of the ISC license (refer to README file). | ||
|
||
: ${DASHT_DOCSETS_DIR:=${XDG_DATA_HOME:-$HOME/.local/share}/dasht/docsets} | ||
: ${DASHT_USE_DASH_APP:=false} | ||
if $DASHT_USE_DASH_APP; then | ||
: ${DASHT_DOCSETS_DIR:="$HOME/Library/Application Support/Dash"} | ||
else | ||
: ${DASHT_DOCSETS_DIR:=${XDG_DATA_HOME:-$HOME/.local/share}/dasht/docsets} | ||
fi | ||
|
||
pattern=$(echo " $1 " | sed -e 's/[%_]/\\&/g' -e 's/[[:space:]]\{1,\}/%/g') | ||
test $# -gt 0 && shift # shift off PATTERN so argv contains solely DOCSETs | ||
|
@@ -95,7 +105,12 @@ status=44 # (default) exit with a nonzero status when no results are found | |
trap 'status=0' USR1 # override default exit status when results are found | ||
|
||
dasht-docsets "$@" | while read -r docset; do | ||
database="$DASHT_DOCSETS_DIR/$docset".docset/Contents/Resources/docSet.dsidx | ||
if $DASHT_USE_DASH_APP; then | ||
relpath=("$DASHT_DOCSETS_DIR"/*/*/"$docset".docset) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
database="$relpath/Contents/Resources/docSet.dsidx" | ||
else | ||
database="$DASHT_DOCSETS_DIR/$docset".docset/Contents/Resources/docSet.dsidx | ||
fi | ||
file_url="file://$(dirname "$database")/Documents/" | ||
|
||
dasht-query-exec "$pattern" "$database" -line | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good refactoring, but I don't think
dasht
should be calling thedasht-docsets-inherit
script at all -- that should be left up to the user to run, if they choose. So I would remove this entire if-statement fromdasht
.