]> git.wh0rd.org Git - home.git/commitdiff
cd_history: handle multiple args to `cd`
authorMike Frysinger <vapier@gentoo.org>
Wed, 15 Mar 2017 23:03:07 +0000 (16:03 -0700)
committerMike Frysinger <vapier@gentoo.org>
Wed, 15 Mar 2017 23:03:07 +0000 (16:03 -0700)
.profile.d/aliases.sh

index 103b795174f19fd1d4c7020d0a45ad50779d221b..5de5ef9f107fec97a589486325852de95a957af5 100644 (file)
@@ -103,6 +103,25 @@ cd_history() {
        fi
        if command cd "$@" ; then
                pushd -n "${PWD}" >/dev/null
+       elif [[ $# -gt 1 ]] ; then
+               # The `cd` above should have shown an error message for us.
+               local arg first_arg="$1"
+               while [[ $# -gt 0 ]] ; do
+                       arg="$1"
+                       shift
+                       if [[ -d ${arg} ]] ; then
+                               if [[ $# -gt 0 ]] ; then
+                                       printf 'cd: remaining: %s\n' "$@" >&2
+                               fi
+                               printf 'cd: entering: %s\n' "${arg}" >&2
+                               cd_history "${arg}"
+                               return
+                       else
+                               printf 'cd: skipping: %s\n' "${arg}" >&2
+                       fi
+               done
+               # If we're still here, then we didn't cd anywhere.
+               echo "cd: cwd is unchanged!" >&2
        fi
 }
 alias cd='cd_history'