oh-my-bash icon indicating copy to clipboard operation
oh-my-bash copied to clipboard

lib: provide a prompt function for the dirstack

Open jjmcdn opened this issue 1 year ago • 4 comments

Providing this additional function for prompts allows anyone using pushd/popd/dirs to navigate directory trees to quickly view their stack and find which entry they want to switch to.

This degrades gracefully for anyone not using the directory stack since dirs will always display the same as \w when the stack is only one entry deep.

The bakke theme has been tweaked to use the new function as an example.

Signed-off-by: Joe MacDonald [email protected]

For what it looks like when it use, I'm adding a screenshot here.

2022-12-06-123744_3840x1080_scrot

jjmcdn avatar Dec 06 '22 17:12 jjmcdn

I have a question. Is it different from directly putting $(dirs) in PS1?

akinomyoga avatar Dec 06 '22 19:12 akinomyoga

I have a question. Is it different from directly putting $(dirs) in PS1?

As currently implemented, no, it's the same thing. I had thought that if this change was okay that there could be a use for having this in a function, such as optionally using the -l option to dirs based on an environment variable (I don't like that behaviour but I can see why others would) or limiting the number of stack entries displayed so it could be used in single-line prompts.

jjmcdn avatar Dec 06 '22 19:12 jjmcdn

OK. Thank you for the clarification! I think I will keep this PR open as an "example configuration".

akinomyoga avatar Dec 06 '22 20:12 akinomyoga

OK. Thank you for the clarification! I think I will keep this PR open as an "example configuration".

Okay, sorry about the delayed follow up on this. I added the full feature as I'd intended it, with the optional -l expansion and limiting the number of dirstack entries from an environment variable. It's only slightly more complex than the simple dirs one I'd initially proposed, so it's probably still useful as an example for others.

Thanks!

jjmcdn avatar Dec 12 '22 15:12 jjmcdn