1
0
Fork 0
mirror of https://github.com/hcartiaux/dotfiles.git synced 2024-10-18 09:15:24 +02:00

[bash,zsh,install.sh] Code refactoring (aliases, environment variables, etc)

This commit is contained in:
Hyacinthe Cartiaux 2014-02-14 03:07:08 +01:00
parent e15b2d4826
commit ed9f33586e
6 changed files with 315 additions and 251 deletions

83
bash/bash_aliases Normal file
View file

@ -0,0 +1,83 @@
#
# ~/.bash_aliases
#
# ----------------------------------------------------------------------
# LS COLORS
# ----------------------------------------------------------------------
# we always pass these to ls(1)
LS_COMMON="-F --group-directories-first -h"
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 .*"
alias lh='la -h'
# ----------------------------------------------------------------------
# ALL ALIASES
# ----------------------------------------------------------------------
if [ "$UNAME" = Linux ]; then
alias grep='grep --color=auto'
fi
alias vi='vim'
# Mandatory aliases to confirm destructive operations
alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -i'
# Fast cd op
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
# Use most instead of less if available
[ -x /usr/bin/most ] && alias more='most' && alias less='most'
[ -x /usr/bin/htop ] && alias top='htop'
# read man in vim with colors
man() {
/usr/bin/man $* | \
col -b | \
vim -R -c 'set ft=man nomod nolist' -
}
# personnal desktop aliases
alias ssha="ssh-add"
alias cdpuppet="cd ~/Uni.lu-repos/puppet-repo"
alias cdsys="~/Uni.lu-repos/sysadmins-repo"
alias pass='eval `~/Uni.lu-repos/passwords-repo/.passrc` && pass'
# g5k aliases
alias puppetplay='bundle exec puppetplay'
alias g5kcap='bundle exec cap'
alias g5k="~/Grid5000"
alias g5kpuppet="~/Grid5000/git.grid5000.fr/puppet-repo"
g5kpass() {
curdir=`pwd`
cd /home/hcartiaux/Grid5000/gitolite.grid5000.fr/password5k
source .passrc && /usr/bin/pass $*
cd $curdir
}

92
bash/bash_environment Normal file
View file

@ -0,0 +1,92 @@
#
# ~/.bash_environments
#
# ----------------------------------------------------------------------
# LOCALES
# ----------------------------------------------------------------------
# enable en_US locale w/ UTF-8 encodings
: ${LANG:="en_US.UTF-8"}
: ${LANGUAGE:="en"}
: ${LC_CTYPE:="en_US.UTF-8"}
: ${LC_ALL:="en_US.UTF-8"}
export LANG LANGUAGE LC_CTYPE LC_ALL
# ----------------------------------------------------------------------
# SHELL TYPE
# ----------------------------------------------------------------------
# detect interactive shell
case "$-" in
*i*) INTERACTIVE=yes ;;
*) unset INTERACTIVE ;;
esac
# detect login shell
case "$0" in
-*) LOGIN=yes ;;
*) unset LOGIN ;;
esac
# ----------------------------------------------------------------------
# PATH - /usr/local
# ----------------------------------------------------------------------
# we want the various sbins on the path along with /usr/local/bin
export PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
export PATH="/usr/local/bin:$PATH"
# Programming stuff
# pkg-config settings
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
# C/C++ include
export C_INCLUDE_PATH=/usr/local/include
export CPLUS_INCLUDE_PATH=${C_INCLUDE_PATH}
export LIBRARY_PATH=/usr/lib:/usr/local/lib
export DYLD_FALLBACK_LIBRARY_PATH=${LIBRARY_PATH}
# put ~/bin on PATH if you have it
if [ -d "$HOME/bin" ]; then
export PATH="$PATH:$HOME/bin:."
fi
export MANPATH="/usr/share/man:/usr/local/share/man:$MANPATH"
# ----------------------------------------------------------------------
# EDITOR & PAGER
# ----------------------------------------------------------------------
test -n "$(command -v vim)" && EDITOR=vim || EDITOR=nano
export EDITOR
export SVN_EDITOR=$EDITOR
# Default pager ('less' is so much better than 'more'...)
if test -n "$(command -v less)" ; then
PAGER="less -FirSwX"
else
PAGER=more
fi
# ----------------------------------------------------------------------
# VCS Configuration
# ----------------------------------------------------------------------
export CVS_RSH='ssh'
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
# ----------------------------------------------------------------------
# MISC
# ----------------------------------------------------------------------
unset SSH_ASKPASS
# Easybuild BUILD PATH
export EASYBUILDBUILDPATH=/tmp/
# Tsocks config
export TSOCKS_CONF_FILE=~/.dotfiles/tsocks/tsocks.conf

50
bash/bash_oar Normal file
View file

