forked from wh5a/arch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zer0prompt
141 lines (120 loc) · 4.17 KB
/
.zer0prompt
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
#
# zer0prompt
# By: Wes Brewer [zer0]
# Last updated: Nov 8, 2009
#
# Credit for ideas/info: Phil!'s ZSH Prompt, Bashish, TERMWIDE prompt
# Bash Prompt Howto
#
# Usage: Add the follwing lines to your ~/.bashrc file
# source ~/.zer0prompt
# zer0prompt
# unset zer0prompt
#### user config ####
## set colour theme
# options -- cyan, blue, green, red, purple, yellow, black, white, none
zpcl="cyan"
## set info colours
# colour ref -- http://www.gilesorr.com/bashprompt/howto/c333.html#AEN335
zi1="\[\033[1;32m\]" # user@host:tty
zi2="\[\033[1;35m\]" # current path
zi3="\[\033[1;33m\]" # time
zi4="\[\033[1;31m\]" # exit status
zi5="\[\033[1;32m\]" # user identifier ($ or #)
## set time format
# options -- 12, 24, 12s, 24s
zptm="12"
## set line graphics to use
zg1="─"; zg2="┌"; zg3="└"; zg4="┤"; zg5="├"; zg6=">"; zg7="|"
#zg1="-"; zg2="+"; zg3="+"; zg4="|"; zg5="|"; zg6=">"; zg7="|"
#### code ####
# Use bash builtin checkwinsize option for terminals which fail to properly
# set the $COLUMNS variable. (bug workaround)
shopt -s checkwinsize
# if root user then colour user@host info and user identifier red.
[ "${UID}" = 0 ] && zi1="\[\033[1;31m\]" && zi5="\[\033[1;31m\]"
# This function is run at every prompt update, keeping our variables updated.
# Bash's PROMPT_COMMAND option handles this (see end of this function).
function pre_prompt {
# show exit code of last failed command, must be the first line in the function
ZEXIT="${?}"
[ "$ZEXIT" = "0" ] && ZEXIT=""
# Whenever displaying the prompt, write the previous line to disk;
history -a
ZPWD=${PWD/#$HOME/\~} # sorten home dir to ~
# set length of our important info
local infolength="$(whoami)@$(hostname):$(basename $(tty))$ZPWD"
# set length of our graphics
local gfxlength=23
# construct ZFILL size to fill terminal width (minus info/gfx lengths).
local fillsize
let fillsize=${COLUMNS}-${gfxlength}-${#infolength}
ZFILL=""
while [ "$fillsize" -gt "0" ]; do
ZFILL="$ZFILL$zg1"
let fillsize=${fillsize}-1
done
# determine how much to truncate ZPWD, if ZFILL can't shrink anymore.
if [ "$fillsize" -lt "0" ]; then
local cut=3-${fillsize} # some tricky math, 3-(-number)=+number
ZPWD="...${ZPWD:${cut}}"
fi
# Required by /etc/profile.d/autojump.bash
# It conflicts with our function so we have to copy over.
(autojump -a "$(pwd -P)"&)>/dev/null 2>>${HOME}/.autojump_errors
}
PROMPT_COMMAND=pre_prompt
# This function tells bash how to draw our prompt
function zer0prompt {
local zc0="\[\033[0m\]" # clear all colors
local zc1="\[\033[1;37m\]"
local zc2="\[\033[0;37m\]"
# set colour theme
if [ "$zpcl" = "cyan" ]; then
local zc3="\[\033[1;36m\]"; local zc4="\[\033[0;36m\]"
elif [ "$zpcl" = "blue" ]; then
local zc3="\[\033[1;34m\]"; local zc4="\[\033[0;34m\]"
elif [ "$zpcl" = "green" ]; then
local zc3="\[\033[1;32m\]"; local zc4="\[\033[0;32m\]"
elif [ "$zpcl" = "red" ]; then
local zc3="\[\033[1;31m\]"; local zc4="\[\033[0;31m\]"
elif [ "$zpcl" = "purple" ]; then
local zc3="\[\033[1;35m\]"; local zc4="\[\033[0;35m\]"
elif [ "$zpcl" = "yellow" ]; then
local zc3="\[\033[1;33m\]"; local zc4="\[\033[0;33m\]"
elif [ "$zpcl" = "black" ]; then
local zc3="\[\033[1;30m\]"; local zc4="\[\033[0;30m\]"
elif [ "$zpcl" = "white" ]; then
local zc3="\[\033[1;37m\]"; local zc4="\[\033[0;37m\]"
else # no colour
local zc3=""; local zc4=""; local zc1=""; local zc2=""
zi1=""; zi2=""; zi3=""; zi4=""; zi5=""
fi
# set time format
if [ "$zptm" = "24" ]; then
local ZTIME="\A"
elif [ "$zptm" = "12s" ]; then
local ZTIME="\T"
elif [ "$zptm" = "24s" ]; then
local ZTIME="\t"
else
local ZTIME="\@"
fi
# set titlebar info if xterm/rxvt
case $TERM in
xterm*|rxvt*)
local TITLEBAR='\[\033]0;\u (\w) [${COLUMNS}x${LINES}]\007\]';;
*)
local TITLEBAR="";;
esac
# prompt
PS1="${TITLEBAR}\
$zi1\u@\h:\l$zc4$zg5$zg1\
$zg4$zi1\$ZPWD$zc4$zg5$zg1$zc4\
\$ZFILL$zc3$zg1$zg1$zg1$zg1$zc1$zg1$zg1$zg1$zc3$zg1$zg1$zc4$zg1\
$zg1$zc2$zg1
$zi4\$ZEXIT$zi5\\\$$zc0 "
# continuation prompt
PS2="$zc3$zg3$zc4$zg1$zg4$zi5\\\$$zc4$zg5$zc2$zg1$zc3$zg6$zc0 "
}