From 9afe94bac03b277b11be9a18c7a10f7bf49cff47 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 5 Aug 2013 23:52:12 +1200 Subject: Test for substring presence in cd function --- bash/bashrc.d/cd.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3