source: trunk/third/bash/examples/functions/ksh-cd @ 16807

Revision 16807, 635 bytes checked in by zacheiss, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16806, which included commits to RCS files with non-trunk default branches.
Line 
1#
2# ksh-like `cd': cd [-LP] [dir [change]]
3#
4cd()
5{
6        OPTIND=1
7        while getopts "LP" opt
8        do
9                case $opt in
10                L|P)    CDOPTS="$CDOPTS -$opt" ;;
11                *)      echo "$FUNCNAME: usage: $FUNCNAME [-LP] [dir] [change]" >&2
12                        return 2;;
13                esac
14        done
15
16        shift $(( $OPTIND - 1 ))
17
18        case $# in
19        0)      builtin cd $CDOPTS "$HOME" ;;
20        1)      builtin cd $CDOPTS "$@" ;;
21        2)      old="$1" new="$2"
22                case "$PWD" in
23                *$old*) ;;
24                *)       echo "${0##*/}: $FUNCNAME: bad substitution" >&2 ; return 1 ;;
25                esac
26
27                dir=${PWD//$old/$new}
28
29                builtin cd $CDOPTS "$dir" && echo "$PWD"
30
31                ;;
32        *)      echo "${0##*/}: $FUNCNAME: usage: $FUNCNAME [-LP] [dir] [change]" >&2
33                return 2 ;;
34        esac
35}
Note: See TracBrowser for help on using the repository browser.