From dd1a3bc3d22fe66300d2393902f8ee31cbdbe79c Mon Sep 17 00:00:00 2001 From: Frank Etoundi Date: Wed, 5 Apr 2023 17:33:48 +0200 Subject: [PATCH] Add customizable separator --- README.md | 3 +++ omz-git.plugin.zsh | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 43fbf59..074563b 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,6 @@ Defaults to 0. name are included in the output. Useful if you have an ID or other fixed-length identifier appended to the branch name. Defaults to 0 with manual install , set to 8 by install script. +* omz-separator - character used to separate the prefix and suffix. +Defaults to a dot `.` +* omz-separator-length - number used to multiply the separator. Defaults to 3 diff --git a/omz-git.plugin.zsh b/omz-git.plugin.zsh index 7229fd4..f31cfe6 100644 --- a/omz-git.plugin.zsh +++ b/omz-git.plugin.zsh @@ -35,12 +35,21 @@ function git_prompt_info() { length=${#ref} suffixStart=`expr ${length} - ${suffixLength} + 1` - separatorLength=3 #3 dots... + separatorLength=$(command git config --get oh-my-zsh.omz-separator-length 2>/dev/null) + if [[ -z ${separatorLength} ]]; then + separatorLength=3 # 3 dots... + fi + + separator=$(command git config --get oh-my-zsh.omz-separator 2>/dev/null) + if [[ -z ${separator} ]]; then + separator='.' + fi + separatorExpression=$(printf "%${separatorLength}s") + nameEnd=`expr ${maxLength} - ${suffixLength} - ${separatorLength}` - ref="$(command echo ${ref} | cut -c 1-${nameEnd})...$(command echo ${ref} | cut -c ${suffixStart}-)" + ref="$(command echo ${ref} | cut -c 1-${nameEnd})$(command echo ${separatorExpression// /${separator}})$(command echo ${ref} | cut -c ${suffixStart}-)" fi echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" fi } -