Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to change path in prompt to /d/i/r format?
- X-seq: zsh-users 19562
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Shiyao Ma <i@xxxxxxxxx>
- Subject: Re: How to change path in prompt to /d/i/r format?
- Date: Thu, 18 Dec 2014 16:04:16 +0100
- Cc: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=vwSRapP6avJzF17Q/xkCDfmEiwPFJqawVnZfEpSkPIA=; b=JWLpMkPeJ0c9Rp0ht/oy9KHUolmPVwP+iyVuDcA5sS+W9iMXFmRgXuL63rly3rFTJL NMBawbOI7A7E0uDmDMM5gW14Q68jb0bjMjIx2QVYsNsv9BieSJ1NnBd80phbVGzqk/7h 7ieMZpZWf46LreGGfzoSsCLUt8FNRcE/I1PM843TFJ4NspdxLen8qFvN8+N651C73STa w4g0dlrdYYvpAtCaSUHzclgKzFcW++FhUHLgBxkpRimobw7nBKT7r32HHqUvmiHKzyb3 9LRtnbm7lnm0Sg2XAcyUzecKKdym7KlFWIPfM1Jy36rsovqhFt9Gmsp/h+tNPZCCp4gP a9vA==
- In-reply-to: <20141218145030.GG1097@FuzzyHorror>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20141218145030.GG1097@FuzzyHorror>
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