Skip to content

Commit

Permalink
GH-15: add dasht-docsets-inherit to make symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaku committed Aug 7, 2016
1 parent 5cfdd5b commit 81a574d
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
85 changes: 85 additions & 0 deletions bin/dasht-docsets-inherit
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/sh -e
#
# # DASHT-DOCSETS-INHERIT 1 2016-05-28 2.1.0
#
# ## NAME
#
# dasht-docsets-inherit - inherits [Dash] docsets from other locations
#
# ## SYNOPSIS
#
# `dasht-docsets-inherit` [*OPTION*...] [*LOCATION*...]
#
# ### Examples
#
# `dasht-docsets-inherit`
# Inherits existing docsets from [Dash], [Zeal], and [helm-dash].
#
# `dasht-docsets-inherit` /some/location/here
# Inherits existing docsets found in or under `/some/location/here`.
#
# `dasht-docsets-inherit` location1 location2
# Inherits existing docsets found in or under `location1` and `location2`.
#
# ## DESCRIPTION
#
# Inherits existing [Dash] docsets found in or under the given *LOCATION*s.
# If no *LOCATION*s are given, then the default docset installation locations
# for [Dash], [Zeal], and [helm-dash] will be searched. Unless this operation
# is forced, you will be prompted to confirm it for every inheritable docset.
#
# If the name of a parent directory of an existing docset contains only digits
# and dashes, then it is considered to be a version number. This number will
# be appended to the inherited docset's name preceded by an "@" symbol. In
# particular, "versioned docsets" inherited from [Dash] undergo this renaming.
#
# ## OPTIONS
#
# `-f`, `--force`
# Forces the operation by overriding the interactive confirmation prompt.
#
# ## ENVIRONMENT
#
# `DASHT_DOCSETS_DIR`
# Defines the filesystem location where your [Dash] docsets are inherited.
# 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/`.
#
# ## SEE ALSO
#
# dasht-docsets-install(1), dasht-docsets-remove(1), dasht-docsets(1), [Dash]
#
# [Dash]: https://kapeli.com/dash
# [Zeal]: https://zealdocs.org
# [helm-dash]: https://github.com/areina/helm-dash
#
# ## AUTHOR
#
# Written in 2016 by Suraj N. Kurapati <https://github.com/sunaku/dasht>
# Distributed under the terms of the ISC license (see the LICENSE file).

: ${DASHT_DOCSETS_DIR:=${XDG_DATA_HOME:-$HOME/.local/share}/dasht/docsets}

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

# supply default locations
test $# -eq 0 && set -- \
"${XDG_DATA_HOME:-$HOME/.local/share}/Zeal/Zeal/docsets" \
"$HOME/Library/Application Support/Dash" \
"$HOME/.docsets"

trap exit INT # let Control-C abort `xargs -p` when running under bash(1)
find "$@" -name '*.docset' | while read -r location; do
# determine the name of the docset along with its version number if any
rootname=${location%.docset}
dirname=${location%/*}
version=${dirname##*/}
docset=${rootname##*/}
echo "$version" | grep -E -q '^[0-9-]+$' && docset="$docset@$version"

test -n "$force" || # don't ask for confirmation when it's being forced
echo "Inherit $docset docset [y/N]" | xargs -p | grep -q . || continue

target="$DASHT_DOCSETS_DIR/$docset.docset"
ln -v -s -f "$location" "$target"
done
48 changes: 48 additions & 0 deletions man/man1/dasht-docsets-inherit.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.TH DASHT\-DOCSETS\-INHERIT 1 2016\-05\-28 2.1.0
.SH NAME
.PP
dasht\-docsets\-inherit \- inherits Dash \[la]https://kapeli.com/dash\[ra] docsets from other locations
.SH SYNOPSIS
.PP
\fB\fCdasht\-docsets\-inherit\fR [\fIOPTION\fP\&...] [\fILOCATION\fP\&...]
.SS Examples
.TP
\fB\fCdasht\-docsets\-inherit\fR
Inherits existing docsets from Dash \[la]https://kapeli.com/dash\[ra], Zeal \[la]https://zealdocs.org\[ra], and helm\-dash \[la]https://github.com/areina/helm-dash\[ra]\&.
.TP
\fB\fCdasht\-docsets\-inherit\fR /some/location/here
Inherits existing docsets found in or under \fB\fC/some/location/here\fR\&.
.TP
\fB\fCdasht\-docsets\-inherit\fR location1 location2
Inherits existing docsets found in or under \fB\fClocation1\fR and \fB\fClocation2\fR\&.
.SH DESCRIPTION
.PP
Inherits existing Dash \[la]https://kapeli.com/dash\[ra] docsets found in or under the given \fILOCATION\fPs.
If no \fILOCATION\fPs are given, then the default docset installation locations
for Dash \[la]https://kapeli.com/dash\[ra], Zeal \[la]https://zealdocs.org\[ra], and helm\-dash \[la]https://github.com/areina/helm-dash\[ra] will be searched. Unless this operation
is forced, you will be prompted to confirm it for every inheritable docset.
.PP
If the name of a parent directory of an existing docset contains only digits
and dashes, then it is considered to be a version number. This number will
be appended to the inherited docset's name preceded by an "@" symbol. In
particular, "versioned docsets" inherited from Dash \[la]https://kapeli.com/dash\[ra] undergo this renaming.
.SH OPTIONS
.TP
\fB\fC\-f\fR, \fB\fC\-\-force\fR
Forces the operation by overriding the interactive confirmation prompt.
.SH ENVIRONMENT
.TP
\fB\fCDASHT_DOCSETS_DIR\fR
Defines the filesystem location where your Dash \[la]https://kapeli.com/dash\[ra] docsets are inherited.
If undefined, its value is assumed to be \fB\fC$XDG_DATA_HOME/dasht/docsets/\fR
or, if \fB\fCXDG_DATA_HOME\fR is undefined, \fB\fC$HOME/.local/share/dasht/docsets/\fR\&.
.SH SEE ALSO
.PP
.BR dasht-docsets-install (1),
.BR dasht-docsets-remove (1),
.BR dasht-docsets (1),
Dash \[la]https://kapeli.com/dash\[ra]
.SH AUTHOR
.PP
Written in 2016 by Suraj N. Kurapati \[la]https://github.com/sunaku/dasht\[ra]
Distributed under the terms of the ISC license (see the LICENSE file).

0 comments on commit 81a574d

Please sign in to comment.