-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
551 lines (434 loc) · 17.6 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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# 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
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# 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|*-256color) 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
if [ "$color_prompt" = yes ]; then
# override default virtualenv indicator in prompt
VIRTUAL_ENV_DISABLE_PROMPT=1
prompt_color='\[\033[;32m\]'
info_color='\[\033[1;34m\]'
prompt_symbol=㉿
if [ "$EUID" -eq 0 ]; then # Change prompt colors for root user
prompt_color='\[\033[;94m\]'
info_color='\[\033[1;31m\]'
prompt_symbol=💀
fi
PS1=$prompt_color'┌──${debian_chroot:+($debian_chroot)──}${VIRTUAL_ENV:+(\[\033[0;1m\]$(basename $VIRTUAL_ENV)'$prompt_color')}('$info_color'\u${prompt_symbol}\h'$prompt_color')-[\[\033[0;1m\]\w'$prompt_color']\n'$prompt_color'└─'$info_color'\$\[\033[0m\] '
# BackTrack red prompt
#PS1='${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV)) }${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset 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, less and man, 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'
alias diff='diff --color=auto'
alias ip='ip --color=auto'
export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink
export LESS_TERMCAP_md=$'\E[1;36m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink
export LESS_TERMCAP_so=$'\E[01;33m' # begin reverse video
export LESS_TERMCAP_se=$'\E[0m' # reset reverse video
export LESS_TERMCAP_us=$'\E[1;32m' # begin underline
export LESS_TERMCAP_ue=$'\E[0m' # reset underline
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
# 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 ! 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
## +-----------------------------------+-----------------------------------+
## | |
## | FANCY BASH PROMT |
## | |
## | Copyright (c) 2018, Andres Gongora <[email protected]>. |
## | |
## | This program is free software: you can redistribute it and/or modify |
## | it under the terms of the GNU General Public License as published by |
## | the Free Software Foundation, either version 3 of the License, or |
## | (at your option) any later version. |
## | |
## | This program is distributed in the hope that it will be useful, |
## | but WITHOUT ANY WARRANTY; without even the implied warranty of |
## | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
## | GNU General Public License for more details. |
## | |
## | You should have received a copy of the GNU General Public License |
## | along with this program. If not, see <http://www.gnu.org/licenses/>. |
## | |
## +-----------------------------------------------------------------------+
##
## DESCRIPTION:
## This script updates your "PS1" environment variable to display colors.
## Addicitionally, it also shortens the name of your current part to maximum
## 25 characters, which is quite useful when working in deeply nested folders.
##
##
##
## INSTALLATION:
## Copy this script to your home folder and rename it to ".fancy-bash-promt.sh"
## Run this command from any terminal:
## echo "source ~/.fancy-bash-promt.sh" >> ~/.bashrc
##
## Alternatively, copy the content of this file into your .bashrc file
##
##
##
## FUNCTIONS:
##
## * bash_prompt_command()
## This function takes your current working directory and stores a shortened
## version in the variable "NEW_PWD".
##
## * format_font()
## A small helper function to generate color formating codes from simple
## number codes (defined below as local variables for convenience).
##
## * bash_prompt()
## This function colorizes the bash promt. The exact color scheme can be
## configured here. The structure of the function is as follows:
## 1. A. Definition of available colors for 16 bits.
## 1. B. Definition of some colors for 256 bits (add your own).
## 2. Configuration >> EDIT YOUR PROMT HERE<<.
## 4. Generation of color codes.
## 5. Generation of window title (some terminal expect the first
## part of $PS1 to be the window title)
## 6. Formating of the bash promt ($PS1).
##
## * Main script body:
## It calls the adequate helper functions to colorize your promt and sets
## a hook to regenerate your working directory "NEW_PWD" when you change it.
##
################################################################################
## FUNCTIONS ##
################################################################################
##
## ARRANGE $PWD AND STORE IT IN $NEW_PWD
## * The home directory (HOME) is replaced with a ~
## * The last pwdmaxlen characters of the PWD are displayed
## * Leading partial directory names are striped off
## /home/me/stuff -> ~/stuff (if USER=me)
## /usr/share/big_dir_name -> ../share/big_dir_name (if pwdmaxlen=20)
##
## Original source: WOLFMAN'S color bash promt
## https://wiki.chakralinux.org/index.php?title=Color_Bash_Prompt#Wolfman.27s
##
bash_prompt_command() {
# How many characters of the $PWD should be kept
local pwdmaxlen=25
# Indicate that there has been dir truncation
local trunc_symbol=".."
# Store local dir
local dir=${PWD##*/}
# Which length to use
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
# Generate name
if [ ${pwdoffset} -gt "0" ]
then
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
fi
}
##
## GENERATE A FORMAT SEQUENCE
##
format_font()
{
## FIRST ARGUMENT TO RETURN FORMAT STRING
local output=$1
case $# in
2)
eval $output="'\[\033[0;${2}m\]'"
;;
3)
eval $output="'\[\033[0;${2};${3}m\]'"
;;
4)
eval $output="'\[\033[0;${2};${3};${4}m\]'"
;;
*)
eval $output="'\[\033[0m\]'"
;;
esac
}
##
## COLORIZE BASH PROMT
##
bash_prompt() {
############################################################################
## COLOR CODES ##
## These can be used in the configuration below ##
############################################################################
## FONT EFFECT
local NONE='0'
local BOLD='1'
local DIM='2'
local UNDERLINE='4'
local BLINK='5'
local INVERT='7'
local HIDDEN='8'
## COLORS
local DEFAULT='9'
local BLACK='0'
local RED='1'
local GREEN='2'
local YELLOW='3'
local BLUE='4'
local MAGENTA='5'
local CYAN='6'
local L_GRAY='7'
local D_GRAY='60'
local L_RED='61'
local L_GREEN='62'
local L_YELLOW='63'
local L_BLUE='64'
local L_MAGENTA='65'
local L_CYAN='66'
local WHITE='67'
## TYPE
local RESET='0'
local EFFECT='0'
local COLOR='30'
local BG='40'
## 256 COLOR CODES
local NO_FORMAT="\[\033[0m\]"
local ORANGE_BOLD="\[\033[1;38;5;208m\]"
local TOXIC_GREEN_BOLD="\[\033[1;38;5;118m\]"
local RED_BOLD="\[\033[1;38;5;1m\]"
local CYAN_BOLD="\[\033[1;38;5;87m\]"
local BLACK_BOLD="\[\033[1;38;5;0m\]"
local WHITE_BOLD="\[\033[1;38;5;15m\]"
local GRAY_BOLD="\[\033[1;90m\]"
local BLUE_BOLD="\[\033[1;38;5;74m\]"
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## CONFIGURE HERE ##
############################################################################
## CONFIGURATION ##
## Choose your color combination here ##
############################################################################
local FONT_COLOR_1=$WHITE
local BACKGROUND_1=$BLUE
local TEXTEFFECT_1=$BOLD
local FONT_COLOR_2=$WHITE
local BACKGROUND_2=$L_BLUE
local TEXTEFFECT_2=$BOLD
local FONT_COLOR_3=$D_GRAY
local BACKGROUND_3=$WHITE
local TEXTEFFECT_3=$BOLD
local PROMT_FORMAT=$BLUE_BOLD
############################################################################
## EXAMPLE CONFIGURATIONS ##
## I use them for different hosts. Test them out ;) ##
############################################################################
## CONFIGURATION: BLUE-WHITE
if [ "$HOSTNAME" = dell ]; then
FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLUE; TEXTEFFECT_1=$BOLD
FONT_COLOR_2=$WHITE; BACKGROUND_2=$L_BLUE; TEXTEFFECT_2=$BOLD
FONT_COLOR_3=$D_GRAY; BACKGROUND_3=$WHITE; TEXTEFFECT_3=$BOLD
PROMT_FORMAT=$CYAN_BOLD
fi
## CONFIGURATION: BLACK-RED
if [ "$HOSTNAME" = giraff6 ]; then
FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
FONT_COLOR_3=$WHITE; BACKGROUND_3=$RED; TEXTEFFECT_3=$BOLD
PROMT_FORMAT=$RED_BOLD
fi
## CONFIGURATION: RED-BLACK
#FONT_COLOR_1=$WHITE; BACKGROUND_1=$RED; TEXTEFFECT_1=$BOLD
#FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
#FONT_COLOR_3=$WHITE; BACKGROUND_3=$BLACK; TEXTEFFECT_3=$BOLD
#PROMT_FORMAT=$RED_BOLD
## CONFIGURATION: CYAN-BLUE
if [ "$HOSTNAME" = sharkoon ]; then
FONT_COLOR_1=$BLACK; BACKGROUND_1=$L_CYAN; TEXTEFFECT_1=$BOLD
FONT_COLOR_2=$WHITE; BACKGROUND_2=$L_BLUE; TEXTEFFECT_2=$BOLD
FONT_COLOR_3=$WHITE; BACKGROUND_3=$BLUE; TEXTEFFECT_3=$BOLD
PROMT_FORMAT=$CYAN_BOLD
fi
## CONFIGURATION: GRAY-SCALE
if [ "$HOSTNAME" = giraff ]; then
FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
FONT_COLOR_3=$WHITE; BACKGROUND_3=$L_GRAY; TEXTEFFECT_3=$BOLD
PROMT_FORMAT=$BLACK_BOLD
fi
## CONFIGURATION: GRAY-CYAN
if [ "$HOSTNAME" = light ]; then
FONT_COLOR_1=$WHITE; BACKGROUND_1=$BLACK; TEXTEFFECT_1=$BOLD
FONT_COLOR_2=$WHITE; BACKGROUND_2=$D_GRAY; TEXTEFFECT_2=$BOLD
FONT_COLOR_3=$BLACK; BACKGROUND_3=$L_CYAN; TEXTEFFECT_3=$BOLD
PROMT_FORMAT=$CYAN_BOLD
fi
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
############################################################################
## TEXT FORMATING ##
## Generate the text formating according to configuration ##
############################################################################
## CONVERT CODES: add offset
FC1=$(($FONT_COLOR_1+$COLOR))
BG1=$(($BACKGROUND_1+$BG))
FE1=$(($TEXTEFFECT_1+$EFFECT))
FC2=$(($FONT_COLOR_2+$COLOR))
BG2=$(($BACKGROUND_2+$BG))
FE2=$(($TEXTEFFECT_2+$EFFECT))
FC3=$(($FONT_COLOR_3+$COLOR))
BG3=$(($BACKGROUND_3+$BG))
FE3=$(($TEXTEFFECT_3+$EFFECT))
FC4=$(($FONT_COLOR_4+$COLOR))
BG4=$(($BACKGROUND_4+$BG))
FE4=$(($TEXTEFFECT_4+$EFFECT))
## CALL FORMATING HELPER FUNCTION: effect + font color + BG color
local TEXT_FORMAT_1
local TEXT_FORMAT_2
local TEXT_FORMAT_3
local TEXT_FORMAT_4
format_font TEXT_FORMAT_1 $FE1 $FC1 $BG1
format_font TEXT_FORMAT_2 $FE2 $FC2 $BG2
format_font TEXT_FORMAT_3 $FC3 $FE3 $BG3
format_font TEXT_FORMAT_4 $FC4 $FE4 $BG4
# GENERATE PROMT SECTIONS
local PROMT_USER=$"$TEXT_FORMAT_1 \u "
local PROMT_HOST=$"$TEXT_FORMAT_2 \h "
local PROMT_PWD=$"$TEXT_FORMAT_3 \${NEW_PWD} "
local PROMT_INPUT=$"$PROMT_FORMAT "
############################################################################
## SEPARATOR FORMATING ##
## Generate the separators between sections ##
## Uses background colors of the sections ##
############################################################################
## CONVERT CODES
TSFC1=$(($BACKGROUND_1+$COLOR))
TSBG1=$(($BACKGROUND_2+$BG))
TSFC2=$(($BACKGROUND_2+$COLOR))
TSBG2=$(($BACKGROUND_3+$BG))
TSFC3=$(($BACKGROUND_3+$COLOR))
TSBG3=$(($DEFAULT+$BG))
## CALL FORMATING HELPER FUNCTION: effect + font color + BG color
local SEPARATOR_FORMAT_1
local SEPARATOR_FORMAT_2
local SEPARATOR_FORMAT_3
format_font SEPARATOR_FORMAT_1 $TSFC1 $TSBG1
format_font SEPARATOR_FORMAT_2 $TSFC2 $TSBG2
format_font SEPARATOR_FORMAT_3 $TSFC3 $TSBG3
# GENERATE SEPARATORS WITH FANCY TRIANGLE
local TRIANGLE=$'\uE0B0'
local SEPARATOR_1=$SEPARATOR_FORMAT_1$TRIANGLE
local SEPARATOR_2=$SEPARATOR_FORMAT_2$TRIANGLE
local SEPARATOR_3=$SEPARATOR_FORMAT_3$TRIANGLE
############################################################################
## WINDOW TITLE ##
## Prevent messed up terminal-window titles ##
############################################################################
case $TERM in
xterm*|rxvt*)
local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
;;
*)
local TITLEBAR=""
;;
esac
############################################################################
## BASH PROMT ##
## Generate promt and remove format from the rest ##
############################################################################
PS1="$TITLEBAR\n${PROMT_USER}${SEPARATOR_1}${PROMT_HOST}${SEPARATOR_2}${PROMT_PWD}${SEPARATOR_3}${PROMT_INPUT}"
## For terminal line coloring, leaving the rest standard
none="$(tput sgr0)"
trap 'echo -ne "${none}"' DEBUG
}
################################################################################
## MAIN ##
################################################################################
## Bash provides an environment variable called PROMPT_COMMAND.
## The contents of this variable are executed as a regular Bash command
## just before Bash displays a prompt.
## We want it to call our own command to truncate PWD and store it in NEW_PWD
PROMPT_COMMAND=bash_prompt_command
## Call bash_promnt only once, then unset it (not needed any more)
## It will set $PS1 with colors and relative to $NEW_PWD,
## which gets updated by $PROMT_COMMAND on behalf of the terminal
bash_prompt
unset bash_prompt
### EOF ###