Artificial intelligent assistant

Detect pushd depth in bash? I would like to be able to programmaticly detect when my `pushd` stack is non-empty, within a bash shell. Is there any way to detect this? Something akin to $SHLVL would be nice. But so far, the only solution I've found is to wrap `pushd` and `popd` with aliases that parse the output of the originals to detect the depth. While that would work, it doesn't feel particularly elegant. (Clearly, the information is stored somewhere in the environment.) My reason is, I wish to adorn my bash prompt with a pushd depth-count, when this is the case.

You can check `DIRSTACK` length:


$ [[ ${#DIRSTACK[@]} -gt 1 ]] && echo dir stack non-empty


Note that you can not use this method if `DIRSTACK` is unset.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 408975479eaca3521851567b8d8d8f79