-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect
executable file
·181 lines (149 loc) · 4.42 KB
/
collect
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
##
# ./collect
# - Collects local configuration files and prepares them for version control.
##
set -e
SCRIPT_DIR="$(
cd "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"
NEOVIM_CONFIG_PATH=~/.config/nvim
STARSHIP_CONFIG_PATH=~/.config/starship.toml
TMUX_CONFIG_PATHS=(~/.config/tmux/tmux.conf ~/.config/tmux/themes)
WTF_CONFIG_PATH=~/.config/wtf/config.yml
STYLE_RESET=$(printf '\e[0m')
STYLE_BOLD=$(printf '\e[1m')
STYLE_HEADER=$(printf '\e[1;97m')
STYLE_SUBHEADER=$(printf '\e[1;36m')
STYLE_PARAGRAPH=$(printf '\e[2m')
STYLE_CLEAR_PREVIOUS_LINE="$(printf '\e[1A\e[2K')"
function showError {
echo -e "${STYLE_RESET}${STYLE_BOLD}\nERROR: $1${STYLE_RESET}" 1>&2
exit 1
}
function showInfo {
echo -e "${STYLE_RESET}${STYLE_BOLD}./$(basename $0)${STYLE_RESET}"
echo "Collects local configuration files and prepares them for version control."
}
function printHeader {
echo -e "${STYLE_RESET}\n${STYLE_HEADER}$1${STYLE_RESET}"
}
function printSubheader {
echo -e "${STYLE_RESET}\n${STYLE_HEADER}▸${STYLE_RESET} ${STYLE_SUBHEADER}$1${STYLE_RESET}"
}
function printParagraph {
echo -e "${STYLE_RESET} ${STYLE_PARAGRAPH}$1${STYLE_RESET}"
}
function clearPreviousLine {
printf $STYLE_CLEAR_PREVIOUS_LINE
}
function waitForEnterKey {
tput bel
read -p "Press Enter to continue"
clearPreviousLine
}
function main {
# parse arguments
while [ $# -gt 0 ]; do
case $1 in
--help)
showInfo
exit
;;
-h)
showInfo
exit
;;
*) showError "Invalid option $1" ;;
esac
shift
done
collect
}
function collect {
printHeader "☕️ Collecting local configurations..."
echo "About to gather local configuration files and copy them into ${SCRIPT_DIR/#$HOME/~}."
waitForEnterKey
clearPreviousLine
################################################
printSubheader "WezTerm"
[[ -f ~/.wezterm.lua ]] && cp -r ~/.wezterm.lua $SCRIPT_DIR/
################################################
printSubheader "Neovim and its plugins"
[[ -d $NEOVIM_CONFIG_PATH ]] && cp -r $NEOVIM_CONFIG_PATH $SCRIPT_DIR/
################################################
printSubheader "Starship prompt config"
if [[ -f $STARSHIP_CONFIG_PATH ]]; then
cp $STARSHIP_CONFIG_PATH $SCRIPT_DIR/
else
printParagraph "$STARSHIP_CONFIG_PATH doesn't exist"
fi
################################################
printSubheader "tmux configuration"
if [[ -f $TMUX_CONFIG_PATHS ]]; then
[ ! -d $SCRIPT_DIR/tmux ] && mkdir $SCRIPT_DIR/tmux
for path in "${TMUX_CONFIG_PATHS[@]}"; do
cp -r "${path}" "${SCRIPT_DIR}/tmux/"
done
fi
################################################
printSubheader "Git"
if [[ -f ~/.gitconfig ]]; then
printParagraph "~/.gitconfig"
cp ~/.gitconfig $SCRIPT_DIR/.gitconfig_global
else
printParagraph "~/.gitconfig doesn't exist"
fi
if [[ -f $SCRIPT_DIR/.gitconfig_global ]]; then
# strip Git config from user specifics
cat $SCRIPT_DIR/.gitconfig_global |
grep -v "email = $(git config --global user.email)" |
grep -v "name = $(git config --global user.name)" \
>$SCRIPT_DIR/.gitconfig_global
fi
if [[ -f ~/.gitignore ]]; then
printParagraph "~/.gitignore"
cp ~/.gitignore $SCRIPT_DIR/.gitignore_global
else
printParagraph "~/.gitignore doesn't exist"
fi
if [[ -f ~/.gitattributes ]]; then
printParagraph "~/.gitattributes"
cp ~/.gitattributes $SCRIPT_DIR/.gitattributes_global
else
printParagraph "~/.gitattributes doesn't exist"
fi
################################################
printSubheader "Zsh dotfiles"
if [[ -f ~/.zshrc ]]; then
printParagraph "~/.zshrc"
cp ~/.zshrc $SCRIPT_DIR/.zshrc
else
printParagraph "~/.zshrc doesn't exist"
fi
printSubheader "ripgrep"
if [[ -f ~/.rgignore ]]; then
printParagraph "~/.rgignore"
cp ~/.rgignore $SCRIPT_DIR/.rgignore_global
else
printParagraph "~/.rgignore doesn't exist"
fi
if [[ -f ~/.ripgreprc ]]; then
printParagraph "~/.ripgreprc"
cp ~/.ripgreprc $SCRIPT_DIR/.ripgreprc
else
printParagraph "~/.ripgreprc doesn't exist"
fi
printSubheader "WTF Terminal Dashboard"
if [[ -f $WTF_CONFIG_PATH ]]; then
printParagraph $WTF_CONFIG_PATH
cp $WTF_CONFIG_PATH $SCRIPT_DIR/wtf_dashboard_config.yml
else
printParagraph "$WTF_CONFIG_PATH doesn't exist"
fi
################################################
tput bel
printHeader "🎉 All done!"
}
main "$@"