-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_ps
44 lines (39 loc) · 1.75 KB
/
bash_ps
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
#For styling the bash prompt
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
light_status_style=$reset_style'\[\033[0;37m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
light_green='\[\033[01;32m\]'
pink='\[\033[01;31m\]'
dark_green='\[\033[0;32m\]'
yellow='\[\e[1;33m\]'
purple='\e[0;35m'
lines_color=$light_green
function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | sed 's/ //g'
}
PS1=$lines_color"\n\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \""$pink"[\[\033[0;31m\]\342\234\227"$pink"]"$lines_color"\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[0;31m\]\h'; else echo '\[\033[0;33m\]\u\[\033[0;37m\]'"$lines_color"'@\[\033[0;96m\]\h'; fi)"$lines_color"]\342\224\200["$pink"\w"$lines_color"] "$purple'$(git_branch)'" "$lines_color'$fill> \t \n'""$light_green"\342\224\224\342\224\200\342\224\200\342\225\274 "$command_style
# # this is invoked every time before a command is executed
trap 'echo -ne "\033[00m"' DEBUG
#
function prompt_command {
pwd_dir_length() {
echo -n ${PWD/~} | wc -c
}
git_branch_length() {
echo -n $(git_branch) | wc -c
}
offset=35
fillsize=$((${COLUMNS}-offset-$(pwd_dir_length)-$(git_branch_length)))
fill=""
while [ $fillsize -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# Log to bash history log in ~/.logs
mkdir -p ~/.logs # make dir if it doesnt exist
if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi
}
export PROMPT_COMMAND=prompt_command