-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
125 lines (99 loc) · 2.59 KB
/
bashrc
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
# .bashrc
# Non-interactive shells
if [[ $- != *i* ]] ; then
return
fi
# Global definitions
shopt -s checkwinsize
shopt -s no_empty_cmd_completion
shopt -s histappend
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
# User exports
if [ -f $HOME/.config/aliases ]
then
source $HOME/.config/aliases
fi
if [ -f $HOME/.config/functions.bash ]
then
source $HOME/.config/functions.bash
fi
# Local exports
if [ -f $HOME/.config/exports.local.bash ]
then
source $HOME/.config/exports.local.bash
fi
rightPrompt() {
local RCol=$(tput sgr0)
local Red=$(tput setaf 1)
local Gre=$(tput setaf 2)
local Yel=$(tput setaf 3)
local Blu=$(tput setaf 3)
local Pur=$(tput setaf 5)
local GitCompete=""
local ColorCompensate=0
# Right side of prompt
# 1. git stuff
local GSP="$(git status --porcelain --branch 2>/dev/null)"
# Modified files
local GSPm="$(grep -c "^ M" <<< "${GSP}")"
if [ "${GSPm}" -gt "0" ]; then
GitString+="${Yel}!"
ColorCompensate=$((${ColorCompensate}+${#Yel}))
fi
# Staged and Tracked files
local GSPs="$(grep -c "^[AM] " <<< "${GSP}")"
if [ "${GSPs}" -gt "0" ]; then
GitString+="${Gre}+"
ColorCompensate=$((${ColorCompensate}+${#Gre}))
fi
# Deleted files
local GSPd="$(grep -c "^ D" <<< "${GSP}")"
if [ "${GSPd}" -gt "0" ]; then
GitString+="${Red}d"
ColorCompensate=$((${ColorCompensate}+${#Red}))
fi
# Untracked files
local GSPu="$(grep -c "^?" <<< "${GSP}")"
if [ "${GSPu}" -gt "0" ]; then
GitString+="${Red}?"
ColorCompensate=$((${ColorCompensate}+${#Red}))
fi
# Branch
local Branch="$(awk '/##/ {print $2}' <<< "${GSP}")"
GitString+="${Pur} ${Branch%...*}"
ColorCompensate=$((${ColorCompensate}+${#Pur}))
let Columns=$(tput cols)+${ColorCompensate}
printf "%*s" ${Columns} "${GitString} "
}
PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs
__prompt_command() {
local EXIT="$?" # This needs to be first
PS1=""
# to check colors use -
# for c in {0..255}; do tput setaf $c; tput setaf $c | cat -v; echo =$c ; done
local RCol=$(tput sgr0)
local Red=$(tput setaf 1)
local Gre=$(tput setaf 2)
local Yel=$(tput setaf 3)
local Pur=$(tput setaf 5)
local Cyan=$(tput setaf 6)
# printing Right Side of prompt and putting cursor back at start
PS1+="\[$(tput sc; rightPrompt; tput rc)\]"
# Left side of prompt
# 1. exit code color
# 2. current working directory
if [ $EXIT != 0 ]; then
PS1+="\[${Red}\]$EXIT> " # Add red if exit code non 0
else
PS1+="\[${Gre}\]> "
fi
PS1+="\[${Cyan}\]\W\[${RCol}\] "
}