Last active 1717407740

My custom .bashrc file, heavily inspired by Parrot's one.

Revision aa1f9b50464f6399f1fbf47ed2dc4bb53c05b919

.bashrc Raw
1###### Color and Behavior ######
2
3case $- in
4 *i*) ;;
5 *) return;;
6esac
7
8# set a fancy prompt (non-color, unless we know we "want" color)
9case "$TERM" in
10 xterm-color) color_prompt=yes;;
11esac
12
13# uncomment for a colored prompt, if the terminal has the capability; turned
14# off by default to not distract the user: the focus in a terminal window
15# should be on the output of commands, not on the prompt
16force_color_prompt=yes
17
18if [ -n "$force_color_prompt" ]; then
19 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
20 # We have color support; assume it's compliant with Ecma-48
21 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
22 # a case would tend to support setf rather than setaf.)
23 color_prompt=yes
24 else
25 color_prompt=
26 fi
27fi
28
29# Set 'man' colors
30if [ "$color_prompt" = yes ]; then
31 man() {
32 env \
33 LESS_TERMCAP_mb=$'\e[01;31m' \
34 LESS_TERMCAP_md=$'\e[01;31m' \
35 LESS_TERMCAP_me=$'\e[0m' \
36 LESS_TERMCAP_se=$'\e[0m' \
37 LESS_TERMCAP_so=$'\e[01;44;33m' \
38 LESS_TERMCAP_ue=$'\e[0m' \
39 LESS_TERMCAP_us=$'\e[01;32m' \
40 man "$@"
41 }
42fi
43
44unset color_prompt force_color_prompt
45
46# enable color support of ls and also add handy aliases
47if [ -x /usr/bin/dircolors ]; then
48 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
49 alias ls='ls -G --color=auto'
50 alias dir='dir --color=auto'
51 alias vdir='vdir --color=auto'
52
53 alias grep='grep --color=auto'
54 alias fgrep='fgrep --color=auto'
55 alias egrep='egrep --color=auto'
56fi
57
58###### Useful ENV ######
59
60# These ones are useful if you are a 42 student
61export USER="your42login"
62export GROUP="your42login"
63export MAIL="[email protected]"
64# This one is not necessary, but quite useful for both the prompt and the CD command (you will see at the shopts)
65export work="path to your main work folder"
66
67# Here is the opportunity to add custom path folders
68PATH=/mnt/nfs/homes/mlabouri/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
69
70###### Aliases ######
71
72alias v2_norminette="~/norm/norminette.rb"
73
74alias ll='ls -lh'
75alias la='ls -lha'
76
77alias em='emacs -nw'
78
79alias dd='dd status=progress'
80
81alias _='sudo'
82alias _i='sudo -i'
83alias please='sudo'
84alias fucking='sudo'
85
86alias gcl='git clone'
87
88###### shopts ######
89
90# enable programmable completion features
91if ! shopt -oq posix; then
92 if [ -f /usr/share/bash-completion/bash_completion ]; then
93 . /usr/share/bash-completion/bash_completion
94 elif [ -f /etc/bash_completion ]; then
95 . /etc/bash_completion
96 fi
97fi
98
99# don't put duplicate lines or lines starting with space in the history.
100# See bash(1) for more options
101HISTCONTROL=ignoreboth
102
103# append to the history file, don't overwrite it
104shopt -s histappend
105
106# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
107HISTSIZE=1000
108HISTFILESIZE=2000
109
110# check the window size after each command and, if necessary,
111# update the values of LINES and COLUMNS.
112shopt -s checkwinsize
113
114# when using cd, corrects minor spelling errors
115shopt -s cdspell
116
117# "$<directory>" expands to "$cd <directory>"
118shopt -s autocd
119
120# if directory not found, treats argument as as variable (remember the work variable?)
121shopt -s cdable_vars
122
123# warns if jobs are running in background before exiting
124shopt -s checkjobs
125
126# do not autofill on empty line
127shopt -s no_empty_cmd_completion
128
129# Block > redir if overwrite happens, now needs to be >|
130set -C
131
132###### Prompt and Term Title ######
133
134# Used colors
135red_c="\[\033[0;31m\]"
136end_c="\[\e[0m\]"
137white_c="\[\033[0;39m\]"
138yellow_c="\[\033[01;33m\]"
139blue_c="\[\033[01;96m\]"
140blue_oc="\[\033[0;96m\]"
141green_c="\[\033[0;32m\]"
142
143# Used charsets
144bottomCharset="\342\224\224\342\224\200\342\224\200\342\225\274"
145topCharset="\342\224\214\342\224\200"
146crossCharset="\342\234\227"
147dashCharset="\342\224\200"
148
149# This provides the current branch you are working in
150gitStatus=""
151function setGitStatus {
152 git_status=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
153}
154
155function psOne {
156 # Last process return value
157 c_status=$?
158 # Count number of running background jobs
159 r_jobs=$(jobs | wc -l)
160 # Count number of existing docker containers
161 r_containers=$(docker ps -a 2>/dev/null | sed '1d' | wc -l)
162
163 # Your path, with a replacement for HOME and work path
164 path_r=$(pwd | sed "s|$HOME|~|" | sed "s|$work|work|")
165 # Your current computer @42 (or just the hostname cut at the first dot)
166 host_r=$(hostname | cut -d "." -f1 )
167
168 setGitStatus
169 # Random bullshit go, good luck with debugging
170 PS1="$red_c$topCharset$(if [[ $c_status != 0 ]]; then echo "[$white_c$crossCharset$red_c]$dashCharset"; fi)"
171 PS1+="$(if [[ $r_jobs != 0 ]]; then echo "[$white_c$r_jobs$red_c]$dashCharset"; fi)"
172 PS1+="[$white_c\u$yellow_c@$blue_c\h$red_c]$dashCharset[$green_c$path_r$red_c]"
173 PS1+="$(if [[ "$git_status" ]]; then echo "$dashCharset[$blue_c$git_status$red_c]"; fi)"
174 PS1+="$(if [[ $r_containers != 0 ]]; then echo "$dashCharset<$blue_oc$r_containers$red_c>"; fi)"
175 PS1+="\n$bottomCharset $yellow_c\$$end_c"
176}
177
178# Set ps1_sp to the title you want for your terminal
179function updateTitle {
180 ps1_sp=$(echo "Hello!")
181 echo -en "\033]0;$ps1_sp\a"
182}
183
184PROMPT_COMMAND='psOne'

Powered by Opengist ⋅ Load: 23ms