Skip to content

Commit

Permalink
add force option for install/remove automation
Browse files Browse the repository at this point in the history
The `xargs -p` prompt reads from /dev/tty so it's not easy to automate.
  • Loading branch information
sunaku committed Mar 9, 2016
1 parent 5408885 commit 26ced75
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
14 changes: 11 additions & 3 deletions bin/dasht-docsets-install
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# ## SYNOPSIS
#
# `dasht-docsets-install` [*NAME*...]
# `dasht-docsets-install` [*OPTION*...] [*NAME*...]
#
# ### Examples
#
Expand All @@ -24,8 +24,13 @@
# ## DESCRIPTION
#
# Installs new [Dash] docsets whose names match the *NAME* regex(7) patterns.
# If no *NAME*s are given, all new docsets currently available are matched.
# You are prompted to confirm this destructive operation for each match.
# If no *NAME*s are given, all new docsets available for install are matched.
# Unless forced, this operation prompts you to confirm it for every match.
#
# ## OPTIONS
#
# `-f`, `--force`
# Forces the operation by overriding the interactive confirmation prompt.
#
# ## ENVIRONMENT
#
Expand All @@ -48,6 +53,8 @@

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

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

# cache the docset download links page to avoid unnecessary network traffic
docset_links_cache="$DASHT_DOCSETS_DIR/docset_links"
wget -T 2 -t 1 -P "$DASHT_DOCSETS_DIR" -N https://kapeli.com/docset_links ||
Expand All @@ -64,6 +71,7 @@ printf "Installable docsets ($#):\n\n\t%s\n\n" "$(echo "$*" | sed 's/ /,&/g')"

trap exit INT # let Control-C abort `xargs -p` when running under bash(1)
for docset; do
test -n "$force" || # don't ask for confirmation when it's being forced
echo "Install $docset docset [y/N]" | xargs -p | grep -q . || continue

basename="$docset".tgz
Expand Down
14 changes: 11 additions & 3 deletions bin/dasht-docsets-remove
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# ## SYNOPSIS
#
# `dasht-docsets-remove` [*NAME*...]
# `dasht-docsets-remove` [*OPTION*...] [*NAME*...]
#
# ### Examples
#
Expand All @@ -24,8 +24,13 @@
# ## DESCRIPTION
#
# Removes installed [Dash] docsets whose names match the *NAME* regex(7)
# patterns. If no *NAME*s are given, all available docsets are matched.
# You are prompted to confirm this destructive operation for each match.
# patterns. If no *NAME*s are given, all installed docsets are matched.
# Unless forced, this operation prompts you to confirm it for every match.
#
# ## OPTIONS
#
# `-f`, `--force`
# Forces the operation by overriding the interactive confirmation prompt.
#
# ## ENVIRONMENT
#
Expand All @@ -47,11 +52,14 @@

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

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

set -- $(dasht-docsets "$@")
printf "Removable docsets ($#):\n\n\t%s\n\n" "$(echo "$*" | sed 's/ /,&/g')"

trap exit INT # let Control-C abort `xargs -p` when running under bash(1)
for docset; do
test -n "$force" || # don't ask for confirmation when it's being forced
echo "Remove $docset docset [y/N]" | xargs -p | grep -q . || continue

rootname="$DASHT_DOCSETS_DIR/$docset"
Expand Down
10 changes: 7 additions & 3 deletions man/man1/dasht-docsets-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
dasht\-docsets\-install \- installs new Dash \[la]https://kapeli.com/dash\[ra] docsets
.SH SYNOPSIS
.PP
\fB\fCdasht\-docsets\-install\fR [\fINAME\fP\&...]
\fB\fCdasht\-docsets\-install\fR [\fIOPTION\fP\&...] [\fINAME\fP\&...]
.SS Examples
.TP
\fB\fCdasht\-docsets\-install\fR
Expand All @@ -20,8 +20,12 @@ Installs new Dash \[la]https://kapeli.com/dash\[ra] docsets whose names contain
Installs new Dash \[la]https://kapeli.com/dash\[ra] docsets whose names match the \fINAME\fP
.BR regex (7)
patterns.
If no \fINAME\fPs are given, all new docsets currently available are matched.
You are prompted to confirm this destructive operation for each match.
If no \fINAME\fPs are given, all new docsets available for install are matched.
Unless forced, this operation prompts you to confirm it for every match.
.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
Expand Down
10 changes: 7 additions & 3 deletions man/man1/dasht-docsets-remove.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
dasht\-docsets\-remove \- removes installed Dash \[la]https://kapeli.com/dash\[ra] docsets
.SH SYNOPSIS
.PP
\fB\fCdasht\-docsets\-remove\fR [\fINAME\fP\&...]
\fB\fCdasht\-docsets\-remove\fR [\fIOPTION\fP\&...] [\fINAME\fP\&...]
.SS Examples
.TP
\fB\fCdasht\-docsets\-remove\fR
Expand All @@ -20,8 +20,12 @@ Removes installed Dash \[la]https://kapeli.com/dash\[ra] docsets whose names con
Removes installed Dash \[la]https://kapeli.com/dash\[ra] docsets whose names match the \fINAME\fP
.BR regex (7)

patterns. If no \fINAME\fPs are given, all available docsets are matched.
You are prompted to confirm this destructive operation for each match.
patterns. If no \fINAME\fPs are given, all installed docsets are matched.
Unless forced, this operation prompts you to confirm it for every match.
.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
Expand Down

0 comments on commit 26ced75

Please sign in to comment.