# .bashrc

if [ "$PS1" ] && (which bk >/dev/null 2>/dev/null) ; then
        
        export BK_RSH=ssh
        export BK_LICENSE=ACCEPTED
        
        # edit all changed files 
        function vim-bk-changed() { 
        	vim `bk sfiles -c | sed -e 's/SCCS\/s\.//'` 
        }
        
        # shows colourized bk diffs in vim
        function bkdiff() {
        	if [ -z "$1" ] ; then echo "bkdiff [-r|<file>]" >&2 ; return 1 ; fi
        	if [ "$1" = "-r" ] ; then
        		bk -r diffs -u
        	else
        		bk diffs -u "$1"
        	fi | vim -R -c "set syntax=diff" -
        }
        
        # ---------------------------------------------------------------------------
        # custom tab completion ....
        # 
        # cheatsheet...
        #	COMP_LINE
        #	COMP_POINT
        #	COMP_WORDS
        #	COMP_CWORD
        #	$1 - command completed
        #	$2 - word being completed
        #	$3 - word before the one being completed
        #	COMPREPLY - result
        
        # if bk is installed then build completion for bk commands
        if ( bk version > /dev/null 2>&1 ) ; then
          BKCMDS="`bk help topics |/bin/grep '^  bk' |cut -d ' ' -f 4 |xargs echo`"
          complete -A file -W "$BKCMDS" bk
        fi
        
fi

