blob: 1813a9dae50d43e899fa6d98876e5c6ebdef708c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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 -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
}
alias cd='__cd'
|