Skip to content

Commit

Permalink
update junest wrapper and handling of args
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Lai <[email protected]>
  • Loading branch information
soraxas committed May 24, 2023
1 parent bc5c3de commit 4bff1b4
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 104 deletions.
2 changes: 1 addition & 1 deletion libexec/shsh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ for arg; do
;;
--version)
cat << EOF
shsh (shell script handler) v2.8.2
shsh (shell script handler) v3.0.0
Copyright (c) 2014 Juan Ibiapina, 2020 Tin Lai (@soraxas)
This is free software; see the source for copying conditions. There is NO
Expand Down
77 changes: 40 additions & 37 deletions libexec/shsh-junest
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,52 @@
#
# Summary: A transparently wrapper of junest with custom ignoring bins
# Usage: shsh junest [-h|--help] <sub_command>
# shsh junest enter [argunments for junest...]
# shsh junest link <executable_name>
# shsh junest unlink <executable_name>
# shsh junest linkable [package]
# shsh junest linked
# shsh junest linkable [package] [-d|--details]
# shsh junest linked [-d|--details]
# shsh junest packages [-d|--details]
# shsh junest lookup <executable_name>
#
# This can automatically bootstrap junest, which brings a lot of
# packages from the arch linux community AUR via yay.
# After bootstrapping, you can directly install packages via yay.


set -e

# TAG completions
if [ "$1" = "--complete" ]; then
printf '%s\n' link unlink linked linkable lookup packages
exit
fi
export JUNEST_HOME="${SHSH_ROOT:?Root directory for shsh has not been defined.}/cellar/arch_junest_root/junest"
junest_bin_root="$JUNEST_HOME/usr/bin_wrappers"

resolve_link() {
if type greadlink >/dev/null 2>&1; then
greadlink -f "$1"
else
if ! readlink -f "$1" 2>/dev/null; then
# use self-implemented `readlink -f`
readlink_canonicalise "$1"
fi
fi
}
shsh_junest_pkg_name=_bootstrap/junest
real_junest_bin="$SHSH_ROOT/cellar/packages/$shsh_junest_pkg_name/bin/junest"

bin_path="$(dirname "$(resolve_link "$0")")"
# shellcheck source=libexec/shsh-_env-var
. "$bin_path/shsh-_env-var"
if [ "$(basename "$0")" = junest ]; then
# wrapper mode
exec "$real_junest_bin" "$@"
exit
fi

# shellcheck source=libexec/shsh-_utils
. "${UTILS_FUNC:?}"

set -e

export JUNEST_HOME="$SHSH_JUNEST_ROOT/junest"
junest_bin_root="$JUNEST_HOME/usr/bin_wrappers"
# TAG completions
if [ "$1" = "--complete" ]; then
printf '%s\n' link unlink linked linkable lookup packages enter
exit
fi

##########################################################
# bootstrap

if [ ! -e "$SHSH_INSTALL_BIN/junest" ] && [ -e "$SHSH_ROOT/libexec/shsh-junest" ]; then
ln -s "$SHSH_ROOT/libexec/shsh-junest" "$SHSH_INSTALL_BIN/junest"
fi
if ! command_exists junest_real || [ ! -d "$JUNEST_HOME" ]; then
prompt "> Junest not found. Install now?" || exit

shsh install fsquillace/junest _bootstrap/junest -v BINS=bin/junest@junest_real:bin/sudoj@sudoj -f
shsh install fsquillace/junest "$shsh_junest_pkg_name" -v BINS=bin/junest@junest_real -f

junest_real setup

Expand All @@ -59,29 +56,25 @@ if ! command_exists junest_real || [ ! -d "$JUNEST_HOME" ]; then
exit 1
fi
mkdir -p "$SHSH_JUNEST_BIN"
shsh junest link yay
fi
[ ! -e "$SHSH_JUNEST_BIN/junest" ] && ln -s "$SHSH_ROOT/libexec/shsh-junest" "$SHSH_JUNEST_BIN/junest"

##########################################################



set -e

is_exectuable_file () {
[ -f "$1" ] && [ -x "$1" ]
}

list_all_packages_and_executables () {
"$(shsh package-path _bootstrap/junest)/bin/junest" -- pacman -Ql | grep ' /usr/bin/' | while read -r package file; do
if is_exectuable_file "$file"; then
"$real_junest_bin" -- pacman -Ql | grep ' /usr/bin/' | while read -r package file; do
if is_exectuable_file "$JUNEST_HOME/$file"; then
printf '%s\t%s\n' "${file##*/}" "pkg: $package"
fi
done
}

