bug-bash
[Top][All Lists]
Advanced

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

Re: pwd and prompt don't update after deleting current working directory


From: felix
Subject: Re: pwd and prompt don't update after deleting current working directory
Date: Thu, 15 Aug 2024 08:27:07 +0200

Le Tue, Jul 16, 2024 at 09:08:14AM -0400, Chet Ramey a écrit :
> On 7/16/24 3:47 AM, David Hedlund wrote:
> > > 
> > > pwd -P >/dev/null 2>&1 || cd ..
> > > 
> > Do you think that it would be appropriate to submit this feature request
> > to the developers of the rm command instead.
> 
> You can try, but I would not expect them to implement it.

Unfortunately, this could be not enough.

~$ mkdir -p /tmp/testdir/subdir/scndsubdir
~$ cd $_
/tmp/testdir/subdir/scndsubdir$ rm -fR /tmp/testdir
/tmp/testdir/subdir/scndsubdir$ pwd
/tmp/testdir/subdir/scndsubdir
/tmp/testdir/subdir/scndsubdir$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent 
directories: No such file or directory

For this, you could use PROMPT_COMMAND feature:

validCurrentDir() { 
    local __vCD_pwd=$PWD;
    while ! [[ -d $__vCD_pwd ]]; do
        __vCD_pwd=${__vCD_pwd%/*};
    done;
    cd $__vCD_pwd
}

~$ PROMPT_COMMAND=validCurrentDir

~$ mkdir -p /tmp/testdir/subdir/scndsubdir
~$ cd $_
/tmp/testdir/subdir/scndsubdir$ rm -fR /tmp/testdir
/tmp$ 



-- 
 Félix Hauri  -  <felix@f-hauri.ch>  -  http://www.f-hauri.ch



reply via email to

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