-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.zsh
152 lines (113 loc) · 3.79 KB
/
config.zsh
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
function SETUP__CONFIG() {
STATUS 'starting application configuration'
GENERATE_INITIAL_LOCAL_CONFIG
SCWRYPTS system/config/update || return 1
CONFIG__ZSH || return 2
CONFIG__VIM || return 3
CONFIG__SYSTEM || return 4
SCWRYPTS generate i3 config || return 5
SUCCESS 'finished application configuration'
}
#####################################################################
GENERATE_INITIAL_LOCAL_CONFIG() {
local HOSTNAME="$(hostnamectl --static)"
[ ${HOSTNAME} ] || return 0
mkdir -p "${DOTWRYN_PATH}/bin/${HOSTNAME}"
local ENV_DIR="${DOTWRYN_PATH}/config/scwrypts/environments"
local GROUP
for GROUP in $(find "${ENV_DIR}" -type f -name \*env.yaml | sed -n 's|.*/local\.\([^.]*\)\.env\.yaml|\1|p')
do
[ -f "${ENV_DIR}/local.${HOSTNAME}.${GROUP}.env.yaml" ] \
|| cp "${ENV_DIR}/local.altaria.${GROUP}.env.yaml" "${ENV_DIR}/local.${HOSTNAME}.${GROUP}.env.yaml"
done
}
#####################################################################
CONFIG__ZSH() {
#CONFIG__ENV zsh || return 1
#CONFIG__RC zsh || return 2
CONFIG__SET_DEFAULT_SHELL || return 3
}
CONFIG__SET_DEFAULT_SHELL() {
local DEFAULT_SHELL=$(awk -F: -v user="${USER}" '$1 == user {print $NF}' /etc/passwd)
[[ ${DEFAULT_SHELL} =~ zsh ]] && return 0
[ ${FORCE_ROOT} ] && return 0
STATUS 'setting zsh as default shell'
sudo chsh -s $(which zsh) $(whoami) 2>&1 \
&& SUCCESS "set zsh as default shell for '${USER}'" \
|| FAIL 1 'failed to set zsh as default shell' \
;
}
#####################################################################
CONFIG__VIM() {
CONFIG__RC vim || return 1
STATUS 'starting vim setup'
SCWRYPTS --name system/vim/vundle/install --group scwrypts --type zsh || return 2
CONFIG__VIM__LINK_SUPERUSER_RC
return 0
}
CONFIG__VIM__LINK_SUPERUSER_RC() {
sudo [ /root/.vimrc ] && return 0
echo "let ${DOTWRYN}=\"${DOTWRYN_PATH}\"\nsource \"${DOTWRYN_PATH}/vim/rc.vim\"" \
| sudo tee /root/.vimrc >/dev/null
sudo mkdir -p /root/.vim
sudo ln -s /home/w0ryn/.vim/bundle /root/.vim/bundle
}
#####################################################################
CONFIG__SYSTEM() {
SCWRYPTS dotwryn system setup
}
#####################################################################
CONFIG__ENV() {
local DEFAULT_CONFIG="${DOTWRYN_PATH}/config/dotwryn.env.$1"
local LOCAL_CONFIG="${HOME}/.config/wryn/env.$1"
[ -f ${LOCAL_CONFIG} ] && {
case ${OVERWRITE_EXISTING} in
0 ) return 0 ;;
1 )
WARNING "local $1 configuration exists (${LOCAL_CONFIG})"
yN 'overwrite this configuration?' || return 0
mv "${LOCAL_CONFIG}" "${LOCAL_CONFIG}.bak" >/dev/null 2>&1 \
&& INFO "created backup of local configuration (${LOCAL_CONFIG}.bak)"
esac
}
STATUS "setting up $1 configuration (${LOCAL_CONFIG})"
case $1 in
zsh ) COMMENT='#' ;;
esac
{
echo "source ${DEFAULT_CONFIG}"
echo -e "\\n${COMMENT}\n${COMMENT} .wryn configuration overrides\n${COMMENT}\n"
sed "s/^[^${COMMENT}].*/${COMMENT}&/" ${DEFAULT_CONFIG}
} > ${LOCAL_CONFIG} \
&& SUCCESS "created $1 configuration" \
|| FAIL 1 "unable to create $1 configuration" \
;
EDITOR=vim VISUAL=vim EDIT "${LOCAL_CONFIG}"
}
CONFIG__RC() {
local TYPE="$1"
local RC
case ${TYPE} in
vim )
RC="${XDG_CONFIG_HOME:-${HOME}/.config}/vim/vimrc"
mkdir -p -- "$(dirname -- "${RC}")"
[ -f "${HOME}/.vimrc" ] \
&& cat "${HOME}/.vimrc" >> "${XDG_CONFIG_HOME:-${HOME}/.config}/vim/vimrc" \
&& rm "${HOME}/.vimrc" \
;
;;
* ) RC="${HOME}/.${TYPE}rc";
;;
esac
local SOURCE_LINE
case ${TYPE} in
zsh ) SOURCE_LINE="source ${DOTWRYN_PATH}/zsh/rc" ;;
vim ) SOURCE_LINE="source ${DOTWRYN_PATH}/vim/rc.vim" ;;
esac
grep -q "^${SOURCE_LINE}$" "${RC}" \
|| echo "${SOURCE_LINE}" >> ${RC}
grep -q "^${SOURCE_LINE}$" "${RC}" \
&& SUCCESS "${TYPE}rc is configured correctly" \
|| FAIL 1 "failed to configure ${TYPE}rc" \
;
}