-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure_zsh.sh
executable file
·131 lines (83 loc) · 2.45 KB
/
configure_zsh.sh
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
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "utils/setup.sh" \
&& . "utils/brew.sh" \
&& cd ..
declare -r DOTFILES_ROOT="$HOME/.dotfiles"
declare -r ZSHRC_FILE="$HOME/.zshrc"
declare -r ALIASES_FILE="$DOTFILES_ROOT/link/.aliases"
declare -r EXPORTS_FILE="$DOTFILES_ROOT/link/.exports"
declare -r INITS_FILE="$DOTFILES_ROOT/link/.inits"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
create_link_directory() {
if [ ! -d "link" ]; then
mkdir link
fi
}
create_zsh_files() {
create_file $INITS_FILE
create_file $ALIASES_FILE
create_file $EXPORTS_FILE
}
create_file() {
if [ ! -f $1 ]; then
touch $1
else
# reset file
echo > $1
fi
}
configure_aliases() {
# find the aliases and run them iteratively
find . -name alias.sh | while read aliasFile ; do source_file ${aliasFile:1} ${ALIASES_FILE} ; done
print_success "Aliases configured"
}
configure_exports() {
# find the exports and run them iteratively
find . -name export.sh | while read exportFile ; do source_file ${exportFile:1} ${EXPORTS_FILE} ; done
print_success "Exports created"
}
configure_inits() {
# find the inits and run them iteratively
find . -name init.sh | while read initFile ; do source_file ${initFile:1} ${INITS_FILE} ; done
print_success "Inits created"
}
source_file() {
echo "source $DOTFILES_ROOT$1" >> $2
}
configure_zshrc_file() {
if [ ! -f $ZSHRC_FILE ]; then
touch $ZSHRC_FILE
else
# reset file
echo > $ZSHRC_FILE
fi
# zsh file linked to .zshrc
echo "source $ALIASES_FILE" >> $ZSHRC_FILE
echo "source $EXPORTS_FILE" >> $ZSHRC_FILE
echo "source $INITS_FILE" >> $ZSHRC_FILE
printf "\n"
print_success "Zshrc file configured"
}
refresh_zsh() {
ask_for_confirmation "Do you want to refresh zsh?"
printf "\n"
if answer_is_yes; then
exec zsh
fi
}
main() {
print_in_purple "\n\n • Zsh configures\n\n\n"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
create_link_directory
create_zsh_files
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
configure_aliases
configure_exports
configure_inits
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
configure_zshrc_file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
refresh_zsh
}
main