Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to change path in prompt to /d/i/r format?



Hi.

My current prompt setup is:

####################################################################################################
local max_path_chars=45
local user_char='❯'
local root_char='❯❯❯'
local success_color='%F{071}'
local failure_color='%F{124}'
local vcs_info_color='%F{242}'

# Set vcs_info parameters.
zstyle ':vcs_info:*' enable git hg svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '!'
zstyle ':vcs_info:*' stagedstr '+'
zstyle ':vcs_info:*' actionformats "%S" "%r/%s/%b %u%c (%a)"
zstyle ':vcs_info:*' formats "%S" "%r/%s/%b %u%c"
zstyle ':vcs_info:*' nvcsformats "%d" ""

# Define prompts.
PROMPT="%(?.${success_color}.${failure_color})${SSH_TTY:+[%n@%m]}%B%${max_path_chars}<...<"'${${(%)vcs_info_msg_0_}/#$HOME/~}'"%<<%(!.${root_char}.${user_char})%b%f "
RPROMPT="${vcs_info_color}"'${vcs_info_msg_1_}'"%f"

####################################################################################################

For long pathes, it will be abruptly cut into the format, e.g., "...lfred 2/Alfred.alfredpreferences/resources❯"

whereas the realpath is: "/Users/John/Library/Application Support/Alfred 2/Alfred.alfredpreferences/resources"

I know ZSH is powerful, so here goes my question.

How to modify the prompt, so the section of address longer than the ${max_path_chars} will be reduced to,
/U/J/L/A/A/ in this example.

So the final form is
/U/J/L/A/A/Alfred.alfredpreferences/resources


If you have better path format in mind, I am all hears.

Thanks in advance.

Regards.



Messages sorted by: Reverse Date, Date, Thread, Author