-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathprompt.zsh
72 lines (62 loc) · 1.63 KB
/
prompt.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
autoload colors && colors
# cheers, @ehrenmurdick
# http://github.com/ehrenmurdick/config/blob/master/zsh/prompt.zsh
if (( $+commands[git] ))
then
git="$commands[git]"
else
git="/usr/bin/git"
fi
git_branch() {
echo $($git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'})
}
git_dirty() {
if $(! $git status -s &> /dev/null)
then
echo ""
else
if [[ $($git status --porcelain) == "" ]]
then
echo "on %{$fg_bold[green]%}$(git_prompt_info)%{$reset_color%}"
else
echo "on %{$fg_bold[red]%}$(git_prompt_info)%{$reset_color%}"
fi
fi
}
git_prompt_info () {
ref=$($git symbolic-ref HEAD 2>/dev/null) || return
# echo "(%{\e[0;33m%}${ref#refs/heads/}%{\e[0m%})"
echo "${ref#refs/heads/}"
}
# This assumes that you always have an origin named `origin`, and that you only
# care about one specific origin. If this is not the case, you might want to use
# `$git cherry -v @{upstream}` instead.
need_push () {
if [ $($git rev-parse --is-inside-work-tree 2>/dev/null) ]
then
number=$($git cherry -v origin/$(git symbolic-ref --short HEAD) 2>/dev/null | wc -l | bc)
if [[ $number == 0 ]]
then
echo " "
else
echo " with %{$fg_bold[magenta]%}$number unpushed%{$reset_color%}"
fi
fi
}
directory_name() {
echo "%{$fg_bold[cyan]%}%1/%\/%{$reset_color%}"
}
battery_status() {
if [[ $(sysctl -n hw.model) == *"Book"* ]]
then
$DOTFILES/bin/battery-status
fi
}
export PROMPT=$'\n$(battery_status)in $(directory_name) $(git_dirty)$(need_push)\n› '
set_prompt () {
export RPROMPT="%{$fg_bold[cyan]%}%{$reset_color%}"
}
precmd() {
title "zsh" "%m" "%55<...<%~"
set_prompt
}