Skip to content

Commit

Permalink
better help, add uninstall using rc file
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Lai <[email protected]>
  • Loading branch information
soraxas committed Jul 13, 2020
1 parent 3a5fced commit b5eef18
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 54 deletions.
9 changes: 9 additions & 0 deletions completions/shsh.fish
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ complete -f -c shsh -n '__fish_shsh_needs_command' -l version -d "Show version n
complete -f -c shsh -n "__fish_shsh_using_command list" -s d -l details -d "display more details of packages"
complete -f -c shsh -n "__fish_shsh_using_command upgrade" -s a -l all -d "performs on all packages"
complete -f -c shsh -n "__fish_shsh_using_command refresh" -s a -l all -d "performs on all packages"

complete -f -c shsh -n "__fish_shsh_using_command install" -s h -l hook -d "add hook to the package"
complete -f -c shsh -n "__fish_shsh_using_command install" -s v -l variable -d "set a variable during installation"
complete -f -c shsh -n "__fish_shsh_using_command install" -s f -l force -d "force the installation even if the package exists"
complete -f -c shsh -n "__fish_shsh_using_command install" -l nocleanup -d "do not perform cleanup"
complete -f -c shsh -n "__fish_shsh_using_command install" -l ssh -d "use ssh protocal instead of https"

complete -f -c shsh -n "__fish_shsh_using_command uninstall" -l use-rc -d "uninstall all packages not present in SHSHRC"
complete -f -c shsh -n "__fish_shsh_using_command uninstall" -l noconfirm -d "do not prompt to confirm"
4 changes: 2 additions & 2 deletions libexec/shsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# DEPS list of dependent packages to install beforehand
#
# Files:
# SHSHRC: The file `$XDG_CONFIG_HOME/shshrc` shall be an executable file
# SHSHRC: The file `$XDG_CONFIG_HOME/shshrc` shall be a plain-text file
# that store all installed packages. Whenever shsh install a package, it
# will add the package to SHSHRC. If there is an existing entry, it will
# update that entry with the new flags/argunment instead. It will search
Expand Down Expand Up @@ -125,7 +125,7 @@ for arg; do
;;
--version)
cat << EOF
shsh (shell script handler) v2.3.1
shsh (shell script handler) v2.3.2
Copyright (c) 2014 Juan Ibiapina, 2020 Tin Lai (@soraxas)
This is free software; see the source for copying conditions. There is NO
Expand Down
34 changes: 34 additions & 0 deletions libexec/shsh-_utils
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,38 @@ requote_args() {
fi
done
printf "%s" "$C"
}

prompt () {
echo -n "$1 [y/N]? "
read answer
while true; do
case $answer in
y|Y|yes|YES) return 0;;
''|n|N|no|NO) return 1;;
*)
echo 'Invalid response';
echo -n "$1 [y/N]? "
read answer;;
esac
done
}

shshrc_get_existing_install_cmd() {
set +e
unset existing
unset existing_prefix
unset existing_suffix
# given $1 as the package name, return the existing line in SHSHRC that installs
# that package
if [ -e "$SHSHRC" ]; then
existing="$(grep -E "^\s*shsh install (.*\s+)?$1(\s.*)?$" "$SHSHRC")"
# extract suffix if any (e.g. '&& \' or '|| \')
_ending_pattern='\s+([&][&]|[|][|])\s*[\]\s*$'
existing_suffix="$(echo "$existing" | grep -oE "$_ending_pattern")"
# extract prefix if any (i.e. white spaces)
existing_prefix="$(echo "$existing" | grep -oE "^\s*")"
# remove these from the statement for comparison
existing="$(echo "$existing" | sed -E "s/$_ending_pattern//; s/^(\s*)//")"
fi
}
2 changes: 1 addition & 1 deletion libexec/shsh-help
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ collect_documentation() {
next
}
/^( *$| )/ && reading_usage {
/^( *$| | +or: +)/ && reading_usage {
usage = usage "\n" $0
next
}
Expand Down
9 changes: 1 addition & 8 deletions libexec/shsh-install
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,7 @@ shsh-_link-completions "$folder"
# add successfully installed package to shshrc
if [ -e "$SHSHRC" ]; then
set +e # allow non-zero exit status in pattern matching
existing="$(grep -E "^\s*shsh install $1(\s.*)?$" "$SHSHRC")"
# extract suffix if any (e.g. '&& \' or '|| \')
_ending_pattern='\s+([&][&]|[|][|])\s*[\]\s*$'
existing_suffix="$(echo "$existing" | grep -oE "$_ending_pattern")"
# extract prefix if any (i.e. white spaces)
existing_prefix="$(echo "$existing" | grep -oE "^\s*")"
# remove these from the statement for comparison
existing="$(echo "$existing" | sed -E "s/$_ending_pattern//; s/^(\s*)//")"
shshrc_get_existing_install_cmd "$package"
new_statement="shsh install $original_args"

if [ -z "$existing" ]; then
Expand Down
48 changes: 47 additions & 1 deletion libexec/shsh-uninstall
Original file line number Diff line number Diff line change
@@ -1,16 +1,62 @@
#!/usr/bin/env sh
# Summary: Uninstalls a package
# Usage: shsh uninstall <package>
# or: shsh uninstall --use-rc [--noconfirm]
#
# Options:
# --use-rc uninstall all packages that is not present in SHSHRC file
# --noconfirm do not prompt to confirm uninstalling each package

set -e

. "${UTILS_FUNC:?}"

if [ "$#" -ne 1 ]; then
for arg; do
shift
case "$arg" in
--use-rc|--rc)
use_rc_file="true"
;;
--noconfirm|--no-confirm)
noconfirm="true"
;;
-*)
shsh-help uninstall
exit 1
;;
*)
set -- "$@" "$arg"
;;
esac
done

