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
1 changed files with 35 additions and 36 deletions

71
kiss
View File

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