-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·131 lines (113 loc) · 2.58 KB
/
setup.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
# exit when any command fails
set -e
_add_config() {
local config=$1
local dest_dir=$2
local prefix=$3
local dest
dest=$dest_dir/$prefix$(basename "$config")
if [[ $OVERWRITE == 0 ]]; then
echo "info add $config -> $dest"
else
echo "info overwriting $config -> $dest"
fi
[[ $DRY_RUN != 0 ]] && return
# check that config exists
config=$(realpath $config)
if [[ ! -f "$config" && ! -d "$config" ]]; then
echo "error $config file does not exist"
exit 1
fi
# check that destination is a directory and exists
if [[ ! -d "$dest_dir" ]]; then
echo "error $dest_dir directory does not exist"
exit 1
fi
if [[ $OVERWRITE == 0 ]]; then
ln -s "$config" "$dest"
else
ln -s -f "$config" "$dest"
fi
}
_add_config_basic() {
_add_config "$1" "$HOME" "."
}
_setup_local_bin() {
# print out bin path
echo "info bin path: $BIN_PATH"
# check if path contains BIN_PATH
if [[ ":$PATH:" == *":$BIN_PATH:"* ]]; then
echo "info path contains $BIN_PATH"
else
echo "warn path does NOT contain $BIN_PATH"
# echo "info add $BIN_PATH to PATH temporarily"
# PATH=$BIN_PATH:$PATH
fi
# create bin path if does not exist
if [[ ! -d $BIN_PATH ]]; then
echo "info mkdir $BIN_PATH"
[[ $DRY_RUN == 0 ]] && mkdir -p "$BIN_PATH"
fi
}
_setup_configs() {
_add_config_basic alacritty.yml
_add_config_basic bash/bashrc
_add_config_basic git/gitconfig
_add_config_basic git/gitignore
_add_config_basic inputrc
_add_config_basic nvim/vimrc
_add_config nvim/init.lua "$HOME/.config/nvim" ""
_add_config nvim/my_modules/ "$HOME/.config/nvim/lua" ""
_add_config nvim/ftplugin "$HOME/.config/nvim/" ""
_add_config_basic psqlrc
_add_config_basic sqliterc
_add_config_basic tmux.conf
}
setup() {
_setup_local_bin
_setup_configs
}
usage() {
echo "usage: $0 [-h | --help] [-n | --dry-run] [-b | --bin-dir <path>]"
echo "sets up my configs and tools"
echo "opts:"
cat <<-_EOF_
-h, --help display help and exit
-n, --dry-run display actions that would have been done
-p, --bin-path <path> set path to install local binaries
-o, --overwrite overwrite config, by default set up fails if config already exists in HOME
_EOF_
return
}
DRY_RUN=0
BIN_PATH=$HOME/LOCAL/bin
OVERWRITE=0
while [[ -n "$1" ]]; do
case "$1" in
-n | --dry-run)
DRY_RUN=1
;;
-o | --overwrite)
OVERWRITE=1
;;
-h | --help)
usage
exit
;;
-b | --bin-path)
shift
BIN_PATH="$1"
if [[ ! -d "$BIN_PATH" && $DRY_RUN == 0 ]]; then
echo "Invalid directory path: $BIN_PATH" >&2
exit 1
fi
;;
*)
usage >&2
exit 1
;;
esac
shift
done
setup