-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorprompt.sh
executable file
·101 lines (87 loc) · 3.23 KB
/
colorprompt.sh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# ============================================================================
# SML: Color Prompt for virtualenv
#
function update_prompt() {
local Reset="\[\033[0m\]" # \[...\] so line-wrap won't break
local color_fmt="\[\033[0;3%dm\]" # foreground color: 0;30 + color number
local brt_color_fmt="\[\033[1;3%dm\]" # bright fg color : 1;30 + color number
local bg_color_fmt="\[\033[4%dm\]" # background color: 40 + color number
local colors=( Black Red Green Yellow Blue Magenta Cyan White )
local index=0
for c in "${colors[@]}"
do
# Color (Foreground)
declare "${colors[index]}"="$(printf $color_fmt $index)"
# BrightColor (Foreground)
declare "Bright${colors[index]}"="$(printf $brt_color_fmt $index)"
# ColorBG
declare "${colors[index]}BG"="$(printf $bg_color_fmt $index)"
((index++))
done
# ------------------------------------------------------------------------
# VirtuelEnv prompt
local venv=${VIRTUAL_ENV##/*/}
local venv_ps=""
if [ "$venv" = "" ]; then
venv_ps=":::SYS ENV:::"
else
venv_ps="$venv"
fi
venv_ps="${Yellow}( ${BrightYellow}${venv_ps} ${Yellow})"
# ------------------------------------------------------------------------
# VC Prompt https://bitbucket.org/mitsuhiko/vcprompt
#
# vcprompt -f "%b"
# VCPROMPT_FORMAT="%b" vcprompt
#
# %n name of the VC system managing the current directory
# (e.g. "cvs", "hg", "git", "svn")
# %b current branch name
# %r current revision
# %u ? if there are any unknown files
# %m + if there are any uncommitted changes (added, modified, or
# removed files)
# %% a single % character
local vcp="\$(vcprompt -f [%n:%b%m%u])" # \$() ensures exec every prompt
# ------------------------------------------------------------------------
# Cursor position
local SaveCursor='\[\033[s\]'
local LoadCursor='\[\033[u\]'
local CursorDown='\[\033[1B\]'
local CursorBack3='\[\033[3D\]'
local CursorForw='\[\033[1C\]'
local CursorUp='\[\033[1A\]'
# ------------------------------------------------------------------------
# Regular prompt
local user_host="${Green}\u@\h"
local date="${Magenta}\d \t"
local path="${BrightBlue}\w/"
local hist="${Blue}[${BrightBlue}\#${Blue}]:"
local uid="${Blue}\$"
PS1="${Reset}"
PS1+="\n${user_host} ${venv_ps} ${vcp} ${date} ${Reset}"
PS1+="\n${path} ${Reset}"
PS1+="\n${hist}${uid}${SaveCursor}${Reset} "
export PS1
PS2="${Blue}${LoadCursor}${CursorDown}${CursorBack3}...${SaveCursor}${Reset} "
export PS2
# ------------------------------------------------------------------------
# Sudo prompt: evoked when running sudo -s
# Strangely although color changed, \$ did not get updated to #
# So hard-coding it here
local sudo_uid="${Red}#"
local sudo_host="${Red}\u@\h"
local date="${Yellow}\d \t"
local path="${Yellow}\w/"
local hist="${Yellow}[${BrightYellow}\#${Yellow}]:"
SUDO_PS1="${Reset}"
SUDO_PS1+="\n${sudo_host} ${venv_ps} ${vcp}${date} ${Reset}"
SUDO_PS1+="\n${path} ${Reset}"
SUDO_PS1+="\n${hist}${sudo_uid}${SaveCursor}${Reset} "
export SUDO_PS1
SUDO_PS2="${Blue}${LoadCursor}${CursorDown}${CursorBack3}...${SaveCursor}${Reset} "
export SUDO_PS2
}
# PROMPT_COMMAND=update_prompt
update_prompt