diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2013-06-23 15:48:29 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2013-06-23 15:48:29 +1200 |
commit | 07250497200475b0950b5247a7b99af15e3e0606 (patch) | |
tree | 55031556fda97198c47d225feb5b588e1f832dc8 /bash/bashrc.d/cd.bash | |
parent | Don't cache stuff in sensitive files (diff) | |
download | dotfiles-07250497200475b0950b5247a7b99af15e3e0606.tar.gz dotfiles-07250497200475b0950b5247a7b99af15e3e0606.zip |
Preserve options for cd alias
Also better explanatory notes
Diffstat (limited to 'bash/bashrc.d/cd.bash')
-rw-r--r-- | bash/bashrc.d/cd.bash | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/bash/bashrc.d/cd.bash b/bash/bashrc.d/cd.bash index 9154291b..a07f07b9 100644 --- a/bash/bashrc.d/cd.bash +++ b/bash/bashrc.d/cd.bash @@ -1,11 +1,17 @@ -# If given two arguments to cd, replace the first with the second in $PWD +# 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 function cd { + while getopts lPe opt + do + local opts="$opts -$opt" + done + shift $(($OPTIND-1)) if [[ -n "$2" ]]; then - builtin cd "${PWD/$1/$2}" + builtin cd $opts "${PWD/$1/$2}" elif [[ -n "$1" ]]; then - builtin cd "$1" + builtin cd $opts "$1" else - builtin cd + builtin cd $opts fi } |