@ -0,0 +1,50 @@
#
# ~/.bash_oar
#
# ----------------------------------------------------------------------
# OAR Batch scheduler
# ----------------------------------------------------------------------
# Resources:
# - http://wiki-oar.imag.fr/index.php/Customization_tips
# - http://wiki-oar.imag.fr/index.php/Oarsh_and_bash_completion
# oarsh completion
function _oarsh_complete_()
{
local word=${COMP_WORDS[COMP_CWORD]}
local list=`cat $OAR_NODEFILE | uniq | tr '\n' ' '`
COMPREPLY=($(compgen -W "$list" -- "${word}"))
}
complete -F _oarsh_complete_ oarsh
# Job + Remaining time
__oar_ps1_remaining_time(){
if [ -n "$OAR_JOB_WALLTIME_SECONDS" -a -n "$OAR_NODE_FILE" -a -r "$OAR_NODE_FILE" ]; then
DATE_NOW=$(date +%s)
DATE_JOB_START=$(stat -c %Y $OAR_NODE_FILE)
DATE_TMP=$OAR_JOB_WALLTIME_SECONDS
((DATE_TMP = (DATE_TMP - DATE_NOW + DATE_JOB_START) / 60))
echo -n "[OAR$OAR_JOB_ID->$DATE_TMP]"
fi
}
# OAR motd
test -n "$INTERACTIVE" && test -n "$OAR_NODE_FILE" && (
echo "[OAR] OAR_JOB_ID=$OAR_JOB_ID"
echo "[OAR] Your nodes are:"
sort $OAR_NODE_FILE | uniq -c | awk '{printf(" %s*%d\n",$2,$1)}END{printf("\n")}' | sed -e 's/,$//'
)
# ----------------------------------------------------------------------
# GRID5000 specific
# ----------------------------------------------------------------------
hostname | grep -e 'grid5000.fr$' >/dev/null 2>&1
if [ $? -eq 0 ] ; then
export OAR_JOB_KEY_FILE=~/.ssh/id_rsa
export HTTP_PROXY=http://proxy:3128
export HTTPS_PROXY=$HTTP_PROXY
fi

View file

