Last active 1717407740

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

Revision 5b6b56bf975760bf0a5fa78f73445b6f0d693c08

.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# This one is not necessary, but quite useful for both the prompt and the CD command (you will see at the shopts)
60export work="path to your main work folder"
61
62# Here is the opportunity to add custom path folders
63#PATH=
64
65###### Aliases ######
66
67alias v2_norminette="~/norm/norminette.rb"
68
69alias ll='ls -lh'
70alias la='ls -lha'
71
72alias dd='dd status=progress'
73
74alias _='sudo'
75alias _i='sudo -i'
76alias please='sudo'
77alias fucking='sudo'
78
79alias gcl='git clone'
80
81###### shopts ######
82
83# enable programmable completion features
84if ! shopt -oq posix; then
85 if [ -f /usr/share/bash-completion/bash_completion ]; then
86 . /usr/share/bash-completion/bash_completion
87 elif [ -f /etc/bash_completion ]; then
88 . /etc/bash_completion
89 fi
90fi
91
92# don't put duplicate lines or lines starting with space in the history.
93# See bash(1) for more options
94HISTCONTROL=ignoreboth
95
96# append to the history file, don't overwrite it
97shopt -s histappend
98
99# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
100HISTSIZE=1000
101HISTFILESIZE=2000
102
103# check the window size after each command and, if necessary,
104# update the values of LINES and COLUMNS.
105shopt -s checkwinsize
106
107# when using cd, corrects minor spelling errors
108shopt -s cdspell
109
110# "$<directory>" expands to "$cd <directory>"
111shopt -s autocd
112
113# if directory not found, treats argument as as variable (remember the work variable?)
114shopt -s cdable_vars
115
116# warns if jobs are running in background before exiting
117shopt -s checkjobs
118
119# do not autofill on empty line
120shopt -s no_empty_cmd_completion
121
122# Block > redir if overwrite happens, now needs to be >|
123set -C
124
125###### Prompt and Term Title ######
126
127# Used colors
128red_c="\[\033[0;31m\]"
129end_c="\[\e[0m\]"
130white_c="\[\033[0;39m\]"
131yellow_c="\[\033[01;33m\]"
132blue_c="\[\033[01;96m\]"
133blue_oc="\[\033[0;96m\]"
134green_c="\[\033[0;32m\]"
135
136# Used charsets
137bottomCharset="\342\224\224\342\224\200\342\224\200\342\225\274"
138topCharset="\342\224\214\342\224\200"
139crossCharset="\342\234\227"
140dashCharset="\342\224\200"
141
142# This provides the current branch you are working in
143gitStatus=""
144function setGitStatus {
145 git_status=$(printf "%.10s" $(git rev-parse --abbrev-ref HEAD 2>/dev/null))
146}
147
148function psOne {
149 # Last process return value
150 c_status=$?
151 # Count number of running background jobs
152 r_jobs=$(jobs | wc -l)
153 # Count number of existing docker containers
154 r_containers=$(docker ps -a 2>/dev/null | sed '1d' | wc -l)
155
156 # Your path, with a replacement for HOME and work path
157 path_r=$(pwd | sed "s|$HOME|~|" | sed "s|$work|work|")
158 # Your current computer @42 (or just the hostname cut at the first dot)
159 host_r=$(hostname | cut -d "." -f1 )
160
161 setGitStatus
162 # Random bullshit go, good luck with debugging
163 PS1="$red_c$topCharset$(if [[ $c_status != 0 ]]; then echo "[$white_c$crossCharset$red_c]$dashCharset"; fi)"
164 PS1+="$(if [[ $r_jobs != 0 ]]; then echo "[$white_c$r_jobs$red_c]$dashCharset"; fi)"
165 PS1+="[$white_c\u$yellow_c@$blue_c\h$red_c]$dashCharset[$green_c$path_r$red_c]"
166 PS1+="$(if [[ "$git_status" ]]; then echo "$dashCharset[$blue_c$git_status$red_c]"; fi)"
167 PS1+="$(if [[ $r_containers != 0 ]]; then echo "$dashCharset<$blue_oc$r_containers$red_c>"; fi)"
168 PS1+="\n$bottomCharset $yellow_c\$$end_c"
169}
170
171# Set ps1_sp to the title you want for your terminal
172function updateTitle {
173 ps1_sp=$(echo "Hello!")
174 echo -en "\033]0;$ps1_sp\a"
175}
176
177PROMPT_COMMAND='psOne'

Powered by Opengist ⋅ Load: 24ms