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, Rhialto wrote:

> In bash, I use an alias '..' for 'cd ..', and '...' for 'cd ../..', and
> a few levels more. It is a very poor approximation of the AmigaShell
> feature where typing a directory name as a command does a 'cd' to that
> directory. I wish (ba)sh had such a feature...
>

Use the ERR trap?

```
command_not_found_handle() {
 	return 127
}

trap '
if [ $? -eq 127 ]
then	d=$(history 1 | awk "{ print \$2 }")
 	test -d "$d" && cd "$d"
fi
' ERR
```

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.

-RVP
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.