#!/bin/bash # ----------------------------------------------------------------------------- # sourced by .bash_profile at bash launch # ----------------------------------------------------------------------------- # aliases # pipefail, simple err alias df='df -h' alias du='du -h' alias less='less -r' alias devenv=\'$(cygpath -u "$VS90COMNTOOLS\..\IDE\devenv")\' alias tree='d -T' alias push=pushd alias pop=popd alias mkdirp='mkdir -p' alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias pgrep='ps -af | grep -is' alias foobar2000=\'$(cygpath -u "$PROGRAMFILES\foobar2000\foobar2000")\'\& alias swriter='/cygdrive/c/Program\ Files\ \(x86\)/OpenOffice.org\ 3/program/swriter' alias firefox=\'$(cygpath -u "$PROGRAMFILES\Mozilla Firefox\firefox")\' alias readlink='readlink -m' alias windowsize='cygpath -m' alias vlc=\'$(cygpath -u "$PROGRAMFILES\VideoLAN\VLC\vlc")\' alias unlock=\'$(cygpath -u "$PROGRAMFILES\Unlocker\Unlocker")\' alias emacs='~/.emacs.d/emacs/bin/runemacs.exe' alias h=history alias f=find alias c='cp -i' alias m='mv -i' alias r='rm -i' # for emacs export SHELL=bash case $TERM in "cygwin") alias cls='cmd /C cls' alias g='grep -E --color=always' alias l='ls --color=always --group-directories-first' ;; *) alias cls='for (( c=0; c<1000; c++ )); do echo; done' alias g='grep -E' alias l='ls --group-directories-first' ;; esac # ----------------------------------------------------------------------------- # miscellaneous settings. # append to history instead of overwriting. shopt -s histappend # specify a Python configuration file. export PYTHONSTARTUP=~/.pythonrc # save history regardless of number of terminals. export SAVEHIST=1 export HISTSIZE=10000 # ignore duplicate lines so we don't have to keep tapping up. export HISTIGNORE='&' # conver multi-line commands to single line in history. shopt -s cmdhist # extended globbing. see features at http://www.caliban.org/bash/. shopt -s extglob # return files beginning with . in path-name expansion. shopt -s dotglob bind 'set bell-style none' #set -e; #set -o pipelinefail; if [ ! -e /c ]; then ln -s /cygdrive/c /c fi if [ ! -e ~/desktop ]; then ln -s /cygdrive/c/Documents\ and\ Settings/$(whoami)/Desktop ~/desktop fi # ----------------------------------------------------------------------------- # miscellaneous helper functions. function dash() { if [ $# -gt 0 ]; then colorize $@ else colorize red fi echo -en -------------------------------------------------------------------------------- colorize } #function find_grep() #{ # find . -iname "$1" -print0|xargs -0 grep $@ #} function deref() { eval echo \$$@ } # credit: http://blog.spikesource.com/bashstringconversion.htm function toupper() { echo $1 | tr "[:lower:]" "[:upper:]" } # credit: http://blog.spikesource.com/bashstringconversion.htm function tolower() { echo $1 | tr "[:upper:]" "[:lower:]" } function pk() { procs=$(pgrep $@); if [ $? -eq 0 ]; then $(which kill) -f $(pgrep $@ | awk '{print $2}'); return; fi; return 1; }; function ld_profile() { . ~/.bash_profile; }; function read_stdin() { # only read stdin for existent pipe. if [[ -p /proc/self/fd/0 ]]; then while read line; do echo $line done fi } # ----------------------------------------------------------------------------- # colorization. # credit: http://wiki.archlinux.org/index.php/Color_Bash_Prompt colorless='\e[0m' black='\e[0;30m' red='\e[0;31m' green='\e[0;32m' yellow='\e[0;33m' blue='\e[0;34m' magenta='\e[0;35m' cyan='\e[0;36m' white='\e[0;37m' eblack='\e[1;30m' ered='\e[1;31m' egreen='\e[1;32m' eyellow='\e[1;33m' eblue='\e[1;34m' emagenta='\e[1;35m' ecyan='\e[1;36m' ewhite='\e[1;37m' bblack='\e[40m' bred='\e[41m' bgreen='\e[42m' byellow='\e[43m' bblue='\e[44m' bmagenta='\e[45m' bcyan='\e[46m' bwhite='\e[47m' case $TERM in "cygwin") # change to: # $PWD # » _ # TODO: clean this up PS1='\[\e]0;\w\a\]\n\[\e[32m\]\033]2;${wnd_title}\007\[\e[32m\]\w\n\[\e[37m\]' PS1+='`if [ $? = 0 ]; then echo -e $colorless; else echo -e $ered; fi`»\[\e[0m\] ' ;; *) PS1='\n\w \n» ' ;; esac function colorize() { if [ $# -eq 0 ]; then color=$colorless else color= for arg in $@; do color=${color}$(deref $arg) done color=$(tolower $color) fi echo -ne $color # see if we should echo stdin for the user read_stdin } function help_color_set() { function ex() { echo -e "$(deref $1) $1" } ex colorless ex black ex red ex green ex yellow ex blue ex magenta ex cyan ex white ex eblack ex ered ex egreen ex eyellow ex eblue ex emagenta ex ecyan ex ewhite ex bblack ex bred ex bgreen ex byellow ex bblue ex bmagenta ex bcyan ex bwhite # remove color colorize # remove ex() unset -f ex } # ----------------------------------------------------------------------------- # for fun alias wayfaring_pig=wandering_guinea_pig alias jeff_goldblum=house_fly # HACK: my Cygwin BASH shell uses code page 437 by default (see # http://msdn.microsoft.com/en-us/goglobal/cc305156.aspx). however, I seem to # be missing most of the good extended ASCII characters. switching to # codepage 1252 gives me most of the ones I want except "white sun with rays". # cmd /c doesn't seem to work either. so, I made a program, eecho, that just # works #code_page=$(chcp.com|sed -r 's,[^0-9]*([0-9]+),\1,') #chcp.com 1252 > /dev/null # /usr/bin/ascii doesn't seem to work. #cnt=0; while [ $cnt -lt 256 ]; do echo -en $(printf '\\x%2X' $cnt) ; let ++cnt; done; #chcp.com $code_page > /dev/null # TODO: eecho src / exe copying. function wandering_guinea_pig() { eecho '' \ ' Ú Ä ' \ ' ²²²² ' \ ' ²°°° °° Ú Ä ÄÙ ' \ ' ²°° ° ÀÄ ' \ ' °°   ² ÀÄ ' \ ' ² ²² Ä ' \ ' ² ²²² ²°° À¿ ' \ ' ²° °° ²² ' \ ' ²° ² Ú Ä Ä ÄÙ ' \ ' ²² °°°°°² ' \ ' ² °°°° ² ÚÙ ' \ ' Û²°° °°°° ²²² À Ä Ä ' \ ' ²²² °°° ²²² ³ ' \ ' ² ²²²²²²ÛÛÛ² Ä ÄÙ ' \ ' ²ÛÛÛÛÛ ' } function caterpillar() { eecho '' \ ' ' \ ' ' \ ' ' \ ' °²²²° ' \ ' °Û Û° ' \ ' À²  ²Ù ' \ ' °Û±±±Û° ' \ ' À² ²Ù ' \ ' °Û±±±Û° ' \ ' À² ²Ù ' \ ' °Û±±±Û° ' } function house_fly() { eecho '' \ ' ' \ ' ÛÛ ' \ ' ÛÛÛÛÛ ' \ ' ¿ ÛÛÛ°±°Û ' \ ' ³¿ Û°±°±°±ÛÛ' \ ' ²²²²²²°±Û°±°±°±°Û ' \ ' ²Û²²²²²²Û°±°±°±°±Û ' \ ' ÛÛÛÛ²²²²²²²²ÛÛ²²²²²ÛÛ ' \ ' ÛÛÛ ²²²²²²²²Û±±±±±±²²²Û ' \ ' ²²²²²Û±±±±°°°°±±²ÛÛ' \ ' ÛÛÛÛÛ²²²²Û°°°±±Û ' \ ' Û Û°²²ÛÛÛ° ' \ ' Û ²Û Û ' \ ' ±ÛÛ Û Û² Û ' \ ' Û° °ÛÛÛ' } function disable_beep { bind 'set bell-style none' net stop beep sc config beep start= disabled } #del /F /S /Q work > nul #rmdir /S /Q work