bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Partial Path" cd


From: Chet Ramey
Subject: Re: "Partial Path" cd
Date: Wed, 23 May 2001 17:04:24 -0400

> I tend to do this a lot after editing a file (vi .../README) and then 
> want to change to the directory that had that file in it, so I type
> cd ESC-. RET so bash tries to cd /usr/local/README.
> 
> So the question is, for Chet especially, is this wanted in Bash?
> 
> I did realize (afterwards: doh!) that this could be done with a function,
> but after also coding up the shell function I feel the C approach is
> cleaner.

Post the shell function.  Mine took eleven lines and two minutes (without
any option parsing).

cd()
{
        builtin cd "$@" && return || es=$?
        if [ -f "$1" ]; then
                case $1 in
                */*)    ;;
                *)      return $es ;;
                esac
                newdir=${1%/*}
                builtin cd "$newdir" && echo $newdir
        else
                return $es
        fi
}

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]