.bashrc
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 25 Apr 2012 19:42:00 +0300
changeset 434 c66a176a8af9
parent 309 d98ee1ad029c
child 449 63fe7a1ebae4
permissions -rw-r--r--
Switch input method.


# set -x
# set -u

# XXX
# [[ -f /etc/bashrc ]] && . /etc/bashrc

if [[ -f ~/.bash_path ]]; then
  . ~/.bash_path
fi

PS1='bash# '
# Set magenta bold font.
case "$TERM" in
  xterm*)
    PS1='\[\033[31m\033[1m\]\h\[\033[35m\]+bash# \[\033[0m\]'
    PS2='\[\033[32m\]> \[\033[0m\]'
  ;;
esac

if command -v dircolors >/dev/null 2>&1 && [[ -f ~/.dircolors ]]; then
  eval "`dircolors -b ~/.dircolors`"
fi

# Don't store duplicate adjacent items in the history.
#   ignorespace     do not save lines that start with space
#   erasedups       all previous lines matching the current line to be removed from
#                   the history list before that line is saved
HISTCONTROL=igrorespace:erasedups

# Don't store noisy/dumb items.
# TIP: MC command start with space.
HISTIGNORE=\
" cd *":\
"e *":\
"sudo mv *":"sudo rm *":"sudo cp *":"sudo mkdir *":"sudo chmod *":"sudo chown *":\
"vlc *":ls:pwd

# To these options assigned default value, as they satisfy my needs I comment them.
# HISTFILE=~/.bash_history  # where is command history stored
# HISTFILESIZE=500          # how many lines been in $HISTFILE
# HISTSIZE=500              # how many lines been stored in bash process

# Can be XXX /visible. I like bell.
# set bell-style visible

# Make Bash append rather than overwrite the history.
shopt -s histappend

shopt -s histreedit
shopt -s histverify

# Minor errors in the spelling of a directory component in a cd command will
# be corrected.
shopt -s cdspell

# Save all lines of a multiple-line command in the same history entry.
shopt -s cmdhist

# Allows files beginning with a dot ('.') to be returned in the results of path-name expansion.
shopt -s dotglob

# ksh-88 egrep-style extended pattern matching.
shopt -s extglob

# Adjust settings according to current terminal window width
# which may have changed while the last command was running
# (which is a common occurance for vim/less/etc.)
# Note this is already set in /etc/bashrc on Fedora 8 at least.
shopt -s checkwinsize

# Let me have core dumps
ulimit -c unlimited

################################################################
# shortcut aliases

alias ..="cd .."        #go to parent dir
alias ...="cd ../.."    #go to grandparent dir
alias -- -="cd -"       # go to previous dir
alias l.='ls -d .*'     #list hidden files
alias ll='ls -lhrt'     #extra info compared to "l"
alias lld='ls -lUd */'  #list directories
# I prefer EN man pages.
alias man='LANG=C man'

alias j='jobs '

# make and change to a directory
md () { mkdir -p "$1" && cd "$1"; }

# LANG=C for speed.
alias grep='GREP_COLOR="31;47" LANG=C grep -n --color=auto'
alias ls='ls --color=auto'
alias minicom='minicom -c on'

# Show 3 months. Weeks start on Monday.
alias cal='cal -3'
alias ncal='ncal -3 -M'

# alias diff='LC_ALL=C TZ=GMT0 diff -Naur' #normalise diffs for distribution
# alias sudo='sudo env PATH=$PATH' #work around sudo built --with-secure-path (ubuntu)
# alias vim='vim -X' #don't try to contact xserver (which can hang on network issues)
# alias gdb='gdb -tui' #enable the text window interface if possible

# what most people want from od (hexdump)
# alias hd='od -Ax -tx1z -v'

# --blank-lines-after-procedures --break-before-boolean-operator --braces-on-if-line --braces-on-struct-decl-line
# --comment-indentationn --space-after-cast --line-comments-indentationn --declaration-indentationn --honour-newlines
# --no-space-after-function-call-names --no-tabs --struct-brace-indentationn --start-left-side-of-comments
alias indent-bifit="indent -bap -bbo -br -brs -cdw -ce -cli0 -c0 -cs -d0 -di0 -hnl -l120 -lc90 -i4 -npcs -ppi 3 -npsl -nut -sbi4 -sc"

# canonicalize path (including resolving symlinks)
# alias realpath='readlink -f'

################################################################
# Key binding.

set -o emacs

bind '"\e/": dabbrev-expand'
bind '"\ee": edit-and-execute-command'

################################################################
# Completion.

# Use system wide completion, if available.
if [[ -f /etc/bash_completion ]]; then
  # Under Cygwin bash completition take a long time for starting.
  if [[ ! $OSTYPE = cygwin ]]; then
    . /etc/bash_completion
  fi
elif [[ -f ~/usr/etc/bash_completion ]]; then
  . ~/usr/etc/bash_completion
fi
# Load local completions.
if [[ -f ~/.bash_completion ]]; then
  . ~/.bash_completion
fi
if [[ -d ~/.bash_completion.d ]]; then
  for f in ~/.bash_completion.d/* ~/.bash_completion.d/.*; do
    [[ -f "$f" ]] && . "$f"
  done
fi