# -*- shell-script -*- # # Fichier d'initialisation de bash commun # Pour les shells non interactif (sous emacs, avec rcp, ...) [ -z "$PS1" -o "$TERM" = dumb ] && return # +-------+ # | Hacks | # +-------+ COLUMNS=$(tput cols) shopt -s checkwinsize # +-------------------------+ # | Customizations diverses | # +-------------------------+ # On ne sauve pas les lignes dupliqués dans l'historique export HISTCONTROL=ignoredups # Convenience [[ -x /usr/bin/lesspipe ]] && eval "$(lesspipe)" if [[ $(uname) == Linux ]]; then eval "$(dircolors)" # alias ls='ls --color -FC' fi # Complétion [ -f /etc/bash_completion ] && . /etc/bash_completion # +----------------------+ # | Génération du prompt | # +----------------------+ # Génération de la ligne de "-" function gen_minus_line { local i MINUS_LINE="" SAVE_COLUMNS=$COLUMNS for ((i = COLUMNS-24; i>0; i--)); do MINUS_LINE=$MINUS_CHAR$MINUS_LINE done } # Génération du prompt après chaque commande function prompt_command { (( SAVE_COLUMNS == COLUMNS )) || gen_minus_line local pwd=${PWD/#$HOME/'~'} if (( ${#pwd} + 27 > COLUMNS )); then if (( COLUMNS >= 33 )); then PS1=$TITLE'\[\e[1;32m\]'$MINUS_CHAR'( \[\e[1;35m\]\D{%H:%M:%S}\[\e[1;32m\] )'$MINUS_CHAR'< \[\e[1;33m\]..'${pwd:${#pwd}+29-COLUMNS}'\[\e[1;32m\] >${MINUS_LINE:0:4-${#?}}[ \[\e[1;$((31+($?==0)*6))m\]$?\[\e[1;32m\] ]'$MINUS_CHAR'\n\[\e[1;31m\]\u\[\e[1;32m\]@\[\e[1;34m\]\h\[\e[1;32m\]% \[\e[0m\]' else PS1=$TITLE'\[\e[1;32m\]'$MINUS_CHAR'( \[\e[1;35m\]\D{%H:%M:%S}\[\e[1;32m\] )'$MINUS_CHAR'< \[\e[1;33m\]'$pwd'\[\e[1;32m\] >'$MINUS_CHAR'[ \[\e[1;$((31+($?==0)*6))m\]$?\[\e[1;32m\] ]'$MINUS_CHAR'\n\[\e[1;31m\]\u\[\e[1;32m\]@\[\e[1;34m\]\h\[\e[1;32m\]% \[\e[0m\]' fi else PS1=$TITLE'\[\e[1;32m\]'$MINUS_CHAR'( \[\e[1;35m\]\D{%H:%M:%S}\[\e[1;32m\] )'$MINUS_CHAR'< \[\e[1;33m\]'$pwd'\[\e[1;32m\] >${MINUS_LINE:'${#pwd}'+${#?}}'$MINUS_CHAR'[ \[\e[1;$((31+($?==0)*6))m\]$?\[\e[1;32m\] ]'$MINUS_CHAR'\n\[\e[1;31m\]\u\[\e[1;32m\]@\[\e[0m\e[1;34m\]\h\[\e[0m\]\[\e[1;32m\]% \[\e[0m\]' fi } # # On change le titre dynamiquement si on est sous X if [[ $TERM = "rxvt-unicode" ]]; then TITLE='\[\e];\u@\h:\w\a\]' else TITLE='' fi # On regénére le prompt après chaque commande PROMPT_COMMAND=prompt_command # +----------------+ # | Aliases commun | # +----------------+ alias grep='grep --color=auto' alias l='ls -s' alias du='du -h' alias df='df -h' # +----------------------+ # | Customization locale | # +----------------------+ [[ -f ~/.bashrc.local ]] && . ~/.bashrc.local # +-------------------+ # | Messages au début | # +-------------------+ if [[ $(uname) == Linux && ( $(locale charmap) == UTF-8 && $TERM != screen ) ]]; then MINUS_CHAR=─ gen_minus_line date=$(/bin/date +"%R, %A %d %B %Y") redate=${date//é/e} redate=${redate//û/u} echo -e "\e[1;32m┬─${redate//?/─}─┬${MINUS_LINE:${#date}-20}\n\ │ \e[1;37m$date\e[1;32m │\n\ └─${redate//?/─}─┘\e[0m\n" unset date else MINUS_CHAR=- gen_minus_line fi # Jolis alias alias ls='ls --color=auto' alias ll='ls -alFh' alias la='ls -A' alias l='ls -CF' alias cd..='cd ..' alias rm='rm -i' alias mv='mv -i' alias cp='cp -i' alias chrome='chromium-browser &' alias grep='grep --color=auto' # Gedit fait de la merde avec l'encodage, du coup je force l'utf-8 alias gedit="gedit --encoding=utf-8" alias gfor='gfortran' alias news='emacs23 -l /usr/scripts/news/moderation.el -e gnus'