Skip to content

Instantly share code, notes, and snippets.

@naufraghi
Created March 28, 2014 16:22
Show Gist options
  • Save naufraghi/9836794 to your computer and use it in GitHub Desktop.
Save naufraghi/9836794 to your computer and use it in GitHub Desktop.
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# http://www.bradshawenterprises.com/blog/2008/5-ways-to-make-using-bash-more-productive/
# erase old dups and skip commands starting with spaces
export HISTCONTROL="ignorespace:ignoredups"
export HISTSIZE=10000
shopt -s histappend # avoid multiple shells history overwriting
shopt -s cmdhist # Save all lines of a multiline command in one history entry
stty -ixon # let ctrl-s be reverse search instead off XOFF
# These set up/down to do the history searching
bind '"\e[A"':history-search-backward
bind '"\e[B"':history-search-forward
# Tell nose to run doctests
export NOSE_WITH_DOCTEST=true
# Smart python
export PYTHONSTARTUP="$HOME/.pythonstart"
# GoLang
export GOPATH="$HOME/opt/golang"
# unison
export UNISONLOCALHOSTNAME=$(hostname | tr "." " " | awk '{print $1}')
# Use vim as default editor
export EDITOR=vim
# Show colors in less
export LESS=-R
# Enable gnupg.vim support
export GPG_TTY=$(tty)
# Force italian properties but leave eng language for messages
# sudo apt-get install language-pack-it language-pack-gnome-it
export LANG="it_IT.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Use ** recursive star
if (( $BASH_VERSINFO >= 4 )); then
shopt -s globstar
fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|rxvt) 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
if [ -f "/usr/share/doc/git/contrib/completion/git-prompt.sh" ]; then
. /usr/share/doc/git/contrib/completion/git-prompt.sh
fi
RED_="\e[0;31m"
GREEN_="\e[01;32m"
CYAN_="\e[01;34m"
NONE_="\e[00m"
RED="\[$RED_\]"
GREEN="\[$GREEN_\]"
CYAN="\[$CYAN_\]"
NONE="\[$NONE_\]"
if [ "$color_prompt" == "yes" ]; then
PS1="${CYAN}[\$(date +%H:%M)]${NONE} ${debian_chroot:+($debian_chroot)}${GREEN}\u@\h${NONE}:${CYAN}\w${NONE}\$(__git_ps1)\$ "
PROMPT_COMMAND='RET=$?; if [[ $RET -ne 0 ]]; then echo -ne "${RED_}Error $RET${NONE_}\n"; fi'
else
PS1='[\$(date +%H:%M)] ${debian_chroot:+($debian_chroot)}\u@\h:\w\$(__git_ps1)\$ '
PROMPT_COMMAND='RET=$?; if [[ $RET -ne 0 ]]; then echo -n "Error $RET\n"; fi'
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
#PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
PROMPT_COMMAND="$PROMPT_COMMAND; history -a; history -r" # saves after every executed command and reload
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto --group-directories-first --classify'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
if [ "`uname`" = "Darwin" ]; then
alias ls='ls -G'
alias git='/usr/local/bin/git'
readlink() { greadlink $@; }
alias realpath="python -c \"import os, sys; sys.stdout.write(os.path.realpath(sys.argv[1])+'\n')\""
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
fi
# some more ls aliases
alias ll='ls -lhF'
alias la='ls -AF'
#alias l='ls -CF'
alias lsnew=" ls -al --time-style=+%D | grep `date +%D` "
alias rxvt="rxvt --background grey10 --foreground white --saveLines 9000 -sr"
alias urxvt="urxvt --background grey10 --foreground white -sr"
alias duf='du -kd 1 | sort -nr | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done'
alias mvim='open -a MacVim'
alias gvim='gvim --remote-silent'
alias seasonal="cd ~/COMMON/timeseries/seasonal; source ~/COMMON/timeseries/64bit/bin/activate"
alias sandbox="cd ~/COMMON/timeseries/seasonal/sandbox; source ~/COMMON/timeseries/64bit/bin/activate"
alias appcfg="~/local/bin/python2.5 ~/Scaricati/google_appengine/appcfg.py"
alias patch="patch --merge"
alias ack="ag -C3 -S"
alias sarchiapone="rdesktop -u 'Pc cad p55' -p 'develer' -g '1024x768' -r clipboard:PRIMARYCLIPBOARD -k it sarchiapone"
alias ag="ag -C3 -S"
vundle-install() {
mkdir ~/.vim/bundle/
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
}
cpd() {
mv $2 $2.old
cp $1 $2
touch -r $2.old $2
rm $2.old
}
histpack() {
cat ~/.bash_history > ~/.bash_history.old && cat ~/.bash_history.old | python ~/bin/histpack.py > ~/.bash_history
}
# http://www.linuxjournal.com/content/floating-point-math-bash
#####################################################################
# Default scale used by float functions.
float_scale=3
#####################################################################
# Evaluate a floating point number expression.
float_eval()
{
local stat=0
local result=0.0
if [[ $# -gt 0 ]]; then
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
stat=$?
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
fi
echo $result
return $stat
}
#####################################################################
# Evaluate a floating point number conditional expression.
float_cond()
{
local cond=0
if [[ $# -gt 0 ]]; then
cond=$(echo "$*" | bc -q 2>/dev/null)
if [[ -z "$cond" ]]; then cond=0; fi
if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi
fi
local stat=$((cond == 0))
return $stat
}
#bernie
please() { nice ionice -c2 -n6 $@; }
idle() { nice -n 19 ionice -c 3 $@; }
reidle() { renice -n 19 -p $@; ionice -c 3 -p $@; }
say() {
local tempfile=$(tempfile --suffix .wav)
pico2wave -l 'it-IT' -w $tempfile "$@"
aplay -q $tempfile
rm -f $tempfile
}
svn-cdi() {
svn di . $(svn st | grep ^X | awk '{print $2}') | colordiff
}
mv2localhome() {
mv /home/$USER/$1 /localhome/$USER/
ln -s /localhome/$USER/$1 /home/$USER/
}
svn-sync-clean() {
pwd
echo "svn revert -R ."
svn revert -R .
echo "svn-clean"
svn-clean
for x in $(svn st | grep ^X | awk '{print $2}'); do
pushd $x
echo "svn revert -R ."
svn revert -R .
echo "svn-clean"
svn-clean
popd
done
svn up
}
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
if [ -f /usr/local/etc/bash_completion ]; then
. /usr/local/etc/bash_completion
fi
_git-svn-action-all() {
action=$1
path=$2
echo "Working in path" $(readlink -f -n $path)
for dir in $(find $path -name ".git" -exec dirname {} \; | sort); do
cd $dir
echo "--------------------------"
echo $dir
echo "--------------------------"
need_stash=$(git st --por | cut -c 1-2 | grep M | cat)
if [ "$need_stash" ]; then
git stash
fi
git svn $action
if [ "$need_stash" ]; then
git stash pop
fi
cd - > /dev/null
done
}
git-svn-rebase-all() {
path=${1:-.}
_git-svn-action-all rebase $path
}
_git-svn-action() {
action=$1
need_stash=$(git st --por | cut -c 1-2 | grep M | cat)
if [ "$need_stash" ]; then
git stash
fi
git svn $action
if [ "$need_stash" ]; then
git stash pop
fi
}
git-svn-dcommit() {
_git-svn-action dcommit
}
git-svn-dcommit-all() {
path=${1:-.}
_git-svn-action-all dcommit $path
}
git-svn-outgoing() {
_git-svn-action "dcommit -n" | grep diff-tree | while read line; do git show $(echo $line | cut -d' ' -f 3); done
}
git-svn-outgoing-all() {
path=${1:-.}
_git-svn-action-all "dcommit -n" $path | grep diff-tree | while read line; do git show $(echo $line | cut -d' ' -f 3); done
}
git-svn-log() {
DASH="------------------------------------------------------------------------"
git log --format="$DASH%n %b | %an | %ad %n%s" $@ | perl -p -e 's/ git-svn-id:.*@([0-9]*).*\n/r\1/'
echo $DASH
}
git-gc-all() {
path=${1:-.}
find $path -type d -name .git | while read dir; do pushd "$dir"; git gc --prune; popd; done
}
worktime() {
today=$(last | grep boot | head -1 | sed "s/.*\([A-Z][a-z][a-z] [0-9][0-9]\).*/\1/g")
start_date=$(last | grep boot | grep "$today" | tail -1)
start_time=$(echo $start_date | awk '{print $8}')
end_date=$(last | grep boot | grep "$today" | head -1)
end_time=$(echo $end_date | awk '{print $10}')
workhours=$(date --utc --date "1970-01-01 $(($(date --utc --date "$end_time" +%s) - $(date --utc --date "$start_time" +%s))) sec" "+%T")
echo $start_date
echo $end_date
echo $today $workhours
}
worklog() {
mkdir -p $HOME/worklog
filename=$HOME/worklog/$(date +"%F").worklog
echo "$(date +'%R') $@" >> $filename
echo $filename
cat $filename
}
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment