Repository navigation
Expand file tree
/
Copy pathprompt.sh
More file actions
61 lines (46 loc) · 1.63 KB
/
Copy pathprompt.sh
File metadata and controls
61 lines (46 loc) · 1.63 KB
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
# Reference for colors: http://stackoverflow.com/questions/689765/how-can-i-change-the-color-of-my-prompt-in-zsh-different-from-normal-text
autoload -U colors && colors
setopt PROMPT_SUBST
set_prompt() {
# [
PS1="%{$fg[white]%}[%{$reset_color%}"
# Path: http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
PS1+="%{$fg_bold[cyan]%}${PWD/#$HOME/~}%{$reset_color%}"
# Status Code
PS1+='%(?.., %{$fg[red]%}%?%{$reset_color%})'
# Git
if git rev-parse --is-inside-work-tree 2> /dev/null | grep -q 'true' ; then
PS1+=', '
PS1+="%{$fg[blue]%}$(git rev-parse --abbrev-ref HEAD 2> /dev/null)%{$reset_color%}"
if [ $(git status --short | wc -l) -gt 0 ]; then
PS1+="%{$fg[red]%}+$(git status --short | wc -l | awk '{$1=$1};1')%{$reset_color%}"
fi
fi
# Timer: http://stackoverflow.com/questions/2704635/is-there-a-way-to-find-the-running-time-of-the-last-executed-command-in-the-shel
if [[ $_elapsed[-1] -ne 0 ]]; then
PS1+=', '
PS1+="%{$fg[magenta]%}$_elapsed[-1]s%{$reset_color%}"
fi
# PID
if [[ $! -ne 0 ]]; then
PS1+=', '
PS1+="%{$fg[yellow]%}PID:$!%{$reset_color%}"
fi
# Sudo: https://superuser.com/questions/195781/sudo-is-there-a-command-to-check-if-i-have-sudo-and-or-how-much-time-is-left
#CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l)
#if [ ${CAN_I_RUN_SUDO} -gt 0 ]
#then
# PS1+=', '
# PS1+="%{$fg_bold[red]%}SUDO%{$reset_color%}"
#fi
PS1+="%{$fg[white]%}]: %{$reset_color%}% "
}
precmd_functions+=set_prompt
preexec () {
(( ${#_elapsed[@]} > 1000 )) && _elapsed=(${_elapsed[@]: -1000})
_start=$SECONDS
}
precmd () {
(( _start >= 0 )) && _elapsed+=($(( SECONDS-_start )))
_start=-1
}