aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/cd.bash
blob: 3ee3329fdebcf1bda52bf410115f614069687d24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 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 opts=
    while getopts lPe opt; do
        opts="$opts -$opt"
    done
    shift $(($OPTIND-1))
    if [[ $# -eq 2 ]]; then
        builtin cd $opts "${PWD/$1/$2}"
    else
        builtin cd $opts "$@"
    fi
}
alias cd='__cd'