list_all_packages () {
"$(shsh package-path _bootstrap/junest)/bin/junest" -- pacman -Q | while read -r package version; do
"$real_junest_bin" -- pacman -Q | while read -r package version; do
if [ -n "$OPT_DETAILS" ]; then
printf '%s\t%s\n' "$package" "$version"
else
Expand All @@ -91,20 +84,29 @@ list_all_packages () {
}

get_package_executables () {
"$(shsh package-path _bootstrap/junest)/bin/junest" -- pacman -Qql "$1" | while read -r file; do
"$real_junest_bin" -- pacman -Qql "$1" | while read -r file; do
is_exectuable_file "$file" && echo "$file"
done
}

get_package_name_from_file () {
"$(shsh package-path _bootstrap/junest)/bin/junest" -- pacman -Qo "$1"
"$real_junest_bin" -- pacman -Qo "$1"
}

show_help_and_exit () {
shsh-help junest
exit 1
}

# super case
case "$1" in
enter)
shift
exec "$real_junest_bin" "$@"
exit
;;
esac

# process flag

# shellcheck disable=SC2116,SC2028
Expand Down Expand Up @@ -153,7 +155,9 @@ if [ "$#" != 0 ]; then
if [ -n "$OPT_DETAILS" ]; then
list_all_packages_and_executables
else
command ls "$junest_bin_root"
for file in "$junest_bin_root"/*; do
is_file_or_link "$file" && echo "${file##*/}"
done
fi
else
show_help_and_exit
Expand All @@ -163,7 +167,6 @@ if [ "$#" != 0 ]; then
linked)
[ "$#" = 1 ] || show_help_and_exit
linked_bins="$(command ls "$SHSH_JUNEST_BIN")"
linked_bins="$(echo "$linked_bins" | tr '\n' ' ')"

if [ -n "$OPT_DETAILS" ]; then
# FIXME The following might be very slow, it's O(mn) complexity
Expand Down
5 changes: 3 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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,cleanup \/\fR[\fI\,-d|--dry\/\fR]
Expand Down Expand Up @@ -32,6 +32,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
5 changes: 3 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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,commands\/\fR
Expand All @@ -28,6 +28,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
5 changes: 3 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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,completions <command>\/\fR
Expand All @@ -27,6 +27,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
5 changes: 3 additions & 2 deletions man/man1/shsh-edit.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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,edit\/\fR
Expand All @@ -26,6 +26,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
5 changes: 3 additions & 2 deletions man/man1/shsh-get.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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,get <package>\/\fR
Expand All @@ -26,6 +26,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
5 changes: 3 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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,help \/\fR[\fI\,--usage\/\fR] \fI\,COMMAND\/\fR
Expand Down Expand Up @@ -32,6 +32,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
5 changes: 3 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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B eval
\fI\,"$(shsh init SHELL)"\/\fR
Expand All @@ -26,6 +26,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
29 changes: 11 additions & 18 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.49.3.
.TH SHSH "1" "April 2023" "shell script handler v2.8.2" "User Commands"
.TH SHSH "1" "May 2023" "shell script handler v3.0.0" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.0
.SH SYNOPSIS
.B shsh
\fI\,install \/\fR[\fI\,site\/\fR]\fI\,/<package>\/\fR[\fI\,@ref\/\fR] [\fI\,<folder>/<folder>\/\fR]
Expand Down Expand Up @@ -73,44 +73,36 @@ multiples are given, they will be run in sequential order.
a+x
Before linking, add executable bit to all files.
.SH EXAMPLES
.IP
.TP
shsh install soraxas/dot\-reminder
.IP
install 'soraxas/dot\-reminder' as a package
.IP
.TP
shsh install soraxas/git\-utils git/tools
.IP
install 'soraxas/git\-utils' to a folder within 'git/tools'
.IP
.TP
shsh install \-\-ssh <package>
.IP
install with ssh protocal (rather than https)
.IP
.TP
shsh install <package> \-v FISH_COMPLETIONS=synoservice.fish:forgit.fish
.IP
link 'synoservice.fish' and 'forgit.fish' as fish
completion files
.IP
.TP
shsh install <package> \-\-hook pre="mv bin/foo bin/bar"
.IP
Execute the script "mv bin/foo bin/bar" before `shsh`
performs linking (e.g. this script renames the binary)
.IP
.TP
shsh install <package> \-\-hook +x=foobar
.IP
add a hook that add executable bits to the file 'foobar',
before linking is performed
.IP
.TP
shsh install <package> \-h pre='make all' \-h post='rm \-r build/*'
.IP
add a hook that runs 'make all' to build binaries, right
after cloning and before linking is performed. Then,
linking is performed with its usual rules (i.e. all
executable files in root and in bin/). Finally,
\&'rm \-r build/*' is ran to remove leftovers.
.IP
.TP
shsh install \-\-plain wsl\-tools/win32yank \-h pre='curl \-sLo out.zip \e
.IP
https://<..>/releases/<..>.zip && unzip out.zip' \-h +x=win32yank.exe
.IP
add a plain package by using curl to download pre\-built
Expand All @@ -132,6 +124,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.B shsh-help (1),
.B shsh-init (1),
.B shsh-install (1),
.B shsh-junest (1),
.B shsh-link (1),
.B shsh-list (1),
.B shsh-outdated (1),
Expand Down
Loading

0 comments on commit 4bff1b4

Please sign in to comment.