diff --git a/bash/bash_logout b/bash/bash_logout new file mode 100755 index 0000000..0e4e4f1 --- /dev/null +++ b/bash/bash_logout @@ -0,0 +1,3 @@ +# +# ~/.bash_logout +# diff --git a/bash/bash_profile b/bash/bash_profile new file mode 100755 index 0000000..5545f00 --- /dev/null +++ b/bash/bash_profile @@ -0,0 +1,5 @@ +# +# ~/.bash_profile +# + +[[ -f ~/.bashrc ]] && . ~/.bashrc diff --git a/bash/bashrc b/bash/bashrc new file mode 100755 index 0000000..e62a483 --- /dev/null +++ b/bash/bashrc @@ -0,0 +1,453 @@ +#! /bin/bash +################################################################################ +# .bashrc -- my personal Bourne-Again shell (aka bash) configuration +# see http://github.com/hcartiaux/dotfiles +# +# Copyright (c) 2010 Sebastien Varrette +# http://varrette.gforge.uni.lu +# Copyright (c) 2013 Hyacinthe Cartiaux +# _ _ +# | |__ __ _ ___| |__ _ __ ___ +# | '_ \ / _` / __| '_ \| '__/ __| +# _ | |_) | (_| \__ \ | | | | | (__ +# (_) |_.__/ \__,_|___/_| |_|_| \___| +# +################################################################################ +# 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 . +################################################################################ +# 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 + +# Basic variables +: ${HOME=~} +: ${LOGNAME=$(id -un)} +: ${UNAME=$(uname)} + +# complete hostnames from this file +: ${HOSTFILE=~/.ssh/known_hosts} + +# readline config +: ${INPUTRC=~/.inputrc} + +# Get ride of mail notification +unset MAILCHECK + +# ---------------------------------------------------------------------- +# SHELL OPTIONS +# ---------------------------------------------------------------------- + +# bring in system bashrc +test -r /etc/bashrc && +. /etc/bashrc + +# 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 '@' +#shopt -s no_empty_cmd_completion >/dev/null 2>&1 +shopt -u mailwarn >/dev/null 2>&1 + +# default umask +umask 0022 + +# ---------------------------------------------------------------------- +# LS AND DIRCOLORS +# ---------------------------------------------------------------------- +# Colored output from ls is nice +export CLICOLOR=1 + +# we always pass these to ls(1) +LS_COMMON="-hB" + +# 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= + eval `$dircolors --sh $COLORS` +} +unset dircolors + +if [ "$UNAME" = Darwin ]; then + # check if you're using gnu core-utils then use --color + test "`which ls`" = "/opt/local/bin/ls" && { + LS_COMMON="$LS_COMMON --color" + } || { + LS_COMMON="$LS_COMMON -G" + } +elif [ "$UNAME" = Linux ]; then + LS_COMMON="$LS_COMMON --color" +fi + +# setup the main ls alias if we've established common args +test -n "$LS_COMMON" && +alias ls="command ls $LS_COMMON" + +# these use the ls aliases above +alias ll="ls -l" +alias la="ll -a" +alias l.="ls -d .*" + +# ---------------------------------------------------------------------- +# ALIASES +# ---------------------------------------------------------------------- +# Mandatory aliases to confirm destructive operations +alias cp='cp -iv' +alias mv='mv -iv' +alias rm='rm -i' + +alias ..='cd ..' +# Color aliases +alias grep='grep --color=auto' +#alias fgrep='fgrep --color=auto' +#alias egrep='egrep --color=auto' + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +# ---------------------------------------------------------------------- +# ENVIRONMENT CONFIGURATION +# ---------------------------------------------------------------------- +# detect interactive shell +case "$-" in + *i*) INTERACTIVE=yes ;; + *) unset INTERACTIVE ;; +esac + +# detect login shell +case "$0" in + -*) LOGIN=yes ;; + *) unset LOGIN ;; +esac + +# enable en_US locale w/ ISO-8859-15 encodings if not already configured +# : ${LANG:="en_US.ISO-8859-15"} +# : ${LANGUAGE:="en"} +# : ${LC_CTYPE:="en_US.ISO-8859-15"} +# : ${LC_ALL:="en_US.ISO-8859-15"} +# export LANG LANGUAGE LC_CTYPE LC_ALL + +# ---------------------------------------------------------------------- +# PATH +# ---------------------------------------------------------------------- +# we want the various sbins on the path along with /usr/local/bin +PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin" +PATH="/usr/local/bin:$PATH" + +# put ~/bin on PATH if you have it +if [ -d "$HOME/bin" ]; then + PATH="$PATH:$HOME/bin:." +fi +MANPATH="/usr/share/man:/usr/local/share/man:$MANPATH" + +# === Programming stuff === +# pkg-config settings +PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH + +# C/C++ include +C_INCLUDE_PATH=/usr/local/include +CPLUS_INCLUDE_PATH=${C_INCLUDE_PATH} +LIBRARY_PATH=/usr/lib:/usr/local/lib +DYLD_FALLBACK_LIBRARY_PATH=${LIBRARY_PATH} + +# RVM specific (see http://beginrescueend.com/) +[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function + +# ---------------------------------------------------------------------- +# PAGER / EDITOR +# ---------------------------------------------------------------------- + +# Default editor +test -n "$(command -v vim)" && EDITOR=vim || EDITOR=nano +export EDITOR + +# Default pager ('less' is so much better than 'more'...) +if test -n "$(command -v less)" ; then + PAGER="less -FirSwX" + MANPAGER="less -FiRswX" +else + PAGER=more + MANPAGER="$PAGER" +fi +export PAGER MANPAGER + +# ---------------------------------------------------------------------- +# BASH COMPLETION +# ---------------------------------------------------------------------- + +bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} +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 +} +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] " + +# ---------------------------------------------------------------------- +# VERSION CONTROL SYSTEM - CVS, SVN and GIT +# ---------------------------------------------------------------------- +# === CVS === +export CVS_RSH='ssh' + +# === SVN === +export SVN_EDITOR=$EDITOR + + +## display the current subversion revision (to be used later in the prompt) +__svn_ps1() { + local svnversion=`svnversion | sed -e "s/[:M]//g"` + # Continue if $svnversion is numerical + if let $svnversion 2>/dev/null + then + printf " (svn:%s)" `svnversion` + fi +} + +# === GIT === +export GIT_AUTHOR='Hyacinthe Cartiaux' +export GIT_AUTHOR_EMAIL='Hyacinthe.Cartiaux@uni.lu' +export GIT_COMMITER=$GIT_AUTHOR +export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL + +# 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\]" +# B&W +WHITE="\[\e[0;37m\]" +GRAY="\[\e[1;30m\]" +BLACK="\[\e[0;30m\]" +# RGB +RED="\[\e[0;31m\]" +GREEN="\[\e[0;32m\]" +BLUE="\[\e[34;1m\]" +# other +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 + COLOR_USER="${RED}" + P="#" +else + COLOR_USER="${WHITE}" + P="" +fi + +# Configure a set of useful variables for the prompt +DOMAIN=`hostname -f | cut -d '.' -f 2` +# get virtualization information +XENTYPE="" +if [ -f "/sys/hypervisor/uuid" ]; then + if [ $( +# `--------' ^ `------' `------' `--------'`--------------' +# cyan | root:red cyan light green +# | underline blue (absent if not relevant) +# 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() { + PS1="$(__colorized_exit_status) ${LIGHT_CYAN}[\t]${RESET_COLOR} ${COLOR_USER}\u${RESET_COLOR}@${CYAN_UNDERLINE}\h${RESET_COLOR}(${PS1_EXTRAINFO}) ${BLUE}\W${RESET_COLOR}${GREEN}\$(__git_ps1 \" (%s)\")\$(__svn_ps1)${RESET_COLOR}${P}> " +} + + +# -------------------------------------------------------------------- +# PATH MANIPULATION FUNCTIONS (thanks rtomayko ;) ) +# -------------------------------------------------------------------- +###### +# List path entries of PATH or environment variable . +# Usage: pls [] +### +pls () { eval echo \$${1:-PATH} |tr : '\n'; } + +###### +# Shift entries off the front of PATH or environment var . +# with the option. +# Usage: pshift [-n ] [] +# Useful: pshift $(pwd) +#### +pshift () { + local n=1 + [ "$1" = "-n" ] && { n=$(( $2 + 1 )); shift 2; } + eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'" +} + +###### +# Pop entries off the end of PATH or environment variable . +# Usage: ppop [-n ] [] +#### +ppop () { + local n=1 i=0 + [ "$1" = "-n" ] && { n=$2; shift 2; } + while [ $i -lt $n ] + do eval "${1:-PATH}='\${${1:-PATH}%:*}'" + i=$(( i + 1 )) + done +} + +###### +# Remove from PATH or environment variable . +# Usage: prm [] +#### +prm () { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; } + +###### +# Shift onto the beginning of PATH or environment variable . +# Usage: punshift [] +##### +punshift () { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; } + +####### +# push +# Usage: ppush [] +#### +ppush () { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; } + +###### +# Remove duplicate entries from a PATH style value while retaining +# the original order. Use PATH if no is given. +# Usage: puniq [] +# +# Example: +# $ puniq /usr/bin:/usr/local/bin:/usr/bin +# /usr/bin:/usr/local/bin +### +puniq () { + echo "$1" |tr : '\n' |nl |sort -u -k 2,2 |sort -n | + cut -f 2- |tr '\n' : |sed -e 's/:$//' -e 's/^://' +} + +# ------------------------------------------------------------------- +# USER SHELL ENVIRONMENT +# ------------------------------------------------------------------- +# condense PATH entries +PATH=$(puniq $PATH) +MANPATH=$(puniq $MANPATH) + +# Set the color prompt by default when interactive +if [ -n "$PS1" ]; then + __set_my_prompt +fi +export PS1 + +# MOTD +test -n "$INTERACTIVE" -a -n "$LOGIN" && { + uname -npsr + uptime +} + +export PKG_CONFIG_PATH +export C_INCLUDE_PATH CPLUS_INCLUDE_PATH LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH + +# Eventually load you private settings (not exposed here) +test -f ~/.bash_private && +. ~/.bash_private + +PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting diff --git a/bash/inputrc b/bash/inputrc new file mode 100755 index 0000000..71279f5 --- /dev/null +++ b/bash/inputrc @@ -0,0 +1,46 @@ +################################################################################ +# .inputrc -- my personal Readline configuration +# see http://github.com/hcartiaux/dotfiles +# +# Copyright (c) 2010 Sebastien Varrette +# Copyright (c) 2013 Hyacinthe Cartiaux +# _ _ +# (_)_ __ _ __ _ _| |_ _ __ ___ +# | | '_ \| '_ \| | | | __| '__/ __| +# _| | | | | |_) | |_| | |_| | | (__ +# (_)_|_| |_| .__/ \__,_|\__|_| \___| +# |_| +################################################################################ +# Resource +# - https://github.com/Falkor/dotfiles/blob/master/bash/.bashrc +# - https://github.com/rtomayko/dotfiles/blob/rtomayko/.inputrc + +# do not bell on tab-completion +set bell-style bell + +set expand-tilde off +set input-meta off +set convert-meta on +set output-meta off +set horizontal-scroll-mode off +set history-preserve-point on +set mark-directories on +set mark-symlinked-directories on +set match-hidden-files off + +# completion settings +set page-completions off +set completion-query-items 2000 +set completion-ignore-case off +set show-all-if-ambiguous on +set show-all-if-unmodified on +set completion-prefix-display-length 10 +set print-completions-horizontally off + +# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving +"\e[1;5C": forward-word +"\e[1;5D": backward-word +"\e[5C": forward-word +"\e[5D": backward-word +"\e\e[C": forward-word +"\e\e[D": backward-word diff --git a/bash/profile b/bash/profile new file mode 100755 index 0000000..9d4184f --- /dev/null +++ b/bash/profile @@ -0,0 +1,5 @@ +# +# ~/.profile +# + +[[ -f ~/.bashrc ]] && . ~/.bashrc