Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/soraxas/shsh
Browse files Browse the repository at this point in the history
  • Loading branch information
soraxas committed Sep 1, 2023
2 parents 2a13f26 + b955dc0 commit 2b2d4ee
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-18.04
# - ubuntu-18.04
# - ubuntu-16.04
- macos-latest
# - macos-10.14
Expand Down
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.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
6 changes: 4 additions & 2 deletions libexec/shsh-_post-install
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ ref="$4"
# script for gh release
if [ -n "$gh_release" ]; then

echo_if_verbose ">> Requesting github release info"
_response="$(request_gh_release_info "$package" "$ref")"

if [ "$(jq -r -n --argjson data "$_response" '$data.message')" = "Not Found" ]; then
error_echo "> The given github repo '$package' was not found"
exit 1
fi

# save the release tag to file
echo_if_verbose ">> Saving release tag to file"
jq -n --argjson data "$_response" '$data' > "$target_folder/.gh-release_info"

# using EOF method as the original json might contain invalid characters
echo_if_verbose ">> Parsing json result"
all_available_assets="$(jq -n --argjson data "$_response" '$data.assets')"
available_assets="$all_available_assets"

Expand Down Expand Up @@ -74,7 +76,7 @@ if [ -n "$gh_release" ]; then
# archives
available_assets="$(filter_by_preference "$available_assets" 'map(select(.name|test("(.tgz)|(.tar.gz)|(.zip)|(.xz)$")))')"
# prefer statically linked assets
available_assets="$(filter_by_preference "$available_assets" 'map(select(.name|test("(linux-musl)|(linux)")))')"
available_assets="$(filter_by_preference "$available_assets" 'map(select(.name|test("(linux-musl)|(linux)|(Linux)")))')"

# get first item
item="$(echo "$available_assets" | jq -r '.[0]')"
Expand Down
2 changes: 1 addition & 1 deletion libexec/shsh-_utils
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ if ! command_exists jq; then
fi

"$SHSH_PACKAGES_PATH/_bootstrap/jq/$bin_name" "$@"
exit $?
return $?
}
fi

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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.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
7 changes: 3 additions & 4 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" "September 2023" "shell script handler v3.0.2" "User Commands"
.SH NAME
shsh \- manual page for shsh v2.8.2
shsh \- manual page for shsh v3.0.2
.SH SYNOPSIS
.B shsh
\fI\,install \/\fR[\fI\,site\/\fR]\fI\,/<package>\/\fR[\fI\,@ref\/\fR] [\fI\,<folder>/<folder>\/\fR]
Expand Down Expand Up @@ -42,8 +42,6 @@ flag implies \fB\-\-plain\fR
TODO: currently it is bias towards linux and amd64;
.IP
to\-be generalised towards detecting current arch.
.HP
\fB\-\-arch[pkg]\fR install the <package> as Arch package (or AUR)
.TP
\fB\-f\fR, \fB\-\-force\fR
force the installation even if the package exists
Expand Down Expand Up @@ -132,6 +130,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 2b2d4ee

Please sign in to comment.