Update paths only once.
# set -x
# set -u
# XXX
# [[ -f /etc/bashrc ]] && . /etc/bashrc
# XXX for mc, cvs, svn, ...
export EDITOR=vim
# XXX vim and gnome-terminal have support for 256 colours in fedora 8 at least
# Note debian/ubuntu users should install the ncurses-term package to support this
# export TERM=xterm-256color
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 [[ -f ~/.dircolors ]]; then
# eval `dircolors -b ~/.dircolors`
# fi
# Easy cd to often used dirs.
CDPATH=.:~:~/devel:~/devel/my-devel
# 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 ..":"cd ../..":" 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"; }
# GREP_COLOR=bright yellow on black bg.
# use GREP_COLOR=7 to highlight whitespace on black terminals
# LANG=C for speed. See also: http://www.pixelbeat.org/scripts/findrepo
# alias grep='GREP_COLOR="1;33;40" LANG=C grep --color=auto'
# alias ls="BLOCK_SIZE=\'1 ls --color=auto" #enable thousands grouping and colour
# alias minicom='minicom -c on' #enable colour
# alias cal='cal -3' #show 3 months by default
# alias units='units -t' #terse mode
# alias diff='LC_ALL=C TZ=GMT0 diff -Naur' #normalise diffs for distribution
# alias lynx='lynx -force_html -width=$COLUMNS' #best settings for viewing HTML
# alias links='links -force-html' #need to enable colour in config menu manually
# alias xterm='xterm -fb "" -bg black -fg gray -fa "Sans Mono" -fs 10 +sb -sl 3000 -g 80x50+1+1'
# 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'
# Special case for CYGWIN to properly display russian letters in rxvt.
# Don't forget set in Windows SHELL=/bin/bash. If default SHELL is sh then .bashrc will not be read.
if [[ x$OSTYPE = xcygwin ]]; then
export LANG=ru_RU.CP1251
# Avoid permission problem in Cygwin.
umask 0000
fi
if [[ ! $PATH =~ $HOME/usr/bin ]]; then
export PATH=$PATH:~/usr/bin
fi
if [[ -z "$MANPATH" ]]; then
export MANPATH=~/usr/share/man:
elif [[ ! $MANPATH =~ $HOME/usr/share/man: ]]; then
export MANPATH=$MANPATH:$HOME/usr/share/man:
fi
if [[ -z "$INFOPATH" ]]; then
export INFOPATH=~/usr/share/info:
elif [[ ! $INFOPATH =~ $HOME/usr/share/info: ]]; then
export INFOPATH=$INFOPATH:$HOME/usr/share/info:
fi
export PYTHONSTARTUP=~/.pystartup
################################################################
# Key binding.
set -o emacs
bind '"\e/": dabbrev-expand'
bind '"\ee": edit-and-execute-command'
################################################################
# Completion.
# user commands see only users
complete -u su passwd write chfn groups slay w sux
# bg completes with stopped jobs
complete -A stopped -P '"%' -S '"' bg
# other job commands
complete -j -P '"%' -S '"' fg jobs disown
# readonly and unset complete with shell variables
complete -v readonly unset
# set completes with set options
complete -A setopt set
# shopt completes with shopt options
complete -A shopt shopt
# helptopics
complete -A helptopic help
# unalias completes with aliases
complete -a unalias
# bind completes with readline bindings (make this more intelligent)
complete -A binding bind
# type and which complete on commands
complete -c command type which
# builtin completes on builtins
complete -b builtin
_hgsyncew() {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "--push" -- $cur) )
return 0
}
complete -F _hgsyncew -o nospace hgsyncew
_pathsearch() {
local prev cur=${COMP_WORDS[COMP_CWORD]}
[[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $prev = -d ]]; then
COMPREPLY=()
return 0
fi
case "$cur" in
-*) COMPREPLY=( $(compgen -W "-d --delimiter= -h --help" -- $cur ) ) ;;
*) COMPREPLY=() ;;
esac
return 0
}
complete -F _pathsearch -o nospace pathsearch
_mycd() {
local cur
cur=${COMP_WORDS[COMP_CWORD]}
if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then
COMPREPLY=( $(compgen -d -- "$cur") )
return 0
fi
local i j k
for i in ${CDPATH//:/$'\n'}; do
k="${#COMPREPLY[@]}"
for j in $( compgen -d -- $i/$cur ); do
COMPREPLY[k++]=${j#$i/}
done
done
return 0
}
complete -F _mycd -o nospace cd
_man() {
local p
local cur=${COMP_WORDS[COMP_CWORD]}
if [[ $cur = /* || $cur = ./* ]]; then
COMPREPLY=( $(compgen -f -- $cur) )
fi
local IFS=':
'
for p in /usr/share/man $MANPATH; do
[[ -n $p ]] || continue
p=( $p/man*/* )
p=( ${p[@]##*/} )
p=( ${p[@]%.gz} )
p=( ${p[@]%.*} )
p=( $(compgen -W '${p[@]}' -- $cur ) )
COMPREPLY=( ${COMPREPLY[@]} ${p[@]} )
done
}
complete -F _man man
_make() {
local i mk
local dir=.
local cur=${COMP_WORDS[COMP_CWORD]}
if [[ $cur = -* ]]; then
COMPREPLY=( $(compgen -W "-C -f" -- "$cur") )
return 0
fi
[[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
case ${COMP_WORDS[i]} in
-f) mk=${COMP_WORDS[i+1]} ;;
-C) dir=${COMP_WORDS[i+1]} ;;
esac
done
if [[ $prev = -C ]]; then
COMPREPLY=( $(compgen -d -- "$cur") )
return 0
fi
if [[ $prev = -f ]]; then
COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") )
return 0
fi
mk=$dir/$mk
[[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile)
[[ -f $mk ]] || return 1
COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) )
return 0
}
complete -F _make make gmake pmake
_cygcheck() {
local opt
local cur=${COMP_WORDS[COMP_CWORD]}
case $COMP_CWORD in
1)
case $cur in
-*)
COMPREPLY=( $(compgen -W "-v --verbose -h --help -V --version -c --check-setup -s --sysinfo
-k --keycheck -f --find-package -l --list-package -p --package-query" -- "$cur") )
return 0 ;;
*)
COMPREPLY=( $(compgen -c -- "$cur") )
return 0 ;;
esac
;;
2)
opt=${COMP_WORDS[1]}
case $opt in
-c|--check-setup|-l|--list-package)
pkgs=( /etc/setup/*.lst.gz )
pkgs=( ${pkgs[@]##*/} )
pkgs=( ${pkgs[@]%.lst.gz} )
COMPREPLY=( $(compgen -W '${pkgs[@]}' -- $cur ) )
return 0;;
esac
return 0;;
esac
return 0
}
complete -F _cygcheck cygcheck.exe cygcheck
# Use bash-completion, if available.
if [ -f /etc/bash_completion ]; then
# Under Cygwin bash completition start a long time.
if [ ! "$OSTYPE" = cygwin ]; then
. /etc/bash_completion
else
# But load local completion anyway.
if [ -f ~/.bash_completion ]; then
. ~/.bash_completion
fi
fi
fi
if [ -f $HOME/usr/etc/bash_completion ]; then
. $HOME/usr/etc/bash_completion
fi