From 2b0c64251261de7c0ac8326196760a8b2900befb Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 24 Feb 2024 08:34:23 -0800 Subject: [PATCH] turn `have`, `has`, and `maybesudo` into one-liners --- home/shrc | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/home/shrc b/home/shrc index c0fa666..29c2354 100644 --- a/home/shrc +++ b/home/shrc @@ -8,18 +8,10 @@ fi # {{{1 utilities -have() { - if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi -} 2>/dev/null -has() { - have "$@" -} >/dev/null +have() { if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi; } 2>/dev/null +has() { have "$@"; } >/dev/null -if has sudo; then - maybesudo() { sudo "$@"; } -else - maybesudo() { maybesudo_ "$@"; } -fi +has sudo && maybesudo() { sudo "$@"; } || maybesudo() { maybesudo_ "$@"; } ADDPATH() { ### @- append a directory to `$PATH` if it isn't already present. [ $# = 1 ] || { printf >&2 'ADDPATH: expected exactly 1 argument, got %s\n' $#; return 64; }