-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bashrc
474 lines (411 loc) · 14.4 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# Exports
export EDITOR=/usr/bin/nano # For lightweight purposes.
# For heavyweight purposes.
if [[ -x "$(command -v nvim)" ]]; then
export VISUAL="/usr/bin/nvim"
elif [[ -x "$(command -v vim)" ]]; then
export VISUAL="/usr/bin/vim"
alias nvim="vim"
else
export VISUAL="/usr/bin/nano"
fi
export PAGER='less'
export MANPAGER='less'
if [[ -x "$(command -v firefox)" ]]; then
export BROWSER="firefox '%' &"
elif [[ -x "$(command -v google-chrome-stable)" ]]; then
export BROWSER="google-chrome-stable '%' &"
elif [[ -x "$(command -v chromium)" ]]; then
export BROWSER="chromium '%' &"
fi
# Resolves an occasional issue with screenfetch.
if [[ -d "/usr/lib/x86_64-linux-gnu/gio/modules/" ]]; then
export GIO_EXTRA_MODULES="/usr/lib/x86_64-linux-gnu/gio/modules/"
fi
add-path() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
add-path "$HOME/bin/"
add-path "/sbin/"
add-path "/usr/sbin/"
export PROMPT_DIRTRIM=3 # Show the last 3 directories in the prompt.
# Dynamically set term to the right prefix.
case $TERM in
konsole|xterm|screen|tmux|rxvt-unicode)
TERM="$TERM-256color";;
esac
# Colors
RED='\e[0;31m'
LIGHTRED='\e[1;31m'
YELLOW='\e[1;33m'
GREEN='\e[0;32m'
LIGHTGREEN='\e[1;32m'
CYAN='\e[0;36m'
LIGHTCYAN='\e[1;36m'
BLUE='\e[0;34m'
LIGHTBLUE='\e[1;34m'
PURPLE='\e[0;35m'
LIGHTPURPLE='\e[1;35m'
BROWN='\e[0;33m'
BLACK='\e[0;30m'
DARKGREY='\e[1;30m'
LIGHTGREY='\e[0;37m'
WHITE='\e[1;37m'
NC='\e[0m' # "No color"
RESET=$NC
BLINK='\e[5m'
BOLD='\e[1m'
# Settings
time_indicator=yes
resource_indicator=yes
enable_banner=yes
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
shopt -s histappend # append to the history file, don't overwrite it
shopt -s cdspell # automatically correct typos in directories when using cd
shopt -s nocaseglob # case insensitive directory search
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
_shrunkPrompt=""
_normalPrompt=""
if [ "$color_prompt" = yes ]; then
_shrunkPrompt='\[\033[00m\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$\[$(tput sgr0)\]\[\033[00m\] '
#PS1="${RESET}${debian_chroot:+($debian_chroot)}${LIGHTGREY}[${DARKGREY}\T${LIGHTGREY}] ${LIGHTGREEN}\u${DARKGREY}@${GREEN}\h${RESET}:${LIGHTBLUE}\w${RESET}\\$\[$(tput sgr0)\]${RESET} " # This string will not work, but is a more human readable version
#PS1='\[\033[00m\]${debian_chroot:+($debian_chroot)}\[\033[00;37m\][\[\033[01;30m\]\T\[\033[00;37m\]] \[\033[01;32m\]\u\[\033[01;30m\]@\[\033[00;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$\[$(tput sgr0)\]\[\033[00m\] '
# [C|R|H|S] = [CPU|RAM|HDD|SSH]
PS1='\[\033[00m\]${debian_chroot:+($debian_chroot)}'
if [ "$time_indicator" = yes ]; then
PS1=${PS1}'\[\033[00;37m\][\[\033[01;30m\]\t\[\033[00;37m\]]'
fi
# if [ "$resource_indicator" = yes ]; then
# sep="\[${LIGHTGREY}\]"
# connectionSecurity=""
# cpuLoad=""
# ramLoad=""
# hddLoad=""
#
#
# # CPU Load
# nCpu=$(grep -c 'processor' /proc/cpuinfo)
# sLoad=$(( 100 * $nCpu ))
# local mLoad=$(( 200 *${nCpu} ))
# local lLoad=$(( 400*${nCpu} ))
#
# load() {
# local SYSLOAD=$(cut -d " " -f1 /proc/loadavg | tr -d '.')
# echo $((10#$SYSLOAD))
# }
#
# # Returns a color indicating system load.
# load_color() {
# local SYSLOAD=$(load)
# if [ ${SYSLOAD} -gt ${lLoad} ]; then
# echo -en "\[${RED}\]"
# elif [ ${SYSLOAD} -gt ${MLOAD} ]; then
# echo -en "\[${LIGHTRED}\]"
# elif [ ${SYSLOAD} -gt ${SLOAD} ]; then
# echo -en "\[${YELLOW}\]"
# else
# echo -en "\[${GREEN}\]"
# fi
# }
#
# cpuLoad=$(load_color)
#
# # CPU Load
# function load()
# {
# local SYSLOAD=$(cut -d " " -f1 /proc/loadavg | tr -d '.')
# # System load of the current host.
# echo $((10#$SYSLOAD)) # Convert to decimal.
# }
#
# local nCpu=$(grep -c 'processor' /proc/cpuinfo)
# local sLoad=$(( 100*${nCpu} ))
# local mLoad=$(( 200*${nCpu} ))
# local lLoad=$(( 400*${nCpu} ))
#
# local SYSLOAD=$(cut -d " " -f1 /proc/loadavg | tr -d '.')
# SYSLOAD=$(( 10#$SYSLOAD ))
#
# if [ ${SYSLOAD} -gt ${lLoad} ]; then
# cpuLoad="\[${RED}\]"
# elif [ ${SYSLOAD} -gt ${mLoad} ]; then
# cpuLoad="\[${LIGHTRED}\]"
# elif [ ${SYSLOAD} -gt ${sLoad} ]; then
# cpuLoad="\[${YELLOW}\]"
# else
# cpuLoad="\[${GREEN}\]"
# fi
#
# # RAM Load
# ramPercent=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
# ramPercent=$(( 10#
# if [ ${ramPercent} -gt ${lLoad} ]; then
# cpuLoad="\[${RED}\]"
# elif [ ${SYSLOAD} -gt ${mLoad} ]; then
# cpuLoad="\[${LIGHTRED}\]"
# elif [ ${SYSLOAD} -gt ${sLoad} ]; then
# cpuLoad="\[${YELLOW}\]"
# else
# cpuLoad="\[${GREEN}\]"
# fi
#
# # Free HDD space
#
# # Secure Connection
# if [ -n "${SSH_CONNECTION}" ]; then
# connectionSecurity="\[${GREEN}\]" # Connected remotely via ssh (secure).
# elif [[ "${DISPLAY%%:0*}" != "" ]]; then
# connectionSecurity="\[${RED}\]" # Connected remotely not via ssh (insecure).
# else
# connectionSecurity="\[${CYAN}\]" # Connected on local machine.
# fi
#
#
# PS1=${PS1}"\[\033[00;37m\][\[\033[01;30m\]${cpuLoad}C${sep}|${ramLoad}R${sep}|H${sep}|${connectionSecurity}S\[\033[00;37m\]]"
# fi
PS1=${PS1}' \[\033[01;32m\]\u\[\033[01;30m\]@\[\033[00;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\\$\[$(tput sgr0)\]\[\033[00m\] '
_normalPrompt=${PS1}
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' # Ubuntu's original
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset time_indicator resource_indicator color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
elif [ -x /usr/share/doc/pkgfile/command-not-found.bash ]; then
# For Arch based systems (pacman -S pkgfile command-not-found)
/usr/share/doc/pkgfile/command-not-found.bash -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Fix tmux 256 colors:
alias tmux='tmux -2'
# Clear color codes before clearing:
alias clear='echo -e "\e[0m" && clear'
# Typical rsync command
alias relocate='rsync -avzh --info=progress2'
# Display the last two directories relative to the working directory.
#export PS1="\[\033[0;32m\]\u@\h \[\033[33m\]\$(pwd)\[\033[0m\] \$ ";
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
# Aliases, functions, commands, etc.
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "Unknown filetype for '$1'" ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
colors () {
echo 'Usage: ${LIGHTPURPLE}Your text ${BLINK}here${RESET}'
echo -e " > ${LIGHTPURPLE}Your text ${BLINK}here${RESET}"
echo -e "Special colors: ${BLINK}BLINK ${NC}NC ${BOLD}BOLD ${RESET}RESET"
echo -e "Normal colors: ${RED}RED ${LIGHTRED}LIGHTRED ${YELLOW}YELLOW ${GREEN}GREEN ${LIGHTGREEN}LIGHTGREEN ${CYAN}CYAN ${LIGHTCYAN} ${BLUE}BLUE ${LIGHTBLUE}LIGHTBLUE ${PURPLE}PURPLE ${LIGHTPURPLE}LIGHTPURPLE ${BROWN}BROWN ${BLACK}BLACK ${DARKGREY}DARKGREY ${LIGHTGREY}LIGHTGREY ${WHITE}WHITE"
}
# Join a telnet based movie theater.
starwars() {
telnet towel.blinkenlights.nl
}
# Download and run a curl based Party Parrot animation.
parrot() {
curl parrot.live
}
# Duplicate of parrot()
party() {
parrot
}
# Ascend the directories X times.
up() {
DEEP=$1
[ -z "${DEEP}" ] && {
DEEP=1
}
for i in $(seq 1 ${DEEP})
do cd ../
done;
}
_shrunk=no
shrink() {
if [ "$_shrunk" = no ]; then
_shrunk=yes
PS1=${_shrunkPrompt}
else
_shrunk=no
PS1=${_normalPrompt}
fi
}
alias grow='shrink'
fix-keys() {
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com "$(sudo apt update 2>&1 | grep -o '[0-9A-Z]\{16\}$' | xargs)"
}
# Banner
if [ "$enable_banner" = yes ]; then
#clear; clear
if hash screenfetch 2>/dev/null; then
screenfetch -w -d '-pkgs,wm,de,res,gtk;+disk' -E
# Fix older versions.
if [[ "$?" -ne 0 ]]; then
clear
screenfetch -d '-pkgs,wm,de,res,gtk;+disk' -E
fi
else
echo -e "${LIGHTBLUE}${BOLD}Welcome back, $USER!${RESET}"
if hash fortune 2>/dev/null; then
fortune -s
fi
echo ""
fi
fi
unset enable_banner
if [ -d "$HOME/anaconda3/bin/" ]; then
export PATH="$HOME/anaconda3/bin:$PATH"
fi
if [[ -d "$HOME/.anaconda3/bin" ]]; then
export PATH="$HOME/.anaconda3/bin:$PATH"
fi
if [ -d "$HOME/.neovim-studio/" ] && [ -z "${NEOVIM_STUDIO_PROFILE_SOURCED}" ]; then
source "$HOME/.profile"
if [ -z "${NEOVIM_STUDIO_PROFILE_SOURCED}" ]; then
# Doesn't exist within the profile.
export NEOVIM_STUDIO_PROFILE_SOURCED=1
fi
fi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
if [[ -x "$(command -v navi)" ]]; then
eval "$(navi widget bash)"
fi
if [[ -d "$HOME/bin" ]]; then
export PATH="$PATH:$HOME/bin"
fi
# NVIDIA CUDA
if [[ -d "/usr/local/cuda/bin" ]]; then
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
# TODO: Set this to dynamically select 32bit path if on a 32bit system.
fi
if [[ -d "$HOME/.rbenv/" ]]; then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
fi
# added by Anaconda2 installer
#export PATH="/home/max/.anaconda2/bin:$PATH"
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/max/.anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/home/max/.anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/max/.anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/home/max/.anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
# Disabled for Cave workspaces.
#if [[ -s "$HOME/batsrc/.batsdevrc" ]]; then
#source "$HOME/batsrc/.batsdevrc"
#fi