blob: 4f3d5f64374f66cb5cfbbb93e92a26a593ef75f6 (
plain) (
tree)
|
|
# If given two arguments to cd, replace the first with the second in $PWD,
# emulating a Zsh function that I often find useful; preserves options too
cd() {
local opt OPTERR OPTIND
local -a opts
while getopts elP opt; do
opts[${#opts[@]}]=-$opt
done
shift $(($OPTIND-1))
if (($# == 2)); then
if [[ $PWD == *$1* ]]; then
builtin cd "${opts[@]}" "${PWD/$1/$2}"
else
printf "bash: cd: could not replace substring\n" >&2
return 1
fi
else
builtin cd "${opts[@]}" "$@"
fi
}
|