1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-12-25 00:20:05 -07:00

kiss: minor changes

This commit is contained in:
Dylan Araps 2020-09-23 21:48:08 +03:00
parent 2762822180
commit e1fa886562
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

71
kiss
View File

@ -127,18 +127,22 @@ pkg_lint() {
pkg_find() { pkg_find() {
# Figure out which repository a package belongs to by searching for # Figure out which repository a package belongs to by searching for
# directories matching the package name in $KISS_PATH/*. # directories matching the package name in $KISS_PATH/*.
query=$1 all=$2 what=$3 IFS=: _query=$1
_paths=${2:-"$KISS_PATH:$sys_db"}
_print=$3
_type=${4:--d}
IFS=:
set -- set --
# Globbing disabled for KISS_PATH word-splitting # Globbing is disabled, splitting is intentional.
for path in $KISS_PATH "${what:-"$sys_db"}"; do for _path in $_paths; do
set +f set +f
# Globbing enabled for search. # Globbing enabled for search.
for path2 in "$path/"${query%%/*}; do for _path2 in "$_path"/${_query%%/*}; do
test "${what:--d}" "$path2" && test "$_type" "$_path2" &&
set -f -- "$@" "$path2" set -f -- "$@" "$_path2"
done done
done done
@ -146,11 +150,12 @@ pkg_find() {
repo_dir=$1 repo_dir=$1
[ "$1" ] || { [ "$1" ] || {
log "Package '$query' not in any repository" log "Package '$_query' not in any repository"
return 1 return 1
} }
[ -z "$all" ] || printf '%s\n' "$@" [ -z "$_print" ] ||
printf '%s\n' "$@"
} }
pkg_list() { pkg_list() {
@ -1413,7 +1418,7 @@ args() {
s|search) s|search)
for pkg do for pkg do
pkg_find "$pkg" all pkg_find "$pkg" '' all
done done
;; ;;
@ -1442,35 +1447,24 @@ args() {
;; ;;
help-ext) help-ext)
log 'Installed extensions (kiss-* in PATH)' log 'Extensions (kiss-* in PATH)'
# shellcheck disable=2046 pkg_find kiss-\* "$PATH" all -x |
# see [1] at top of script.
set -- $(KISS_PATH=$PATH pkg_find kiss-\* all -x)
# To align descriptions figure out which extension has the longest while read -r file; do
# name by doing a simple 'name > max ? name : max' on the basename name=${file#*/kiss-}
# of the path with 'kiss-' stripped as well.
# contains "$list" "$name" || {
# This also removes any duplicates found in '$PATH', picking the list=" $list $name "
# first match.
for path do p=${path#*/kiss-} printf '%-15s ' "$name"
case " $seen " in sed -n 's/^# *//;2p' "$file"
*" $p "*) shift ;; }
*) seen=" $seen $p " max=$((${#p} > max ? ${#p}+1 : max))
esac
done done
# Print each extension, grab its description from the second line
# in the file and align the output based on the above max.
for path do
printf "%b->%b %-${max}s " "$lcol" "$lclr" "${path#*/kiss-}"
sed -n 's/^# *//;2p' "$path"
done >&2
;; ;;
*) *)
KISS_PATH=$PATH pkg_find "kiss-$action*" "" -x 2>/dev/null || pkg_find "kiss-$action*" "$PATH" '' -x 2>/dev/null ||
die "'kiss $action' is not a valid command" die "'kiss $action' is not a valid command"
"$repo_dir" "$@" "$repo_dir" "$@"
@ -1489,7 +1483,11 @@ main() {
# Allow the user to disable colors in output via an environment variable. # Allow the user to disable colors in output via an environment variable.
# Check this once so as to not slow down printing. # Check this once so as to not slow down printing.
[ "$KISS_COLOR" = 0 ] || lcol='\033[1;33m' lcol2='\033[1;34m' lclr='\033[m' [ "$KISS_COLOR" = 0 ] || {
lcol='\033[1;33m'
lcol2='\033[1;34m'
lclr='\033[m'
}
# The PID of the current shell process is used to isolate directories # The PID of the current shell process is used to isolate directories
# to each specific KISS instance. This allows multiple package manager # to each specific KISS instance. This allows multiple package manager
@ -1517,9 +1515,10 @@ main() {
# This is used enough to warrant a place here. # This is used enough to warrant a place here.
uid=$(id -u) uid=$(id -u)
# Make sure that the KISS_ROOT doesn't end with a '/'. This might break # (lazily) ensure that the KISS_ROOT doesn't end with a '/'.
# some operations if left unchecked. KISS_ROOT=${KISS_ROOT%/}
KISS_ROOT=${KISS_ROOT%/} KISS_ROOT=${KISS_ROOT%/} KISS_ROOT=${KISS_ROOT%/} KISS_ROOT=${KISS_ROOT%/}
KISS_ROOT=${KISS_ROOT%/}
# Define some paths which we will then use throughout the script. # Define some paths which we will then use throughout the script.
sys_db=$KISS_ROOT/${pkg_db:=var/db/kiss/installed} sys_db=$KISS_ROOT/${pkg_db:=var/db/kiss/installed}