From 6e8c6c521ae5d60427634be01b82fe61a79f192b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Dec 2018 14:52:11 +1300 Subject: Refactor some conditionals --- sh/shrc.d/path.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sh/shrc.d/path.sh') diff --git a/sh/shrc.d/path.sh b/sh/shrc.d/path.sh index 70947515..a854e148 100644 --- a/sh/shrc.d/path.sh +++ b/sh/shrc.d/path.sh @@ -34,7 +34,9 @@ path() { # Add a directory at the start of $PATH insert) - [ "$#" -eq 2 ] || set -- "$1" "$PWD" + if ! [ "$#" -eq 2 ] ; then + set -- "$1" "$PWD" + fi path _argcheck "$@" || return if path check "$2" ; then printf >&2 'path(): %s: %s already in PATH\n' "$@" @@ -45,7 +47,9 @@ path() { # Add a directory to the end of $PATH append) - [ "$#" -eq 2 ] || set -- "$1" "$PWD" + if ! [ "$#" -eq 2 ] ; then + set -- "$1" "$PWD" + fi path _argcheck "$@" || return if path check "$2" ; then printf >&2 'path(): %s: %s already in PATH\n' "$@" @@ -56,7 +60,9 @@ path() { # Remove a directory from $PATH remove) - [ "$#" -eq 2 ] || set -- "$1" "$PWD" + if ! [ "$#" -eq 2 ] ; then + set -- "$1" "$PWD" + fi path _argcheck "$@" || return if ! path check "$2" ; then printf >&2 'path(): %s: %s not in PATH\n' "$@" @@ -108,7 +114,9 @@ path() { # Check whether a directory is in PATH check) path _argcheck "$@" || return - [ "$#" -eq 2 ] || set -- "$1" "$PWD" + if ! [ "$#" -eq 2 ] ; then + set -- "$1" "$PWD" + fi case :$PATH: in *:"$2":*) return 0 ;; esac -- cgit v1.2.3