kiss: simplify

This commit is contained in:
Dylan Araps 2020-03-23 12:05:54 +02:00
parent 2db59e03db
commit 7f22697bdc
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

20
kiss
View File

@ -119,7 +119,7 @@ pkg_find() {
# in $KISS_PATH/*. # in $KISS_PATH/*.
query=$1 match=$2 IFS=:; set -- query=$1 match=$2 IFS=:; set --
# Both counts of word-splitting is intentional here. # Both counts of word-splitting are intentional here.
# Firstly to split the repositories and secondly to # Firstly to split the repositories and secondly to
# allow for the query to be a glob. # allow for the query to be a glob.
# shellcheck disable=2086 # shellcheck disable=2086
@ -131,6 +131,8 @@ pkg_find() {
done done
done done
IFS=$old_ifs
# A package may also not be found due to a repository not being # A package may also not be found due to a repository not being
# readable by the current user. Either way, we need to die here. # readable by the current user. Either way, we need to die here.
[ "$1" ] || die "Package '$query' not in any repository" [ "$1" ] || die "Package '$query' not in any repository"
@ -138,8 +140,6 @@ pkg_find() {
# Show all search results if called from 'kiss search', else # Show all search results if called from 'kiss search', else
# print only the first match. # print only the first match.
[ "$match" ] && printf '%s\n' "$@" || printf '%s\n' "$1" [ "$match" ] && printf '%s\n' "$@" || printf '%s\n' "$1"
IFS=$old_ifs
} }
pkg_list() { pkg_list() {
@ -148,21 +148,13 @@ pkg_list() {
# file read. # file read.
# Change directories to the database. This allows us to # Change directories to the database. This allows us to
# avoid having to 'basename' each path. If this fails, # avoid having to 'basename' each path. .
# set '$1' to mimic a failed glob which indicates that cd "$sys_db" 2>/dev/null
# nothing is installed.
cd "$sys_db" 2>/dev/null || set -- "$sys_db/"\*
# Optional arguments can be passed to check for specific # Optional arguments can be passed to check for specific
# packages. If no arguments are passed, list all. As we # packages. If no arguments are passed, list all.
# loop over '$@', if there aren't any arguments we can
# just set the directory contents to the argument list.
[ "$1" ] || { set +f; set -f -- *; } [ "$1" ] || { set +f; set -f -- *; }
# If the 'glob' above failed, exit early as there are no
# packages installed.
[ "$1" = "$sys_db/"\* ] && return 1
# Loop over each package and print its name and version. # Loop over each package and print its name and version.
for pkg do for pkg do
[ -d "$pkg" ] || { log "$pkg" "not installed"; return 1; } [ -d "$pkg" ] || { log "$pkg" "not installed"; return 1; }