dots-of-war/files/nix-stuff/nixpkgs/modules/term/zsh/prompt.zsh

48 lines
1.1 KiB
Bash
Raw Normal View History

2020-07-09 22:46:25 +00:00
2020-07-03 22:47:14 +00:00
local __bright_cyan="#8ec07c"
local __bright_white="#ebdbb2"
local __bright_green="#b8bb26"
dir() {
local CUTOFF=3
local IFS=/
local my_path=($(print -P '%~'))
local p
for p in $my_path; do
printf %s "${s}${p[0,$CUTOFF]}"
local s=/
done
printf '%s\n' "${p:$CUTOFF}"
}
2020-07-09 22:46:25 +00:00
2020-07-03 22:47:14 +00:00
git_status() {
local BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/*\s*\(.*\)/\1/')
if [ ! -z $BRANCH ]; then
2021-01-31 10:55:50 +00:00
echo -n "(%F{$__bright_cyan}$BRANCH%F{$__bright_white}"
[ ! -z "$(git status --short)" ] && echo -n "*"
echo -n ")%f"
2020-07-03 22:47:14 +00:00
fi
}
function _my_prompt() {
2020-07-09 22:46:25 +00:00
local exit_code="$?"
2020-07-04 14:43:46 +00:00
echo -n "%F{$__bright_white}╭───"
2020-07-03 22:47:14 +00:00
echo -n "%F{$__bright_cyan}$USER"
echo -n "%F{$__bright_white} in"
echo -n "%F{$__bright_green} $(dir)"
echo -n "%F{$__bright_white} $(git_status)"
2020-07-09 22:46:25 +00:00
if [ ! "$exit_code" = 0 ]; then
2020-10-21 20:01:39 +00:00
echo -n "%F{red} REEEEEEEEEEE $exit_code"
2020-07-09 22:46:25 +00:00
fi
2020-07-03 22:47:14 +00:00
echo
# %3{stuff%} tell's zsh that the characters are printed as 3 chars wide
2020-07-05 22:43:10 +00:00
echo -n "%F{$__bright_white}%3{╰─λ%} "
2020-07-03 22:47:14 +00:00
}
setopt prompt_subst
autoload -U colors && colors
PS1='$(_my_prompt)'