dotfiles/zsh/prompt_miniline_setup

71 lines
1.7 KiB
Bash

# vim: set filetype=zsh :
function () {
MINILINE_NERD_FONTS=true;
MINILINE_GLYPH_GIT="|\\";
MINILINE_GLYPH_BRANCH="|/";
MINILINE_GLYPH_COMMIT="@-";
MINILINE_INCLUDE_VCS=true;
MINILINE_COLOR_COMMIT="yellow"; #"#FFA500";
MINILINE_COLOR_BRANCH="cyan";
if $MINILINE_NERD_FONTS; then
MINILINE_GLYPH_GIT=$'\ue702';
MINILINE_GLYPH_BRANCH=$'\ue725';
MINILINE_GLYPH_COMMIT=$'\ue729';
fi
prompt_opts=(cr percent subst);
function ps_vcs() {
ps_vcs="";
! $MINILINE_INCLUDE_VCS && return;
# search for git dir
local found=false;
local dir="$(readlink -f "$(pwd)")";
while [[ "$dir" != "/" ]]; do
if [[ -d "$dir/.git" ]]; then
found=true;
break;
fi;
dir="$(readlink -f "$dir/..")";
done;
# handle git repo
if $found; then
local git_dir="$dir/.git";
# read current head
local head_type="commit";
local head="$(<"$git_dir/HEAD")";
local branch;
if [[ "$head" =~ 'ref: (.*)' ]]; then
head="${match[1]}";
head_type="branch";
[[ "$head" =~ 'refs/heads/(.*)' ]];
branch="${match[1]}";
fi;
if [[ "$head_type" == "commit" ]]; then
[[ "$head" =~ '(........).*' ]]; # this might not be a valid commit but whos going to use a repo with smth that large
ps_vcs=" | $MINILINE_GLYPH_COMMIT %F{$MINILINE_COLOR_COMMIT}${match[1]}%F{white}";
elif [[ "$head_type" == "branch" ]]; then
ps_vcs=" | $MINILINE_GLYPH_BRANCH %F{$MINILINE_COLOR_COMMIT}HEAD%F{$MINILINE_COLOR_BRANCH}@$branch%F{white}";
fi;
fi;
}
function precmd() {
ps_vcs;
}
PS1=$'\u256d\u2500 %F{cyan}%n@%m%F{white} | %F{red}%/%f${ps_vcs} > \n\u2570%(!.#.$)%F{white} ';
PS2=$'%{\x1b[A\u2502 \x1b[B\x1b[G%0G%}\u2570%(!.#.$)%F{white} ';
}