2013-05-02 23:39:51 +02:00
|
|
|
#! /bin/bash
|
|
|
|
################################################################################
|
|
|
|
# .bashrc -- my personal Bourne-Again shell (aka bash) configuration
|
2013-09-16 15:13:17 +02:00
|
|
|
# see https://github.com/hcartiaux/dotfiles
|
2013-05-02 23:39:51 +02:00
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
2013-09-16 15:13:17 +02:00
|
|
|
# https://varrette.gforge.uni.lu
|
2013-05-02 23:39:51 +02:00
|
|
|
# Copyright (c) 2013 Hyacinthe Cartiaux <Hyacinthe.Cartiaux@uni.lu>
|
|
|
|
# _ _
|
|
|
|
# | |__ __ _ ___| |__ _ __ ___
|
|
|
|
# | '_ \ / _` / __| '_ \| '__/ __|
|
|
|
|
# _ | |_) | (_| \__ \ | | | | | (__
|
|
|
|
# (_) |_.__/ \__,_|___/_| |_|_| \___|
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
# This file is NOT part of GNU bash
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
################################################################################
|
|
|
|
# Resources:
|
|
|
|
# - https://github.com/Falkor/dotfiles/blob/master/bash/.bashrc
|
|
|
|
# - http://bitbucket.org/dmpayton/dotfiles/src/tip/.bashrc
|
|
|
|
# - https://github.com/rtomayko/dotfiles/blob/rtomayko/.bashrc
|
|
|
|
|
2014-02-14 03:30:34 +01:00
|
|
|
# -------------------------------------------------------------------
|
|
|
|
# USER SHELL ENVIRONMENT
|
|
|
|
# -------------------------------------------------------------------
|
2013-05-02 23:39:51 +02:00
|
|
|
|
2014-02-14 03:30:34 +01:00
|
|
|
# Source bash_environment
|
|
|
|
if [ -f ~/.bash_environment ]; then
|
|
|
|
. ~/.bash_environment
|
|
|
|
fi
|
2013-05-02 23:39:51 +02:00
|
|
|
|
2014-02-14 03:30:34 +01:00
|
|
|
# Eventually load you private settings (not exposed here)
|
|
|
|
test -f ~/.bash_private &&
|
|
|
|
. ~/.bash_private
|
2013-05-02 23:39:51 +02:00
|
|
|
|
2014-02-14 03:30:34 +01:00
|
|
|
# MOTD
|
|
|
|
test -n "$INTERACTIVE" -a -n "$LOGIN" && (
|
|
|
|
uname -npsr
|
|
|
|
uptime
|
|
|
|
)
|
2013-05-02 23:39:51 +02:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# SHELL OPTIONS
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# bring in system bashrc
|
|
|
|
test -r /etc/bashrc &&
|
|
|
|
. /etc/bashrc
|
|
|
|
|
2013-05-03 00:22:46 +02:00
|
|
|
# bring in git prompt
|
|
|
|
. ~/.git-prompt.sh
|
|
|
|
|
2013-05-02 23:39:51 +02:00
|
|
|
# shell opts. see bash(1) for details
|
|
|
|
shopt -s cdspell >/dev/null 2>&1 # correct minor errors in the spelling
|
|
|
|
# of a directory in a cd command
|
|
|
|
shopt -s extglob >/dev/null 2>&1 # extended pattern matching
|
|
|
|
shopt -s hostcomplete >/dev/null 2>&1 # perform hostname completion
|
|
|
|
# on '@'
|
2015-07-02 12:18:15 +02:00
|
|
|
shopt -s direxpand >/dev/null 2>&1 # replaces variables on filename completion
|
|
|
|
shopt -s cdable_vars >/dev/null 2>&1
|
|
|
|
|
2013-05-02 23:39:51 +02:00
|
|
|
#shopt -s no_empty_cmd_completion >/dev/null 2>&1
|
|
|
|
shopt -u mailwarn >/dev/null 2>&1
|
|
|
|
|
|
|
|
# default umask
|
|
|
|
umask 0022
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# BASH COMPLETION
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
|
2013-05-03 12:25:26 +02:00
|
|
|
test -n "$PS1" && test $bmajor -gt 1 && (
|
|
|
|
# search for a bash_completion file to source
|
|
|
|
for f in /usr/local/etc/bash_completion \
|
|
|
|
/opt/local/etc/bash_completion \
|
|
|
|
/etc/bash_completion
|
|
|
|
do
|
|
|
|
test -f $f && (
|
|
|
|
. $f
|
|
|
|
break
|
|
|
|
)
|
|
|
|
done
|
|
|
|
)
|
2013-05-02 23:39:51 +02:00
|
|
|
unset bash bmajor bminor
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# BASH HISTORY
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Increase the history size
|
|
|
|
HISTSIZE=10000
|
|
|
|
HISTFILESIZE=20000
|
|
|
|
|
|
|
|
# Add date and time to the history
|
|
|
|
HISTTIMEFORMAT="[%d/%m/%Y %H:%M:%S] "
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
2014-02-14 03:07:08 +01:00
|
|
|
# VERSION CONTROL SYSTEM - SVN and GIT
|
2013-05-02 23:39:51 +02:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
## display the current subversion revision (to be used later in the prompt)
|
|
|
|
__svn_ps1() {
|
2016-03-10 19:15:56 +01:00
|
|
|
(
|
|
|
|
local svnversion
|
|
|
|
svnversion=$(svnversion | sed -e "s/[:M]//g")
|
|
|
|
# Continue if $svnversion is numerical
|
|
|
|
let $svnversion
|
|
|
|
if [[ "$?" -eq "0" ]]
|
|
|
|
then
|
|
|
|
printf " (svn:%s)" "$(svnversion)"
|
|
|
|
fi
|
|
|
|
) 2>/dev/null
|
2013-05-02 23:39:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# render __git_ps1 even better so as to show activity in a git repository
|
|
|
|
export GIT_PS1_SHOWDIRTYSTATE=1
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# PROMPT
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Define some colors to use in the prompt
|
|
|
|
RESET_COLOR="\[\e[0m\]"
|
|
|
|
BOLD_COLOR="\[\e[1m\]"
|
|
|
|
WHITE="\[\e[0;37m\]"
|
|
|
|
RED="\[\e[0;31m\]"
|
|
|
|
GREEN="\[\e[0;32m\]"
|
|
|
|
BLUE="\[\e[34;1m\]"
|
|
|
|
YELLOW="\[\e[0;33m\]"
|
|
|
|
LIGHT_CYAN="\[\e[36;1m\]"
|
|
|
|
CYAN_UNDERLINE="\[\e[4;36m\]"
|
|
|
|
|
|
|
|
# Configure user color and prompt type depending on whoami
|
|
|
|
if [ "$LOGNAME" = "root" ]; then
|
2013-05-03 12:25:26 +02:00
|
|
|
COLOR_USER="${RED}"
|
|
|
|
P="#"
|
2013-05-02 23:39:51 +02:00
|
|
|
else
|
2013-05-03 14:33:25 +02:00
|
|
|
COLOR_USER="${WHITE}"
|
2013-05-03 14:32:15 +02:00
|
|
|
P="$"
|
2013-05-02 23:39:51 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# get virtualization information
|
|
|
|
XENTYPE=""
|
|
|
|
if [ -f "/sys/hypervisor/uuid" ]; then
|
2015-07-02 12:00:12 +02:00
|
|
|
if [ "$(</sys/hypervisor/uuid)" == "00000000-0000-0000-0000-000000000000" ]; then
|
2013-05-03 12:25:26 +02:00
|
|
|
XENTYPE=",Dom0"
|
|
|
|
else
|
|
|
|
XENTYPE=",DomU"
|
|
|
|
fi
|
2013-05-02 23:39:51 +02:00
|
|
|
fi
|
|
|
|
# Test the PS1_EXTRA variable
|
|
|
|
if [ -z "${PS1_EXTRA}" -a -f "/proc/cmdline" ]; then
|
2013-05-03 12:25:26 +02:00
|
|
|
# Here PS1_EXTRA is not set and/or empty, check additionally if it has not
|
|
|
|
# been set via kernel comment
|
|
|
|
kernel_ps1_extra="$(grep PS1_EXTRA /proc/cmdline)"
|
|
|
|
if [ -n "${kernel_ps1_extra}" ]; then
|
2015-06-22 16:48:38 +02:00
|
|
|
PS1_EXTRA=$(sed -e "s/.*PS1_EXTRA=\"\?\([^ ^\t^\"]\+\)\"\?.*/\1/g" /proc/cmdline)
|
2013-05-03 12:25:26 +02:00
|
|
|
fi
|
2013-05-02 23:39:51 +02:00
|
|
|
fi
|
|
|
|
PS1_EXTRAINFO="${BOLD_COLOR}${DOMAIN}${XENTYPE}${RESET_COLOR}"
|
|
|
|
if [ -n "${PS1_EXTRA}" ]; then
|
2013-05-03 12:25:26 +02:00
|
|
|
PS1_EXTRAINFO="${PS1_EXTRAINFO},${YELLOW}${PS1_EXTRA}${RESET_COLOR}"
|
2013-05-02 23:39:51 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-07 00:28:47 +02:00
|
|
|
# Test if we are in a screen session
|
|
|
|
if [ "${SHLVL}" -ge "2" ]; then
|
|
|
|
PS1_SCREEN='\[\033k\033\\\]'
|
|
|
|
fi
|
2013-05-02 23:39:51 +02:00
|
|
|
|
|
|
|
# This function is called from a subshell in $PS1, to provide the colorized
|
|
|
|
# exit status of the last run command.
|
|
|
|
# Exit status 130 is also considered as good as it corresponds to a CTRL-D
|
|
|
|
__colorized_exit_status() {
|
2015-06-30 16:09:57 +02:00
|
|
|
printf -- "\$(status=\$? ; if [[ \$status = 0 || \$status = 130 ]]; then \
|
2015-06-30 16:10:36 +02:00
|
|
|
echo -e '\[\e[01;32m\]'\$status; \
|
|
|
|
else \
|
2015-06-22 16:54:43 +02:00
|
|
|
echo -e '\[\e[01;31m\]'\$status; fi)"
|
2013-05-02 23:39:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
###########
|
|
|
|
# my prompt; the format is as follows:
|
|
|
|
#
|
2013-05-03 14:55:20 +02:00
|
|
|
# [hh:mm:ss]:$?:username@hostname(domain[,xentype][,extrainfo])[OAR job info] workingdir(svn/git status) $>
|
|
|
|
# `--------' ^ `------' `------' `--------'`--------------'
|
|
|
|
# cyan | root:red cyan light green
|
|
|
|
# | underline blue (absent if not relevant)
|
2013-05-02 23:39:51 +02:00
|
|
|
# exit code of
|
|
|
|
# the previous command
|
|
|
|
#
|
|
|
|
# The git/svn status part is quite interesting: if you are in a directory under
|
|
|
|
# version control, you have the following information in the prompt:
|
|
|
|
# - under GIT: current branch name, followed by a '*' if the repository has
|
|
|
|
# uncommitted changes, followed by a '+' if some elements were
|
|
|
|
# 'git add'ed but not commited.
|
|
|
|
# - under SVN: show (svn:XX[M]) where XX is the current revision number,
|
|
|
|
# followed by 'M' if the repository has uncommitted changes
|
|
|
|
#
|
|
|
|
# `domain` reflect the current domain of the machine that run the prompt
|
|
|
|
# (guessed from hostname -f)
|
|
|
|
# `xentype` is DOM0 or domU depending if the machine is a Xen dom0 or domU
|
|
|
|
# Finally, is the environment variable PS1_EXTRA is set (or passed to the
|
|
|
|
# kernel), then its content is displayed here.
|
|
|
|
#
|
|
|
|
# This prompt is perfect for terminal with black background, in my case the
|
|
|
|
# Vizor color set (see http://visor.binaryage.com/) or iTerm2
|
|
|
|
__set_my_prompt() {
|
2016-04-07 00:28:47 +02:00
|
|
|
PS1="${PS1_SCREEN}$(__colorized_exit_status) ${LIGHT_CYAN}\t${RESET_COLOR} ${COLOR_USER}\u${RESET_COLOR}@${CYAN_UNDERLINE}\h${RESET_COLOR}(${PS1_EXTRAINFO})${RED}\$(__oar_ps1_remaining_time)${RESET_COLOR}${GREEN}\$(__git_ps1 \" (%s)\")\$(__svn_ps1)${RESET_COLOR} ${BLUE}\W${RESET_COLOR} ${P} "
|
2013-05-02 23:39:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Set the color prompt by default when interactive
|
|
|
|
if [ -n "$PS1" ]; then
|
|
|
|
__set_my_prompt
|
2013-05-03 12:25:26 +02:00
|
|
|
export PS1
|
2013-05-02 23:39:51 +02:00
|
|
|
fi
|
|
|
|
|
2014-02-14 03:07:08 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# DIRCOLORS
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# Colored output from ls is nice
|
|
|
|
export CLICOLOR=1
|
|
|
|
|
|
|
|
# if the dircolors utility is available, set that up to
|
|
|
|
dircolors="$(type -P gdircolors dircolors | head -1)"
|
|
|
|
test -n "$dircolors" && (
|
|
|
|
COLORS=/etc/DIR_COLORS
|
|
|
|
test -e "/etc/DIR_COLORS.$TERM" && COLORS="/etc/DIR_COLORS.$TERM"
|
|
|
|
test -e "$HOME/.dircolors" && COLORS="$HOME/.dircolors"
|
|
|
|
test ! -e "$COLORS" && COLORS=
|
2015-07-02 12:00:12 +02:00
|
|
|
eval "$($dircolors --sh $COLORS)"
|
2014-02-14 03:07:08 +01:00
|
|
|
)
|
|
|
|
unset dircolors
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# ALIASES
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Source bash_aliases
|
|
|
|
if [ -f ~/.bash_aliases ]; then
|
|
|
|
. ~/.bash_aliases
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# OAR & G5K support
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Source bash_oar
|
|
|
|
if [ -f ~/.bash_oar ]; then
|
|
|
|
. ~/.bash_oar
|
|
|
|
fi
|
|
|
|
|