From e91f582b678ea3e71d1ddfe8bef092025aa09e91 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 19 Jul 2021 00:00:41 +0300 Subject: [PATCH] kiss: initial unneeded [ (external command) removal --- kiss | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kiss b/kiss index 89fcd62..698f97f 100755 --- a/kiss +++ b/kiss @@ -80,6 +80,10 @@ mkcd() { mkdir -p "$@" && cd "$1" } +null() { + case $1 in '') return 1 ;; *) return 0; esac +} + fnr() { # Replace all occurrences of substrings with substrings. This # function takes pairs of arguments iterating two at a time @@ -327,7 +331,7 @@ pkg_source_resolve() { set -- "$1" "$_fnr" "${3%"${3##*[!/]}"}" "$4" # Git repository. - if [ -z "${2##git+*}" ]; then + if ! null "${2##git+*}"; then _res=$2 # Remote source (cached). @@ -335,7 +339,7 @@ pkg_source_resolve() { _res=$src_dir/$1/${3:+"$3/"}${2##*/} # Remote source. - elif [ -z "${2##*://*}" ]; then + elif ! null "${2##*://*}"; then _res=url+$2 _des=$src_dir/$1/${3:+"$3/"}${2##*/} @@ -498,7 +502,7 @@ pkg_depends() { # dependencies are listed first and then the parents in reverse order. contains "$deps" "$1" || { # Filter out non-explicit, already installed packages. - [ -z "$3" ] || [ "$2" ] || contains "$explicit" "$1" || + ! null "$3" || null "$2" || contains "$explicit" "$1" || ! [ -d "$sys_db/$1" ] || return # Detect circular dependencies and bail out. @@ -975,7 +979,7 @@ pkg_checksums() { esac done < "$repo_dir/sources" - sh256 "$@" + null "$1" || sh256 "$@" } pkg_verify() { @@ -1703,7 +1707,7 @@ args() { # Rerun the script as root with a fixed environment if needed. We sadly # can't run singular functions as root so this is needed. case $action in a|alternatives|i|install|r|remove) - [ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || { + ! null "$1" || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || { as_root env \ HOME="$HOME" \ XDG_CACHE_HOME="$XDG_CACHE_HOME" \