-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bashrc
144 lines (128 loc) · 4.89 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
################################################################################
# ██████╗ █████╗ ███████╗██╗ ██╗██████╗ ██████╗
# ██╔══██╗██╔══██╗██╔════╝██║ ██║██╔══██╗██╔════╝
# ██████╔╝███████║███████╗███████║██████╔╝██║
# ██╔══██╗██╔══██║╚════██║██╔══██║██╔══██╗██║
# ██████╔╝██║ ██║███████║██║ ██║██║ ██║╚██████╗
# ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
################################################################################
# o┳━┓┳━┓┳━┓┳━┓o┏┓┓┳━┓┳━┓┳━┓┓ ┳
# ┃┃━┃┃━┫┃┳┛┃━┃┃ ┃ ┃┳┛┃━┫┃┳┛┗┏┛
# ┇┇━┛┛ ┇┇┗┛┇━┛┇ ┇ ┇┗┛┛ ┇┇┗┛ ┇
################################################################################
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
alias la='ls -la'
alias ll='ls -l'
alias cls='clear'
alias c='clear'
alias r='source ~/.bashrc'
alias q='exit'
alias :q='exit'
alias f='fish'
timer_now() {
date +%s%N
}
timer_start() {
timer_start=${timer_start:-$(timer_now)}
}
timer_stop() {
local delta_us=$((($(timer_now) - $timer_start) / 1000))
local us=$((delta_us % 1000))
local ms=$(((delta_us / 1000) % 1000))
local s=$(((delta_us / 1000000) % 60))
local m=$(((delta_us / 60000000) % 60))
local h=$((delta_us / 3600000000))
# Goal: always show around 3 digits of accuracy
if (( h > 0 )); then
timer_show=${h}h${m}m
elif (( m > 0 )); then
timer_show=${m}m${s}s
elif (( s >= 10 )); then
timer_show=${s}.$((ms / 100 ))s
elif (( s > 0 )); then
timer_show=${s}.$(printf %03d $ms)s
elif (( ms >= 100 )); then
timer_show=${ms}ms
elif (( ms > 0 )); then
timer_show=${ms}.$(( us / 100 ))ms
else
timer_show=${us}us
fi
unset timer_start
}
__prompt_command() {
local EXIT="$?"
PS1=""
local prompt="❯ᵇ "
local none='\[\e[0m\]'
local bold='\[\e[1m\]'
local faint='\[\e[2m\]'
local italic='\[\e[4m\]'
local teal='\[\e[96m\]'
local grey='\[\e[37m\]'
local red='\[\e[91m\]'
local green='\[\e[92m\]'
local BYel='\[\e[1;33m\]'
local BBlu='\[\e[1;34m\]'
local Pur='\[\e[0;35m\]'
timer_stop
local lasttime=$timer_show
local lasttimelength=${#lasttime}
local lasttimelength=$(expr $lasttimelength + 1)
local cwd=$(pwd | sed "s,$HOME,~,")
local columns=$(tput cols)
local lines=$(tput lines)
local rlength="12"
local llength=${#cwd}
#local exitlength=${#EXIT}
local exitlength=$(expr ${#EXIT} + 1)
local longenough=$(echo $lasttime | grep -P '\d\.\d+s')
if [ $EXIT = 0 ]; then
if [ $longenough ]; then
local padlength=$(expr $columns - $rlength - $llength - $lasttimelength - 0)
else
local padlength=$(expr $columns - $rlength - $llength - 0)
fi
else
if [ $longenough ]; then
local padlength=$(expr $columns - $rlength - $llength - $exitlength - $lasttimelength - 0)
else
local padlength=$(expr $columns - $rlength - $llength - $exitlength - 0)
fi
fi
local pad=$(seq -s· $padlength | tr -d '[:digit:]')
# line separation between prompts
PS1+="\n"
# current directory
PS1+="${bold}${teal}\w${none} "
# seperation between cwd and time
PS1+="${faint}${grey}${pad}${none} "
if [ $EXIT != 0 ]; then
PS1+="${bold}${red}${EXIT}${none} "
fi
# last command run-time
if [ $longenough ]; then
PS1+="${italic}${faint}${grey}${lasttime}${none} "
fi
# time
PS1+="${faint}${grey}\D{}${none}"
# prompt line
PS1+="\n"
#if last exit code 1 red prompt else green prompt
if [ $EXIT != 0 ]; then
PS1+="${red}${prompt}${none}" # Add red if exit code non 0
else
PS1+="${green}${prompt}${none}"
fi
}
trap 'timer_start' DEBUG
PROMPT_COMMAND=__prompt_command # Function to generate PS1 after CMDs
# For setting default text editor
export VISUAL='emacsclient --create-frame --alternate-editor=""'
export EDITOR='emacsclient --create-frame --alternate-editor=""'
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
eval 'dircolors ~/.dircolors' >/dev/null
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] && source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash