Currently, my zshrc
looks like this
setopt prompt_subst # real time reevaluation of prompt
zmodload zsh/mathfunc # int function
function widthHelper() { echo $(( int(${COLUMNS:-80}) * ${1}/100)) } # calc $1% of prompt
outWidth='$(widthHelper 40)'
inWidth='$(widthHelper 90)'
export PROMPT="%F{cyan}%${outWidth}<◀︎<%f" # truncation based on terminal width
PROMPT+="%(l." # inner truncation group
PROMPT+="%F{cyan}%8>‣>%n%>>%f" # username truncated
PROMPT+="%-${inWidth}(l. %F{blue}%5>‣>%m%>>%f.) " # hostname truncated
PROMPT+=".)" # end truncation
PROMPT+="%F{magenta}%1~%f%<< " # pwd 1 depth
PROMPT+="%# " # privilege group
influenced by this question and my other question
what is currently working as expected
- it truncates the hostname and the username to constant values
- it dynamically truncates the entire PROMPT based on
widthHelper()
which allows me to resize my terminal and dynamically truncate the PROMPT
Currently, I have this line working but not in the desired way
PROMPT+="%-${inWidth}(l. %F{blue}%5>‣>%m%>>%f.) " # hostname truncated
what I want
I want to have the displaying of the hostname depend on the length of the entire PROMPT
and not just rely on the width of the current terminal COLUMNS
.
i.e. I want the hostname to dissapear if I enter a directory with a very long name before I begin to truncate the entire prompt. But I do want both to happen in this order
- the hostname would dissapear (this happens but is not dependent on the
PROMPT
length but on the width of the entire terminal,COLUMNS
) - the entire prompt would begin to truncate on the left (this currently works)
example
If I am in a directory ~
then move into a directory with a long name ~/abcdefghijklmnopqrstuvwxyzabcd
I want the hostname to dissapear, but what is happening is that my prompt is being truncated first.
william‣ wmbp‣ ~ %
william‣ wmbp‣ ~ % cd abcdefghijklmnopqrstuvwxyzabcd
◀︎m‣ wmbp‣ abcdefghijklmnopqrstuvwxyzabcd %
what I want
william‣ wmbp‣ ~ %
william‣ wmbp‣ ~ % cd abcdefghijklmnopqrstuvwxyzabcd
william‣ abcdefghijklmnopqrstuvwxyzabcd %
If I could make the # hostname truncated
line depend on the PROMPT
length then I could solve this issue.
tldr
How can I remove part of my PROMPT
based on how long my current PROMPT
is.