So everytime I change the directory I would like the new path to automatically get listed with ls
.
There are solutions if the path gets changed using cd
but I never found a solution that would work when the path gets changed using the autocd
option.
Would be quite convenient, has anyone achieved that before?
Best Answer
You can achieve this by changing the variable
PROMPT_COMMAND
, which is executed before PS1, e.g.:This will list each time you get a new prompt. Of course you only want to execute
ls
if the directory has changed:This checks if the new directory isn't the same as the last one set, and then executes
ls
, after which your current directory is stored inmy_currdir
I found an even better line here, where they use bash as a file manager:
since it is possible that
__new_wd
is unset, you can assign a default value which will be used in that case (seebash
man pages, search for:=
)