diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-01-19 11:59:29 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-01-19 11:59:29 -0800 |
commit | 1f130366be64a5a86ac94126384413cc8d07d0df (patch) | |
tree | 01310e6d5f3cdd5d5812eb220083a0a022b3df69 | |
parent | de2b13d60203cdb0b05c87a38e3b460ca9e6ee81 (diff) | |
download | cdlog-1f130366be64a5a86ac94126384413cc8d07d0df.tar.gz cdlog-1f130366be64a5a86ac94126384413cc8d07d0df.tar.bz2 cdlog-1f130366be64a5a86ac94126384413cc8d07d0df.zip |
Reduce repeated code.
* cdlog.sh (cdlog.rot): Eliminate repeated code,
distinguishing different parts with a flag indicating the
first loop iteration.
-rw-r--r-- | cdlog.sh | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -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 ;; ( * ) |