aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-20 13:45:17 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-20 13:45:17 +1200
commit6f36a9e6494c723b209b253dfe3c83b62741c105 (patch)
treedc90d921978c517e3c2679c96f6a9db43ae31e6d
parentMove bd() from Bash func section in README (diff)
downloaddotfiles-6f36a9e6494c723b209b253dfe3c83b62741c105.tar.gz
dotfiles-6f36a9e6494c723b209b253dfe3c83b62741c105.zip
Correctly bail from failed subshell
-rw-r--r--sh/shrc.d/bd.sh5
-rw-r--r--sh/shrc.d/cd.sh6
-rw-r--r--sh/shrc.d/ud.sh6
3 files changed, 9 insertions, 8 deletions
diff --git a/sh/shrc.d/bd.sh b/sh/shrc.d/bd.sh
index 5593ff4d..a5344ae7 100644
--- a/sh/shrc.d/bd.sh
+++ b/sh/shrc.d/bd.sh
@@ -54,9 +54,10 @@ bd() {
# Print the target
printf '%s\n' "$dirname"
+ )"
- # If the subshell failed, return from the function with the same exit value
- )" || return
+ # If the subshell printed nothing, return with failure
+ [ -n "$1" ] || return
# Try to change into the determined directory
command cd -- "$@"
diff --git a/sh/shrc.d/cd.sh b/sh/shrc.d/cd.sh
index 37574f78..7bfacd6d 100644
--- a/sh/shrc.d/cd.sh
+++ b/sh/shrc.d/cd.sh
@@ -65,10 +65,10 @@ cd() {
# Print the target
printf '%s\n' "$new"
+ )"
- # If the subshell failed, return from the function with the same exit
- # value
- )" || return
+ # If the subshell printed nothing, return with failure
+ [ -n "$2" ] || return
fi
# Execute the cd command as normal
diff --git a/sh/shrc.d/ud.sh b/sh/shrc.d/ud.sh
index 0dfd858c..259f3167 100644
--- a/sh/shrc.d/ud.sh
+++ b/sh/shrc.d/ud.sh
@@ -32,10 +32,10 @@ ud() {
# Print the target
printf '%s\n' "$dirname"
+ )"
- # If the subshell failed, return from the function with the same exit
- # value
- )" || return
+ # If the subshell printed nothing, return with failure
+ [ -n "$1" ] || return
# Try to change into the determined directory
command cd -- "$@"