aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bash/bashrc.d/cd.bash7
1 files changed, 6 insertions, 1 deletions
diff --git a/bash/bashrc.d/cd.bash b/bash/bashrc.d/cd.bash
index 0b4944ba..4adaafab 100644
--- a/bash/bashrc.d/cd.bash
+++ b/bash/bashrc.d/cd.bash
@@ -7,7 +7,12 @@ __cd() {
done
shift "$(($OPTIND-1))"
if [[ "$#" -eq 2 ]]; then
- builtin cd $opts "${PWD/$1/$2}"
+ if [[ "$PWD" == *"$1"* ]]; then
+ builtin cd $opts "${PWD/$1/$2}"
+ else
+ printf 'bash: cd: could not replace substring\n'
+ return 1
+ fi
else
builtin cd $opts "$@"
fi