@ -44,7 +44,7 @@
# readline config
: ${INPUTRC=~/.inputrc}
# Get ride of mail notification
# Get rid of mail notification
unset MAILCHECK
# ----------------------------------------------------------------------
@ -70,130 +70,6 @@ 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="-h"
# 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"
alias grep='grep --color=auto'
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 ..'
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}
# Easybuild BUILD PATH
EASYBUILDBUILDPATH=/tmp/
# 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
# ----------------------------------------------------------------------
@ -213,52 +89,6 @@ test -n "$PS1" && test $bmajor -gt 1 && (
)
unset bash bmajor bminor
# ----------------------------------------------------------------------
# OAR Batch scheduler
# ----------------------------------------------------------------------
# Resources:
# - http://wiki-oar.imag.fr/index.php/Customization_tips
# - http://wiki-oar.imag.fr/index.php/Oarsh_and_bash_completion
# oarsh completion
function _oarsh_complete_()
{
local word=${COMP_WORDS[COMP_CWORD]}
local list=`cat $OAR_NODEFILE | uniq | tr '\n' ' '`
COMPREPLY=($(compgen -W "$list" -- "${word}"))
}
complete -F _oarsh_complete_ oarsh
# Job + Remaining time
__oar_ps1_remaining_time(){
if [ -n "$OAR_JOB_WALLTIME_SECONDS" -a -n "$OAR_NODE_FILE" -a -r "$OAR_NODE_FILE" ]; then
DATE_NOW=$(date +%s)
DATE_JOB_START=$(stat -c %Y $OAR_NODE_FILE)
DATE_TMP=$OAR_JOB_WALLTIME_SECONDS
((DATE_TMP = (DATE_TMP - DATE_NOW + DATE_JOB_START) / 60))
echo -n "[OAR$OAR_JOB_ID->$DATE_TMP]"
fi
}
# OAR motd
test -n "$INTERACTIVE" && test -n "$OAR_NODE_FILE" && (
echo "[OAR] OAR_JOB_ID=$OAR_JOB_ID"
echo "[OAR] Your nodes are:"
sort $OAR_NODE_FILE | uniq -c | awk '{printf(" %s*%d\n",$2,$1)}END{printf("\n")}' | sed -e 's/,$//'
)
# ----------------------------------------------------------------------
# GRID5000 specific
# ----------------------------------------------------------------------
hostname | grep -e 'grid5000.fr$' >/dev/null 2>&1
if [ $? -eq 0 ] ; then
export OAR_JOB_KEY_FILE=~/.ssh/id_rsa
export HTTP_PROXY=http://proxy:3128
export HTTPS_PROXY=$HTTP_PROXY
fi
# ----------------------------------------------------------------------
# BASH HISTORY
# ----------------------------------------------------------------------
@ -271,14 +101,8 @@ HISTFILESIZE=20000
HISTTIMEFORMAT="[%d/%m/%Y %H:%M:%S] "
# ----------------------------------------------------------------------
# VERSION CONTROL SYSTEM - CVS, SVN and GIT
# VERSION CONTROL SYSTEM - 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() {
@ -290,12 +114,6 @@ __svn_ps1() {
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
@ -414,6 +232,12 @@ __set_my_prompt() {
# -------------------------------------------------------------------
# USER SHELL ENVIRONMENT
# -------------------------------------------------------------------
# Source bash_environment
if [ -f ~/.bash_environment ]; then
. ~/.bash_environment
fi
# Set the color prompt by default when interactive
if [ -n "$PS1" ]; then
__set_my_prompt
@ -426,11 +250,52 @@ test -n "$INTERACTIVE" -a -n "$LOGIN" && (
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
# ----------------------------------------------------------------------
# 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=
eval `$dircolors --sh $COLORS`
)
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
# -------------------------------------------------------------------
# Ruby & RVM
# -------------------------------------------------------------------
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
# RVM specific (see http://beginrescueend.com/)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

View file

@ -20,11 +20,14 @@ ln -sf $DOTFILES/zsh/zshrc ~/.zshrc
## bash
ln -sf $DOTFILES/bash/bashrc ~/.bashrc
ln -sf $DOTFILES/bash/inputrc ~/.inputrc
ln -sf $DOTFILES/bash/bash_profile ~/.bash_profile
ln -sf $DOTFILES/bash/profile ~/.profile
ln -sf $DOTFILES/bash/bash_logout ~/.bash_logout
ln -sf $DOTFILES/bash/bashrc ~/.bashrc
ln -sf $DOTFILES/bash/inputrc ~/.inputrc
ln -sf $DOTFILES/bash/bash_profile ~/.bash_profile
ln -sf $DOTFILES/bash/profile ~/.profile
ln -sf $DOTFILES/bash/bash_logout ~/.bash_logout
ln -sf $DOTFILES/bash/bash_environment ~/.bash_environment
ln -sf $DOTFILES/bash/bash_oar ~/.bash_oar
ln -sf $DOTFILES/bash/bash_aliases ~/.bash_aliases
if [[ ! -f ~/.git-prompt.sh ]] ; then
curl -o ~/.git-prompt.sh \

View file

@ -29,11 +29,9 @@
source /etc/profile
##################################################################
## Default locale for command line tools
## Basic variables
#
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
: ${UNAME=$(uname)}
##################################################################
## Shell and prompt configuration
@ -66,7 +64,6 @@ source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# type a directory's name to cd to it.
compctl -/ cd
##################################################################
## Auto-completion
#
@ -90,7 +87,6 @@ zstyle ':completion:*:kill:*' force-list always
# cd not select parent dir.
zstyle ':completion:*:cd:*' ignore-parents parent pwd
##################################################################
## Key bindings
## http://mundy.yazzy.org/unix/zsh.php
@ -122,7 +118,6 @@ bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix
##################################################################
## HISTORY
#
@ -132,68 +127,44 @@ SAVEHIST=10000
setopt appendhistory
setopt incappendhistory
##################################################################
## Environment variables
#
export TSOCKS_CONF_FILE=~/.dotfiles/tsocks/tsocks.conf
export SVN_EDITOR=vim
export EDITOR="vim"
# git
unset SSH_ASKPASS
if [ -f ~/.bash_environment ]; then
. ~/.bash_environment
fi
##################################################################
## Aliases
#
alias vi='/usr/bin/vim'
alias ls='/bin/ls --color=auto -F --group-directories-first -h'
alias ll='/bin/ls -l --color=auto'
alias la='ll -a'
alias lh='la -h'
eval `dircolors -b`
export GREP_COLOR=31
alias grep='grep --color=auto'
alias top='htop'
alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -i'
[ -x /usr/bin/most ] && alias more='most' && alias less='most'
# read man in vim with colors
man() {
/usr/bin/man $* | \
col -b | \
vim -R -c 'set ft=man nomod nolist' -
}
alias -s pdf="/usr/bin/xpdf "
alias killflash="ps aux | grep flash | xargs | cut -d' ' -f2 | xargs kill"
alias ssha="ssh-add"
alias cdpuppet="cd ~/Uni.lu-repos/puppet-repo"
alias cdsys="~/Uni.lu-repos/sysadmins-repo"
alias pass='eval `~/Uni.lu-repos/passwords-repo/.passrc` && pass'
# g5k alias
alias puppetplay='bundle exec puppetplay'
alias g5kcap='bundle exec cap'
alias g5k="~/Grid5000"
alias g5kpuppet="~/Grid5000/git.grid5000.fr/puppet-repo"
g5kpass() {
curdir=`pwd`
cd /home/hcartiaux/Grid5000/gitolite.grid5000.fr/password5k
source .passrc && /usr/bin/pass $*
cd $curdir
}
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
##################################################################
## RVM
## OAR & G5K Integration
#
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:/usr/lib/ruby/gems/1.9.1/bin/:$HOME/.rvm/bin # Add RVM to PATH for scripting
if [ -f ~/.bash_oar ]; then
. ~/.bash_oar
fi
##################################################################
## Colors
#
eval `dircolors --sh`
export GREP_COLOR=31
##################################################################
## Ruby & RVM
#
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Add System Ruby and RVM to PATH for scripting
export PATH=$PATH:/usr/lib/ruby/gems/2.1.0/bin/:$HOME/.rvm/bin