summaryrefslogtreecommitdiffstats
path: root/bashrc/main.sh
blob: baf265389ecc19e230dfbe171b75a35a12cb168a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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"

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

	if [[ -n "$(git fetch 2>&1)" && $? -eq 0 ]]; then
		echo -ne "\033[31m*\033[0m dotfile updates found, merge now? "

		if read; then
			git merge origin/master
			
			if [[ -e management/symlinks.md5 ]]; then
				md5sum -c management/symlinks.md5 --status 2>/dev/null
				
				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"
			fi
			md5sum symlink-mapping > management/symlinks.md5

			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}
	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

# 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

# bash completion
_load common bashcomp

# load common distribution settings
_load dist common

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