Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to show shorten project dir on Git #300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion bullet-train.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,23 @@ prompt_hg() {
fi
}

prompt_pwd_maybe_short_dir() {
git_root=$PWD
while [[ $git_root != / && ! -e $git_root/.git ]]; do
git_root=$git_root:h
done

if [[ $git_root = / || $git_root = ~ || $git_root = "$HOME" ]]; then
unset git_root
prompt_short_dir='%~'
else
parent=${git_root%\/*}
prompt_short_dir=${PWD#$parent/}
fi

echo $prompt_short_dir
}

# Dir: current working directory
prompt_dir() {
local dir=''
Expand All @@ -486,6 +503,8 @@ prompt_dir() {
elif [[ $BULLETTRAIN_DIR_EXTENDED == 2 ]]; then
#long directories
dir="${dir}%0~"
elif [[ $BULLETTRAIN_DIR_SHORTEN_GIT_REPO == true ]] then
prompt_segment $BULLETTRAIN_DIR_BG $BULLETTRAIN_DIR_FG `prompt_pwd_maybe_short_dir`
else
#medium directories (default case)
dir="${dir}%4(c:...:)%3c"
Expand Down Expand Up @@ -558,7 +577,7 @@ prompt_kctx() {
if command -v kubectl > /dev/null 2>&1; then
if [[ -f $BULLETTRAIN_KCTX_KCONFIG ]]; then
prompt_segment $BULLETTRAIN_KCTX_BG $BULLETTRAIN_KCTX_FG $BULLETTRAIN_KCTX_PREFIX" $(cat $BULLETTRAIN_KCTX_KCONFIG|grep current-context| awk '{print $2}')"
fi
fi
fi
}

Expand Down