agkozak / agkozak-zsh-prompt

A fast, asynchronous Zsh prompt with color ASCII indicators of Git, exit, SSH, virtual environment, and vi mode status. Framework-agnostic and customizable.
MIT License
292 stars 26 forks source link

Long branch names in git cannot be concatenated #38

Closed ScottA38 closed 2 years ago

ScottA38 commented 3 years ago

Hi,

Finally migrated to zsh on business PC, but I have really long branch names, generated by BitBucket branch generator on JIRA tickets

Is there some option that can be added to allow the branch name to be shortened with some ellipsis? Say to a specific char limit?

Looked into the extension source code but I understand nothing prompt

agkozak commented 3 years ago

I'll try to come up with something for you. Would it be more helpful to be able to see the beginning of the branch name or the end of the branch name?

Also, which options have you set already? It looks as if you're using AGKOZAK_MULTILINE=0 and AGKOZAK_LEFT_PROMPT_ONLY=1. Anything else? Thanks!

ScottA38 commented 3 years ago

Thanks - currently

% cat ~/.scripts/.zshrc | grep AGKOZAK 
AGKOZAK_MULTILINE=0
AGKOZAK_LEFT_PROMPT_ONLY=1
AGKOZAK_COLORS_USER_HOST=cyan
AGKOZAK_COLORS_PATH=magenta

Start of the branch name :pray:

agkozak commented 3 years ago

Try adding this:

AGKOZAK_CUSTOM_PROMPT='%(?..%B%F{${AGKOZAK_COLORS_EXIT_STATUS:-red}}(%?%)%f%b )%(9V.%F{${AGKOZAK_COLORS_CMD_EXEC_TIME:-default}}${AGKOZAK_CMD_EXEC_TIME_CHARS[1]}%9v${AGKOZAK_CMD_EXEC_TIME_CHARS[2]}%f .)%(!.%S%B.%B%F{${AGKOZAK_COLORS_USER_HOST:-green}})%n%1v%(!.%b%s.%f%b) %B%F{${AGKOZAK_COLORS_PATH:-blue}}%2v%f%b%(10V. %F{${AGKOZAK_COLORS_VIRTUALENV:-green}}${AGKOZAK_VIRTUALENV_CHARS[1]-[}%10v${AGKOZAK_VIRTUALENV_CHARS[2]-]}%f.)%(1j. %F{${AGKOZAK_COLORS_BG_STRING:-magenta}}%j${AGKOZAK_BG_STRING:-j}%f.)'

# Here's where the abbreviation occurs
AGKOZAK_CUSTOM_PROMPT+='%(3V. %F{${AGKOZAK_COLORS_BRANCH_STATUS:-yellow}}(%13>...>%6v%>>%(7V. %7v)%f.)'

AGKOZAK_CUSTOM_PROMPT+='${AGKOZAK_PROMPT_WHITESPACE}%F{${AGKOZAK_COLORS_PROMPT_CHAR:-default}}%(4V.${AGKOZAK_PROMPT_CHAR[3]:-:}.%(!.${AGKOZAK_PROMPT_CHAR[2]:-%#}.${AGKOZAK_PROMPT_CHAR[1]:-%#}))%f '

The part that does the abbreviating is %13>...>%6v%>>. That means, "Display the branch name (%6v), but keep it down to 13 characters, using ... to show that abbreviation has occurred. You can change the number 13 to whatever works.

Sorry this solution is ugly, but it's the first time anyone's asked to have the branch name abbreviated. If I get the feeling there's more demand for this sort of thing, I might build in a simpler setting.

ScottA38 commented 3 years ago

Thanks, I think I will just edit the source and hard-code this :+1:

ScottA38 commented 3 years ago

Works like a charm prompt_updated

ScottA38 commented 2 years ago

@agkozak The provided fix works for me ok, when the directory does not have any git repo then the trailing (%) is missing

agkozak commented 2 years ago

@ScottA38 Try this:

AGKOZAK_MULTILINE=0
AGKOZAK_LEFT_PROMPT_ONLY=1
AGKOZAK_COLORS_USER_HOST=cyan
AGKOZAK_COLORS_PATH=magenta

AGKOZAK_CUSTOM_PROMPT='%(?..%B%F{${AGKOZAK_COLORS_EXIT_STATUS:-red}}(%?%)%f%b )%(9V.%F{${AGKOZAK_COLORS_CMD_EXEC_TIME:-default}}${AGKOZAK_CMD_EXEC_TIME_CHARS[1]}%9v${AGKOZAK_CMD_EXEC_TIME_CHARS[2]}%f .)%(!.%S%B.%B%F{${AGKOZAK_COLORS_USER_HOST:-green}})%n%1v%(!.%b%s.%f%b) %B%F{${AGKOZAK_COLORS_PATH:-blue}}%2v%f%b%(10V. %F{${AGKOZAK_COLORS_VIRTUALENV:-green}}${AGKOZAK_VIRTUALENV_CHARS[1]-[}%10v${AGKOZAK_VIRTUALENV_CHARS[2]-]}%f.)%(1j. %F{${AGKOZAK_COLORS_BG_STRING:-magenta}}%j${AGKOZAK_BG_STRING:-j}%f.)'

# Here's where the abbreviation occurs
AGKOZAK_CUSTOM_PROMPT+='%(3V~ %F{${AGKOZAK_COLORS_BRANCH_STATUS:-yellow}}(%13>...>%6v%>>%(7V~ %7v~)%)%f~)'

AGKOZAK_CUSTOM_PROMPT+='${AGKOZAK_PROMPT_WHITESPACE}%F{${AGKOZAK_COLORS_PROMPT_CHAR:-default}}%(4V.${AGKOZAK_PROMPT_CHAR[3]:-:}.%(!.${AGKOZAK_PROMPT_CHAR[2]:-%#}.${AGKOZAK_PROMPT_CHAR[1]:-%#}))%f '