Bash
has the PROMPT_DIRTRIM
option, e.g. when I set PROMPT_DIRTRIM=3
, then a long path like:
user@computer: /this/is/some/silly/path
would show instead as:
user@computer: .../some/silly/path
Does a similar option exist for zsh
?
promptzsh
Bash
has the PROMPT_DIRTRIM
option, e.g. when I set PROMPT_DIRTRIM=3
, then a long path like:
user@computer: /this/is/some/silly/path
would show instead as:
user@computer: .../some/silly/path
Does a similar option exist for zsh
?
Best Answer
To get a similar effect like in
bash
, that is including the...
, try:This checks, if the path is at least 4 elements long (
%(4~|true|false)
) and, if true, prints some dots with the last 3 elements (.../%3~
), otherwise the full path is printed%~
.I noticed that
bash
seems to shorten paths in the home directory differently, for example:For a similar effect, you may want to use:
This checks, whether the path is longer then 5 elements, and in that case prints the first element (
%-1~
), some dots (/…/
) and the last 3 elements. It is not exactly the same as paths, that are not in your home directory, will also have the first element at the beginning, whilebash
just prints dots in that case. Soinstead of
But this might not necessarily a bad thing.