]> git.wh0rd.org - home.git/commitdiff
aliases: cd: fix return code with basic failures
authorMike Frysinger <vapier@gentoo.org>
Mon, 30 Oct 2017 20:19:44 +0000 (16:19 -0400)
committerMike Frysinger <vapier@gentoo.org>
Mon, 30 Oct 2017 20:19:44 +0000 (16:19 -0400)
.profile.d/aliases.sh

index accde15f50b631b398679de2c03bebf42c42b5ee..dbbf4f41c14e5ca1d01bd90cd992bfc4446c9e6f 100644 (file)
@@ -102,27 +102,34 @@ cd_history() {
                        ;;
                esac
        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
+       else
+               local ret=$?
+
+               if [[ $# -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
-                               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
+                       done
+                       # If we're still here, then we didn't cd anywhere.
+                       echo "cd: cwd is unchanged!" >&2
+               fi
+
+               return ${ret}
        fi
 }
 alias cd='cd_history'