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

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



On Thu, Dec 18, 2014 at 3:50 PM, Shiyao Ma <i@xxxxxxxxx> wrote:
> 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 ears.
>
> Thanks in advance.
>
> Regards.

http://mika.l3ib.org/code/zsh-functions/disambiguate-keeplast
http://mika.l3ib.org/code/zsh-functions/disambiguate
I use this to shorten path segments so that they're unambiguous, you
can probably modify this to be closer to what you want. Mine is also
unconditional, and I have a hotkey to disable it when needed. The
first one always keeps the full last segment and the second shortens
everything.

-- 
Mikael Magnusson



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