----- Original Message ----
> From: Hilco Wijbenga <[email protected]>
> On 12 November 2010 10:36, Hilco Wijbenga <[email protected]> wrote:
> > On 12 November 2010 09:57, Philip Webb <[email protected]> wrote:
> >> It needs to be a Bash function, so in ~/.bashrc
> >> I tried 'function cd2() { cd .. ; cd $1 ; }',
> >
> > Doesn't
> >
> > function cd2() { cd ../$1 }
> >
> > work? (I haven't tried it.)
>
> So yes, this:
>
> function cd2() { cd ../$1; }
>
> works.
Something I have found useful is the pushd/popd functions in Bash.
Of course, to use them the way you want to you'd have to use two step procedure:
1. Init to the directory you want:
function cdInit()
{
pushd ${1} > /dev/null
pushd ${2} > /dev/null
}
2. cd away:
function cd2()
{
popd > /dev/null
pushd ${1} > /dev/null
}
3. close out when you're done:
function cdFini()
{
popd
}
You could probably modify the above do pull out the initial directory from a
single string by - e.g. turn /my/path/parent/child into /my/path/parent - as
well.
You could also process the DIRSTACK variable (or use the 'dirs' command) to see
if the parent directory is already on the stack too.
Note: I have the redirs in there because pushd/popd by default dumps the
DIRSTACK as its output.
$0.02
Ben