tech-userlevel archive

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

Re: Fwd: Re: interactive shell detection in shrc



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


Home | Main Index | Thread Index | Old Index