[Top][All Lists]

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

Re: bash: cd improvement

From: Chet Ramey
Subject: Re: bash: cd improvement
Date: Mon, 13 May 2002 13:18:15 -0400

> dont know if this is targeted correctly,
> or in any way interesting.
> Ive written a little patch that will let a user
> change directory to the working directory of a specific job.
> cd %<jobid>

Easy enough to do with a shell function:

        local j
        jwd=            # global
        j=$(jobs "$1")
        [ -z "$j" ] && return;
        case "$j" in
        *\(wd:*)        jwd=${j##*(wd: } ; jwd=${jwd%?} ;;
        *)              return ;;

This takes a job id as an argument and sets $jwd to that job's working
directory, if it differs from $PWD (and is thus printed in the output
of `jobs').  This function can be compressed; it's in separate steps
so you can follow the logic.  You could also augment it to assign $PWD
to jwd if the job's working directory is the same as $PWD for completeness,
if you like.

You can do something like this, (probably) augmenting an already-existing
function replacement for `cd':


        case "$1" in
        %*)     jwd $1
                [ -n "$jwd" ] && builtin cd "$jwd"
                return ;;
        *)      builtin cd "$@" ; return ;;



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

Chet Ramey, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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