This repository was archived by the owner on Nov 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
243 lines (208 loc) · 6.6 KB
/
bashrc
File metadata and controls
243 lines (208 loc) · 6.6 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#
# bashrc
#
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# Basic settings:
# ======================================================================= #
# set default editor
export EDITOR=vim
# don't put duplicate lines or lines starting with space in the history.
HISTCONTROL=ignoreboth
HISTSIZE=1000
HISTFILESIZE=2000
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# Source additional files
# ======================================================================= #
# ~/.bash_aliases file
if [ -f ~/.bash_aliases ] ; then
. ~/.bash_aliases
fi
# bash-completion
if ! shopt -oq posix ; then
if [ -f /usr/share/bash-completion/bash_completion ] ; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ] ; then
. /etc/bash_completion
fi
fi
# Check for color settings
# ======================================================================= #
case "$TERM" in
xterm-color|*-256color) color_term=yes;;
esac
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null ; then
# We have color support
color_term=yes
else
color_term=
fi
# Color settings
# ======================================================================= #
# enable color support of ls
if [[ "$color_term" = yes && -x /usr/bin/dircolors ]] ; then
eval `dircolors -b ~/.dircolors`
fi
# colorized man pages
if [ "$color_term" = yes ]; then
export GROFF_NO_SGR=1
fi
# variables below are as follows:
# _mb: begin 'blinking'
# _md: begin BOLD
# _me: end all effects
# _se: end 'standout mode'
# _so: begin 'standout mode'
# _ue: end underline mode
# _us: begin underline mode
if [ "$color_term" = yes ]; then
man() {
env \
LESS_TERMCAP_mb=$'\e[01;31m' \
LESS_TERMCAP_md=$'\e[01;40;37m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[00;45;30m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[00;36m' \
man "$@"
}
fi
# tar compression options reminder
reptar() {
echo "tar compression options:"
echo
echo " -J --xz"
echo
echo " -j --bzip2"
echo
echo " -z --gzip"
}
# Colors (including extra \[ and \] to surround non-printed codes in PS1
BLACK="\[\033[0;30m\]"
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"
MAGENTA="\[\033[0;35m\]"
CYAN="\[\033[0;36m\]"
WHITE="\[\033[0;37m\]"
COLOR_NONE="\[\033[0m\]"
# I'll handle the VIRTUAL_ENV prompt on my own thank you very much
VIRTUAL_ENV_DISABLE_PROMPT=1
__set_ps1 () {
PY_VENV_STRING=""
git_head=''
git_changed=''
git_new=''
git_staged=''
GIT_STATUS=''
GIT_BRANCH=''
GIT_STRING=''
# Python Virtual Environment
if [[ -n $CONDA_DEFAULT_ENV ]] && [[ -n $VIRTUAL_ENV ]] ; then
PY_VENV_STRING="${RED}{BAD!}${COLOR_NONE} "
elif [[ -n $CONDA_DEFAULT_ENV ]] ; then
PY_VENV_STRING="${MAGENTA}{${CONDA_DEFAULT_ENV}}${COLOR_NONE} "
elif [[ -n $VIRTUAL_ENV ]] ; then
PY_VENV_STRING="${MAGENTA}{`basename \"$VIRTUAL_ENV\"`}${COLOR_NONE} "
fi
# check if we are in git repository
if $(git rev-parse --git-dir >/dev/null 2>/dev/null); then
# check if we are in .git dir of repo
if $(git rev-parse --is-inside-git-dir 2>/dev/null); then
# ahh!!!
GIT_STATUS="${RED}"
GIT_BRANCH="(_GIT DIR!_)"
else
# check status
$(git diff --no-ext-diff --quiet) || git_changed='yes'
$(git ls-files --others --exclude-standard --directory \
--no-empty-directory --error-unmatch -- ':/*' \
> /dev/null 2> /dev/null) && git_new='yes'
$(git diff --no-ext-diff --cached --quiet) || git_staged='yes'
# set GIT_STATUS
if [ -z $git_changed ] && [ -z $git_new ] ; then
if [ -z $git_staged ] ; then
GIT_STATUS="${GREEN}"
else
GIT_STATUS="${YELLOW}"
fi
else
GIT_STATUS="${RED}"
fi
# set GIT_BRANCH
if git_head=$(git symbolic-ref --short -q HEAD); then
GIT_BRANCH=$git_head
else
GIT_BRANCH="(_DETACHED_)"
fi
fi
GIT_STRING="${GIT_STATUS}(${GIT_BRANCH})${COLOR_NONE} "
fi
PS1="${PY_VENV_STRING}${BLUE}\u${COLOR_NONE}:${CYAN}\w${COLOR_NONE} ${GIT_STRING}\$ "
}
PROMPT_COMMAND='__set_ps1'
# Use `printf '\033[1 q'` to set blinking, block cursor
printf '\033[1 q'
# remove duplicate entries from PATH
# as seen in: https://unix.stackexchange.com/questions/40749/remote-duplicate-path-entries-with-awk-command
if [ -n "$PATH" ]; then
old_PATH=$PATH:; PATH=
while [ -n "$old_PATH" ]; do
x=${old_PATH%%:*} # the first remaining entry
case $PATH: in
*:"$x":*) ;; # already there
*) PATH=$PATH:$x;; # not there yet
esac
old_PATH=${old_PATH#*:}
done
PATH=${PATH#:}
unset old_PATH x
fi
if [ -r ~/.bashrc.local ]; then
source ~/.bashrc.local
fi
# start tmux, unless not installed, not desired, or already running
if which tmux >/dev/null 2>&1; then
if [ -z $TMUX ]; then
echo "Opening tmux in 3 seconds."
if read -r -s -n 1 -t 3 -p "Press any key to cancel..." key; then
echo "not starting tmux..."
else
# start tmux
echo ""
echo "starting tmux..."
sleep 1
ID="$( tmux ls | grep -vm1 attached | cut -d: -f1 )" # get the id of a deattached session
if [[ -z "$ID" ]] ;then # if not available create a new one
exec tmux new-session
else
exec tmux attach-session -t "$ID" # if available attach to it
fi
fi
fi
fi
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/krisgerig/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/krisgerig/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/krisgerig/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/krisgerig/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<