-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·106 lines (83 loc) · 2.13 KB
/
install.sh
File metadata and controls
executable file
·106 lines (83 loc) · 2.13 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
#!/usr/bin/env bash
#
# install.sh
#
##
set -o pipefail
BASE_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly BASE_DIR
VIM_PLUGINS=(
https://github.com/editorconfig/editorconfig-vim.git
https://github.com/grafana/vim-alloy.git
https://github.com/hashivim/vim-terraform.git
)
LN_OPTS=()
function _usage()
{
cat << EOF
Usage: $0 [options]
Options:
-f, --force Overwrite existing files (default: false)
-h, --help Show this message
EOF
}
function install_dotfiles()
{
local src_path
local target_dir
local src_dir
echo "--> Installing dotfiles..."
# Ignore current and upper directories
GLOBIGNORE=".:.."
for src_path in "${BASE_DIR}/src"/.* ; do
if [[ -f "$src_path" ]] ; then
ln -s -v "${LN_OPTS[@]}" "$src_path" "$HOME"
elif [[ -d "$src_path" ]] ; then
target_dir="${HOME}/$( basename "$src_path" )"
mkdir -p -v "$target_dir" || continue
for src_dir in "${src_path}"/* ; do
ln -s -v "${LN_OPTS[@]}" "$src_dir" "$target_dir"
done
fi
done
}
function install_vim_plugins()
{
local plugin_repo
local plugin_dir
echo "--> Installing Vim plugins..."
for plugin_repo in "${VIM_PLUGINS[@]}" ; do
plugin_dir="${HOME}/.vim/pack/plugins/start/$( basename "${plugin_repo/.git/}" )"
if [[ ! -d "$plugin_dir" ]] ; then
echo "--> Installing plugin '$plugin_repo'"
git clone "$plugin_repo" "$plugin_dir"
else
echo "--> Directory '$plugin_dir' already exists, running 'git pull'"
git -C "$plugin_dir" pull
fi
done
}
function main()
{
while [[ $# -gt 0 ]] ; do
case $1 in
-f|--force)
LN_OPTS+=( --force )
;;
-h|--help)
_usage
exit 0
;;
*)
echo "Invalid argument: $1"
_usage
exit 2
;;
esac
shift
done
install_dotfiles
install_vim_plugins
echo "--> Done"
}
main "$@"