-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·117 lines (96 loc) · 2.63 KB
/
init.sh
File metadata and controls
executable file
·117 lines (96 loc) · 2.63 KB
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
#!/usr/bin/zsh
# Initialize an environment with the bclindner dotfiles.
set -u
# Directory to put the Developer folder
DEV_FOLDER=$HOME/Developer
# Directory to put the dotfiles
DOTSDIR=$DEV_FOLDER/dotfiles
# App versions
PLUGVIM_VERSION="0.11.0"
ANTIDOTE_VERSION="v1.8.6"
ASDF_VERSION="v0.11.3"
#############################
# required commands
REQUIRED_COMMANDS=(mkdir ln zsh nvim git curl)
# paths that cannot be created before initialization
REQUIRED_NONEXISTING_PATHS=(
"$HOME/.asdf"
"$HOME/.zshrc.d"
"$DEV_FOLDER"
"$HOME/.config/nvim"
)
# logging constructs
log() {
echo -e "\033[$1 $2 \033[0m"
}
log_fail() {
log '0;31m[fail]' "$1"
}
log_warn() {
log '0;33m[warn]' "$1"
}
log_info() {
log '0m[info]' "$1"
}
log_ok() {
log '0;32m[done]' "$1"
}
# ensure a command exists
# return a warning log line and return status 1 if it does not
ensure_command_exists() {
if ! command -v $1 &>/dev/null; then
log_warn "command not in PATH: $1"
return 1
fi
}
ensure_path_not_exists() {
if [[ -d "$1" ]]; then
log_warn "path already exists: $1"
return 1
fi
}
log_info "checking for required commands..."
# test for required commands
failures=0
for name in ${REQUIRED_COMMANDS[@]}; do
ensure_command_exists $name
failures=$(($failures+$?))
done
log_info "checking for directory issues..."
for dir in ${REQUIRED_NONEXISTING_PATHS[@]}; do
ensure_path_not_exists $dir
failures=$(($failures+$?))
done
set -e
# if anything failed, exit early
if [ $failures -gt 0 ]; then
log_fail "$failures problems detected, cannot continue"
fi
if [[ $- == *i* ]]; then
# if we are in an interactive session, ask for confirmation
log_info "no problems detected, press enter to continue"
read
fi
log_info "creating developer folder structure..."
mkdir -p "$HOME/Developer"
mkdir -p "$HOME/Developer/projects"
mkdir -p "$HOME/Developer/sandboxes"
mkdir -p "$HOME/Developer/archive"
# detect if we are in the actual repo
if [ -f ./LICENSE ] && [ -f ./nvim ] && [ -f zshrc ]; then
log_info "copying dotfiles to new dir..."
cp -r ../* $DOTSDIR
else
log_info "cloning dotfiles to new dir..."
git clone https://github.com/bclindner/dotfiles.git $DOTSDIR
fi
log_info "setting up (neo)vim..."
mkdir -p $HOME/.config
ln -s "$DOTSDIR/nvim" "$HOME/.config/nvim"
log_info "setting up zsh..."
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch $ASDF_VERSION
ln -s "$DOTSDIR/zshrc" "$HOME/.zshrc"
log_info "setting up misc. links..."
ln -s "$DOTSDIR/gitconfig" "$HOME/.gitconfig"
log_ok "dotfiles fully initialized"
log_ok "run \`source ~/.zshrc\` or relog session to initialize zsh"