From 1f130366be64a5a86ac94126384413cc8d07d0df Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 19 Jan 2024 11:59:29 -0800 Subject: Reduce repeated code. * cdlog.sh (cdlog.rot): Eliminate repeated code, distinguishing different parts with a flag indicating the first loop iteration. --- cdlog.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cdlog.sh b/cdlog.sh index a617b4b..911c606 100644 --- a/cdlog.sh +++ b/cdlog.sh @@ -57,28 +57,22 @@ cdlog.rot() local p=$cur local n=$cur local d=("" "$c1" "$c2" "$c3" "$c4" "$c5" "$c6" "$c7" "$c8" "$c9") + local first=y unset d[0] [ $# -gt 0 ] || set 1 - n=$1; shift - case $n in - ( [1-9] ) - command cd "${d[$n]}" || return - p=$n - ;; - ( * ) - printf "cdlog.rot: bad argument: %s\n" "$n" - return 1 - ;; - esac - while [ $# -gt 0 ] ; do n=$1; shift case $n in ( [1-9] ) - d[$p]=${d[$n]} + if [ $first ] ; then + command cd "${d[$n]}" || return + else + d[$p]=${d[$n]} + fi + first= p=$n ;; ( * ) -- cgit v1.2.3