aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/cd.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2014-10-14 17:52:13 +1300
committerTom Ryder <tom@sanctum.geek.nz>2014-10-14 17:52:13 +1300
commit76707d905aa636b1343948f3802305af1c82a8cd (patch)
tree603e8ae069ad02ab7ebf70ff9e9932e43ae8908e /bash/bashrc.d/cd.bash
parentRemove never-used vis function (diff)
downloaddotfiles-76707d905aa636b1343948f3802305af1c82a8cd.tar.gz
dotfiles-76707d905aa636b1343948f3802305af1c82a8cd.zip
Simplify cd wrapper
Diffstat (limited to 'bash/bashrc.d/cd.bash')
-rw-r--r--bash/bashrc.d/cd.bash20
1 files changed, 10 insertions, 10 deletions
diff --git a/bash/bashrc.d/cd.bash b/bash/bashrc.d/cd.bash
index 267e85b9..7a075657 100644
--- a/bash/bashrc.d/cd.bash
+++ b/bash/bashrc.d/cd.bash
@@ -1,26 +1,26 @@
# 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 dir endopts
- local -a opts dirs
+ local arg
+ local -a opts
for arg in "$@" ; do
if [[ $arg == -- ]] ; then
- endopts=1
- elif [[ $arg == -* ]] && ! ((endopts)) ; then
+ shift
+ break
+ elif [[ $arg == -* ]] ; then
+ shift
opts=("${opts[@]}" "$arg")
- else
- dirs=("${dirs[@]}" "$arg")
fi
done
- if ((${#dirs[@]} == 2)) ; then
- if [[ $PWD == *"${dirs[0]}"* ]] ; then
- builtin cd "${opts[@]}" -- "${PWD/${dirs[0]}/${dirs[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[@]}" -- "${dirs[@]}"
+ builtin cd "${opts[@]}" -- "$@"
fi
}