if [ "$#" -ne 1 ] && [ -z "$use_rc_file" ]; then
shsh-help uninstall
exit 1
fi

if [ -n "$use_rc_file" ] && [ "$#" -ne 0 ]; then
shsh-help uninstall
exit 1
fi

# using SHSHRC file
if [ -n "$use_rc_file" ]; then
for package in $(shsh list); do
set +e
shshrc_get_existing_install_cmd "$package"
set -e

if [ -z "$existing" ]; then
if [ -n "$noconfirm" ] || prompt "Uninstall $package?"; then
echo "> Uninstalling $package"
shsh uninstall "$package"
fi
fi
done
exit
fi

# TAG completions
if [ "$1" = "--complete" ]; then
exec shsh-list
Expand Down
8 changes: 7 additions & 1 deletion libexec/shsh-upgrade
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env sh
# Summary: Upgrades a package
# Usage: shsh upgrade <package|[-a|--all]>
#
# Usage: shsh upgrade <package>
# or: shsh upgrade <-a|--all>
#
# Options:
# -a, --all upgrade all packages, instead of invidivual package


set -e

Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-cleanup.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,cleanup\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-commands.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,commands\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-completions.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,completions <command>\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-help.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,help \/\fR[\fI\,--usage\/\fR] \fI\,COMMAND\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-init.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B eval
\fI\,"$(shsh init SHELL)"\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-install.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,install \/\fR[\fI\,site\/\fR]\fI\,/<package>\/\fR[\fI\,@ref\/\fR] [\fI\,<folder>/<folder>\/\fR]
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-link.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,link \/\fR[\fI\,--no-deps\/\fR] \fI\,<directory> <package>\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-list.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,list \/\fR[\fI\,-d|--details\/\fR]
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-outdated.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,outdated \/\fR[\fI\,-q|--quiet\/\fR]
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-package-path.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B source
\fI\,"$(shsh package-path <package>)/file.sh"\/\fR
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-refresh.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,refresh <package> \/\fR[\fI\,--verbose\/\fR] [\fI\,-a|--all\/\fR]
Expand Down
4 changes: 2 additions & 2 deletions man/man1/shsh-self-upgrade.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,self-upgrade\/\fR
Expand Down
16 changes: 12 additions & 4 deletions man/man1/shsh-uninstall.1
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,uninstall <package>\/\fR
.br
.B shsh
\fI\,uninstall --use-rc \/\fR[\fI\,--noconfirm\/\fR]
.SH DESCRIPTION
Uninstalls a package
.PP
Uninstalls a package
.SH OPTIONS
.TP
\fB\-\-use\-rc\fR
uninstall all packages that is not present in SHSHRC file
.TP
\fB\-\-noconfirm\fR
do not prompt to confirm uninstalling each package
.SH AUTHOR
Written by Tin Lai (@soraxas)
.SH COPYRIGHT
Expand Down
15 changes: 10 additions & 5 deletions man/man1/shsh-upgrade.1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.15.
.TH SHSH "1" "July 2020" "shell script handler v2.3.1" "User Commands"
.TH SHSH "1" "July 2020" "shell script handler v2.3.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.3.1
shsh \- manual page for shsh v2.3.2
.SH SYNOPSIS
.B shsh
\fI\,upgrade <package|\/\fR[\fI\,-a|--all\/\fR]\fI\,>\/\fR
\fI\,upgrade <package>\/\fR
.br
.B shsh
\fI\,upgrade <-a|--all>\/\fR
.SH DESCRIPTION
Upgrades a package
.PP
Upgrades a package
.SH OPTIONS
.TP
\fB\-a\fR, \fB\-\-all\fR
upgrade all packages, instead of invidivual package
.SH AUTHOR
Written by Tin Lai (@soraxas)
.SH COPYRIGHT
Expand Down
Loading

0 comments on commit b5eef18

Please sign in to comment.