Collapse directories in zsh prompt in a unique way

Viewed 1972

Is there a way to collapse the current working directory in the zsh prompt in a unique way, so that I could copy and paste it to another terminal, hit TAB and get the original path?

Let's say we have following directories:

/adam/devl
/alice/devl
/alice/docs
/bob/docs

If the prompt is programmed to show the first characters, and I'm in /b/d, then it is unique. On the other hand, /a/d is not unique, so I would need /ad/d, /al/de and /al/do. And even /ali/… as soon as the user alex appears.

Is it possible to hack this directly in zsh or do I need to write a script, that finds the shortest unique beginning of each parent directory?

Thank you for your ideas!

2 Answers
Related