blob: 8557b8c9b8a197482551577082b23d34f53801ca (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# 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 arg
local -a opts
for arg ; do
case $arg in
--)
shift
break
;;
-*)
shift
opts[${#opts[@]}]=$arg
;;
*)
break
;;
esac
done
if (($# == 2)) ; then
if [[ $PWD == *"$1"* ]] ; then
builtin cd "${opts[@]}" -- "${PWD/$1/$2}"
else
printf 'bash: %s: could not replace substring\n' \
"$FUNCNAME" >&2
return 2
fi
else
builtin cd "${opts[@]}" -- "$@"
fi
}
|