-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·116 lines (98 loc) · 2.51 KB
/
install
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
#!/bin/sh
# link TARGET NAME
#
# Creates a symbolic link from NAME to TARGET, printing the result.
#
# If NAME already exists and is not a link to TARGET, it is first moved to
# "NAME.original".
link () {
[[ "$1" && "$2" ]] || return
local -r target="$1"
local name="$2"
if [[ ! -L "${name}" && -d "${name}" ]]; then
name+="$(basename ${target})"
fi
readonly name
set -eu
echo -n "${name} -> ${target}"
if [[ ! -e "${target}" ]]; then
echo " (target doesn't exist)"
elif [[ "$(readlink ${name})" == "${target}" ]]; then
echo " (already exists)"
else
if [[ -e "${name}" || -L "${name}" ]]; then
echo " (existing ${name} moved to ${name}.original)"
mv "${name}"{,.original}
else
echo ""
fi
ln -s "${target}" "${name}"
fi
}
# source_rc TARGET RC
#
# Sources TARGET from RC.
source_rc() {
local -r target="$1"
local -r rc="$2"
local -r src="source ${target}"
echo -n "${rc} => ${target}"
if grep -Fxq "${src}" "${rc}" 2>/dev/null; then
echo " (already exists)"
else
echo ""
echo "${src}" >> "${rc}"
fi
}
# prompt MSG
#
# Prints "Press [Enter] to MSG", then waits for [Enter] to be pressed.
prompt() {
echo -e "\n\e[0;34mPress [Enter] to $1\e[m"
read
}
install_tmux_plugins() {
if [[ ! -e ".tmux/plugins/tpm/tpm" ]]; then
git clone https://github.com/tmux-plugins/tpm .tmux/plugins/tpm
fi
}
# install_vim_plugins
install_vim_plugins() {
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
nvim +PlugClean +PlugInstall +GoInstallBinaries +qall
}
# install SRC_DIR
setup_dotfiles() {
[[ "$1" ]] || return
source_rc "$1/bashrc" ".bashrc"
mkdir -p .config/nvim && source_rc "$1/nvimrc" ".config/nvim/init.vim"
echo ""
link "$1/dir_colors" ".dir_colors"
link "$1/gitconfig" ".gitconfig"
link "$1/gitignore" ".gitignore"
link "$1/tmux.conf" ".tmux.conf"
echo ""
mkdir -p bin && ls "$1/bin" | while read f; do
link "$1/bin/${f}" "bin/${f}"
done
}
# install SRC_DIR
install() {
[[ "$1" ]] || return
prompt "source (=>) and link (->) dotfiles"
setup_dotfiles "$1"
prompt "install tmux plugins"
install_tmux_plugins
prompt "install vim plugins"
install_vim_plugins
echo -e "\n\e[0;34mDone!\e[m"
echo -e "\nReopen any bash sessions to make use of the new goodness."
}
main() {
set -eu
local -r src_dir="$(realpath -s "$(dirname -- "$0")")"
cd ~
install "${src_dir}"
}
if [[ "$0" == "$BASH_SOURCE" ]]; then main "$@"; fi