aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/cd.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-08-05 23:52:12 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-08-05 23:52:12 +1200
commit9afe94bac03b277b11be9a18c7a10f7bf49cff47 (patch)
treeae4c8fc256f0d08f02fcbc7d47a337286f9906cc /bash/bashrc.d/cd.bash
parentQuote expansions in cd function (diff)
downloaddotfiles-9afe94bac03b277b11be9a18c7a10f7bf49cff47.tar.gz
dotfiles-9afe94bac03b277b11be9a18c7a10f7bf49cff47.zip
Test for substring presence in cd function
Diffstat (limited to 'bash/bashrc.d/cd.bash')
-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