Re: Fwd: Re: interactive shell detection in shrc
RVP <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.userlevel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 1 Oct 2024, RVP wrote:
> Ugly, but, works--after a fashion:
>
> - Only for DIRs in the CWD.
> - no `/' allowed in DIR.
> - if CMD with the same name as DIR is found in $PATH, that will be executed.
>
>> (I tried defining a command_not_found_handle function but that doesn't
>> seem to work if the command that is not found is a directory).
>>
>
> Ayup, dunno what's up with that.
>
bash(1) returns 126 for `Is a directory', so:
```
trap '
if [[ $? -eq 127 || $? -eq 126 ]]
then _d=$( history 1 | awk "{ print \$2 }" )
[[ -d "$_d" ]] && cd "$_d"
unset _d
fi
' ERR
```
but, there's no need for any of this. Close reading the man-page tells us:
```
shopt -s autocd
```
already exists (knew I had seen that somewhere!).
-RVP