-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·90 lines (77 loc) · 2.22 KB
/
bootstrap.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
#!/usr/bin/env bash
set -euo pipefail
ROOT_PATH=$(
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd
)
cd "${ROOT_PATH}"
source "./.functions"
linkFiles () {
if [[ -L "${2}" ]]; then
output_info "SKIP '${1}' -> symlink already exists in '${2}'"
return 0;
fi
if [[ -d "${2}" && ! -L "${2}" ]]; then
read -p "Directory '${2}' already exists. Do you want to sync it and create symlink ?(y/n) " -n 1;
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rsync -ah "${2}" "$(dirname ${1})" --delete
rm -rf "${2}"
else
return 0;
fi
fi
if ln -snfT "${1}" "${2}"; then
output_success "linked ${1} to ${2}"
else
output_error "linked ${1} to ${2}"
fi
}
doIt () {
# Create config files
for file in $(find ${ROOT_PATH} \
-maxdepth 1 \
-name ".*" \
-not -name ".gitignore" \
-not -name ".extra" \
-not -name ".gitconfig_private" \
-not -name ".git" \
-not -name ".idea" \
-not -name ".local" \
-not -name ".config" \
-not -name "*.swp" \
-not -path "*.gitmodules*" \
-not -path "*.git/*")
do
linkFiles "${file}" "${HOME}/$(basename ${file})"
done
mkdir -p "${HOME}/.config/zellij"
linkFiles "${ROOT_PATH}/.config/starship.toml" "${HOME}/.config/starship.toml"
linkFiles "${ROOT_PATH}/.config/zellij/config.kdl" "${HOME}/.config/zellij/config.kdl"
mkdir -p "${HOME}/.local/bin"
for script in script/*
do
linkFiles "${ROOT_PATH}/${script}" "${HOME}/.local/bin/$(basename ${script})"
done
# Create private files if they do not exist
for file in ".extra" ".gitconfig_private"
do
if [[ ! -f "${HOME}/${file}" ]]; then
cp "${file}" "${HOME}"
output_success "Create ${file} in home ${HOME}"
else
output_info "SKIP private file '${file}' -> already exists"
fi
done
}
if [[ "${1:-}" == "--force" || "${1:-}" == "-f" ]]; then
doIt
else
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
doIt
fi
fi
unset doIt