summaryrefslogblamecommitdiffstats
path: root/bashrc/main.sh
blob: 911f5358250cca44b2725403002f47077aab5f3b (plain) (tree)
1
2
3
4
5
6
7
8


                                                    
                         
 
                                         
                                                          
 


                                                


                   


                                          
 
                                    



                                                                                    
                                               
 
                                                                 



                                                                                              
                                                                                         

                                          
 
                                                       

                                                                                                             


                                                                                             
                                                                                                   
                          
 


























                                                            







                                                   
                                          
                                                                             





















                                  


                                 


                  


                    






                        
                   
 
                         
                   
 






                                          
                       

                              
                 
# this file is sourced by all bash shells on startup

# test for interactive shell
[[ $- != *i* ]] && return

# return if this script is executed twice
[[ -n $(declare -p _DOTFILES_DIR 2>/dev/null) ]] && return

declare -r _DOTFILES_DIR="${HOME}/.dotfiles"
declare -r _BASHRC_DIR="${_DOTFILES_DIR}/bashrc"

# start in home dir
cd "${HOME}"

# self update magic
_self_update() {
	pushd ${_DOTFILES_DIR} &>/dev/null

	git fetch origin 2>/dev/null
	if [[ -n "$(git whatchanged HEAD..origin/master)" ]]; then
		echo -ne "\033[31m*\033[0m dotfile updates found, merge now? (Y/n) "
		read _merge;
		if [[ $_merge != 'n' ]]; then
			git merge origin/master

			if [[ -e management/symlinks.md5 ]]; then
				if hash md5sum 2> /dev/null ; then
					md5sum -c management/symlinks.md5 --status 2>/dev/null
				else
					if hash md5 2> /dev/null ; then
						md5 -c management/symlinks.md5 >/dev/null
					fi
				fi

				if [[ $? -ne 0 ]]; then
					echo -e "\033[33m*\033[0m symlink mapping changed!"
					echo -e "\033[33m*\033[0m Maybe you should execute godot.sh again..."
				fi
			else
				echo -e "\033[33m*\033[0m symlink mapping checksum not found"
				echo -e "\033[33m*\033[0m Maybe you should execute godot.sh again."
			fi

			popd &>/dev/null
			exec $SHELL
		fi
	fi

	popd &>/dev/null
}

# module load magic
_load() {
	local base path
	local pedantic=0

	[[ -z $1 || -z $2 ]] && return

	base=${_BASHRC_DIR}/${1}

	if [[ $1 == "common" || $2 == "init" ]]; then
		path=${2}.sh
		pedantic=1
	else
		case $1 in
			(dist)  path=${_DISTNAME}/${2}.sh ;;
			(node)  path=${_NODENAME}/${2}.sh ;;
		esac
	fi

	if [[ -r ${base}/${path} ]]; then
	    source ${base}/${path} 2>&1 > /dev/null
	elif [[ $1 == "node" && $2 == "*" ]]; then
	    for file in ${base}/${path}; do
		if [[ -r $file ]]; then
		    source $file 2>&1 > /dev/null
		fi
	    done
	elif [[ ${pedantic} -eq 1 ]]; then
	    echo "error: cannot find necessary startup file: ${base}/${path}"
	fi
}

# update first
_self_update

# locale should be set first
_load common locale

# now set a reasonable environment
_load common env

# bash configuration
_load common shopt

# load internals
_load dist  init
_load node  init

# command aliases
_load common alias

# ssh agent forwarding
_load common ssh-agent-forwarding

# pager options
_load common pager

# browser options
_load common browser

# color code definitions
_load common color

# colored output for ls
_load common dircolors

# command prompt
_load common prompt

# screen shelltitle magic
_load common screen

# bash completion
_load common bashcomp

# load common distribution settings
_load dist common

# load distribution specific node settings
_load node ${_DISTNAME}

# initialize preexec hack last
init_preexec_hack