.bashrc
Raw
###### Color and Behavior ######
case $- in
*i*) ;;
*) return;;
esac
# 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
# Set 'man' colors
if [ "$color_prompt" = yes ]; then
man() {
env \
LESS_TERMCAP_mb=$'\e[01;31m' \
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[01;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[01;32m' \
man "$@"
}
fi
unset color_prompt force_color_prompt
# 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 -G --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
###### Useful ENV ######
# These ones are useful if you are a 42 student
export USER="your42login"
export GROUP="your42login"
export MAIL="[email protected]"
# This one is not necessary, but quite useful for both the prompt and the CD command (you will see at the shopts)
export work="path to your main work folder"
# Here is the opportunity to add custom path folders
PATH=/mnt/nfs/homes/mlabouri/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
###### Aliases ######
alias v2_norminette="~/norm/norminette.rb"
alias ll='ls -lh'
alias la='ls -lha'
alias em='emacs -nw'
alias dd='dd status=progress'
alias _='sudo'
alias _i='sudo -i'
alias please='sudo'
alias fucking='sudo'
alias gcl='git clone'
###### shopts ######
# enable programmable completion features
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
# 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
# when using cd, corrects minor spelling errors
shopt -s cdspell
# "$<directory>" expands to "$cd <directory>"
shopt -s autocd
# if directory not found, treats argument as as variable (remember the work variable?)
shopt -s cdable_vars
# warns if jobs are running in background before exiting
shopt -s checkjobs
# do not autofill on empty line
shopt -s no_empty_cmd_completion
# Block > redir if overwrite happens, now needs to be >|
set -C
###### Prompt and Term Title ######
# Used colors
red_c="\[\033[0;31m\]"
end_c="\[\e[0m\]"
white_c="\[\033[0;39m\]"
yellow_c="\[\033[01;33m\]"
blue_c="\[\033[01;96m\]"
blue_oc="\[\033[0;96m\]"
green_c="\[\033[0;32m\]"
# Used charsets
bottomCharset="\342\224\224\342\224\200\342\224\200\342\225\274"
topCharset="\342\224\214\342\224\200"
crossCharset="\342\234\227"
dashCharset="\342\224\200"
# This provides the current branch you are working in
gitStatus=""
function setGitStatus {
git_status=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
}
function psOne {
# Last process return value
c_status=$?
# Count number of running background jobs
r_jobs=$(jobs | wc -l)
# Count number of existing docker containers
r_containers=$(docker ps -a 2>/dev/null | sed '1d' | wc -l)
# Your path, with a replacement for HOME and work path
path_r=$(pwd | sed "s|$HOME|~|" | sed "s|$work|work|")
# Your current computer @42 (or just the hostname cut at the first dot)
host_r=$(hostname | cut -d "." -f1 )
setGitStatus
# Random bullshit go, good luck with debugging
PS1="$red_c$topCharset$(if [[ $c_status != 0 ]]; then echo "[$white_c$crossCharset$red_c]$dashCharset"; fi)"
PS1+="$(if [[ $r_jobs != 0 ]]; then echo "[$white_c$r_jobs$red_c]$dashCharset"; fi)"
PS1+="[$white_c\u$yellow_c@$blue_c\h$red_c]$dashCharset[$green_c$path_r$red_c]"
PS1+="$(if [[ "$git_status" ]]; then echo "$dashCharset[$blue_c$git_status$red_c]"; fi)"
PS1+="$(if [[ $r_containers != 0 ]]; then echo "$dashCharset<$blue_oc$r_containers$red_c>"; fi)"
PS1+="\n$bottomCharset $yellow_c\$$end_c"
}
# Set ps1_sp to the title you want for your terminal
function updateTitle {
ps1_sp=$(echo "Hello!")
echo -en "\033]0;$ps1_sp\a"
}
PROMPT_COMMAND='psOne'
| 1 | ###### Color and Behavior ###### |
| 2 | |
| 3 | case $- in |
| 4 | *i*) ;; |
| 5 | *) return;; |
| 6 | esac |
| 7 | |
| 8 | # set a fancy prompt (non-color, unless we know we "want" color) |
| 9 | case "$TERM" in |
| 10 | xterm-color) color_prompt=yes;; |
| 11 | esac |
| 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 |
| 16 | force_color_prompt=yes |
| 17 | |
| 18 | if [ -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 |
| 27 | fi |
| 28 | |
| 29 | # Set 'man' colors |
| 30 | if [ "$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 | } |
| 42 | fi |
| 43 | |
| 44 | unset color_prompt force_color_prompt |
| 45 | |
| 46 | # enable color support of ls and also add handy aliases |
| 47 | if [ -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' |
| 56 | fi |
| 57 | |
| 58 | ###### Useful ENV ###### |
| 59 | |
| 60 | # These ones are useful if you are a 42 student |
| 61 | export USER="your42login" |
| 62 | export GROUP="your42login" |
| 63 | export 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) |
| 65 | export work="path to your main work folder" |
| 66 | |
| 67 | # Here is the opportunity to add custom path folders |
| 68 | PATH=/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 | |
| 72 | alias v2_norminette="~/norm/norminette.rb" |
| 73 | |
| 74 | alias ll='ls -lh' |
| 75 | alias la='ls -lha' |
| 76 | |
| 77 | alias em='emacs -nw' |
| 78 | |
| 79 | alias dd='dd status=progress' |
| 80 | |
| 81 | alias _='sudo' |
| 82 | alias _i='sudo -i' |
| 83 | alias please='sudo' |
| 84 | alias fucking='sudo' |
| 85 | |
| 86 | alias gcl='git clone' |
| 87 | |
| 88 | ###### shopts ###### |
| 89 | |
| 90 | # enable programmable completion features |
| 91 | if ! 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 |
| 97 | fi |
| 98 | |
| 99 | # don't put duplicate lines or lines starting with space in the history. |
| 100 | # See bash(1) for more options |
| 101 | HISTCONTROL=ignoreboth |
| 102 | |
| 103 | # append to the history file, don't overwrite it |
| 104 | shopt -s histappend |
| 105 | |
| 106 | # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) |
| 107 | HISTSIZE=1000 |
| 108 | HISTFILESIZE=2000 |
| 109 | |
| 110 | # check the window size after each command and, if necessary, |
| 111 | # update the values of LINES and COLUMNS. |
| 112 | shopt -s checkwinsize |
| 113 | |
| 114 | # when using cd, corrects minor spelling errors |
| 115 | shopt -s cdspell |
| 116 | |
| 117 | # "$<directory>" expands to "$cd <directory>" |
| 118 | shopt -s autocd |
| 119 | |
| 120 | # if directory not found, treats argument as as variable (remember the work variable?) |
| 121 | shopt -s cdable_vars |
| 122 | |
| 123 | # warns if jobs are running in background before exiting |
| 124 | shopt -s checkjobs |
| 125 | |
| 126 | # do not autofill on empty line |
| 127 | shopt -s no_empty_cmd_completion |
| 128 | |
| 129 | # Block > redir if overwrite happens, now needs to be >| |
| 130 | set -C |
| 131 | |
| 132 | ###### Prompt and Term Title ###### |
| 133 | |
| 134 | # Used colors |
| 135 | red_c="\[\033[0;31m\]" |
| 136 | end_c="\[\e[0m\]" |
| 137 | white_c="\[\033[0;39m\]" |
| 138 | yellow_c="\[\033[01;33m\]" |
| 139 | blue_c="\[\033[01;96m\]" |
| 140 | blue_oc="\[\033[0;96m\]" |
| 141 | green_c="\[\033[0;32m\]" |
| 142 | |
| 143 | # Used charsets |
| 144 | bottomCharset="\342\224\224\342\224\200\342\224\200\342\225\274" |
| 145 | topCharset="\342\224\214\342\224\200" |
| 146 | crossCharset="\342\234\227" |
| 147 | dashCharset="\342\224\200" |
| 148 | |
| 149 | # This provides the current branch you are working in |
| 150 | gitStatus="" |
| 151 | function setGitStatus { |
| 152 | git_status=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) |
| 153 | } |
| 154 | |
| 155 | function 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 |
| 179 | function updateTitle { |
| 180 | ps1_sp=$(echo "Hello!") |
| 181 | echo -en "\033]0;$ps1_sp\a" |
| 182 | } |
| 183 | |
| 184 | PROMPT_COMMAND='psOne' |