-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·113 lines (88 loc) · 2.61 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
#!/usr/bin/env bash
set -eu
set -o pipefail
EMACS_DIR="${EMACS_DIR:-$HOME/.emacs.d}"
PAIRING_EMACS_REPO="${PAIRING_EMACS_REPO:-https://github.com/totherme/pairing-emacs}"
RED='\033[0;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # No Colour
main() {
info "Attempting to clone pairing-emacs..."
get_git_repo "$PAIRING_EMACS_REPO" "$EMACS_DIR"
info "Attempting to install golang tooling..."
optionally_get_go_tools
info "Attempting to install tmux config..."
install_tmux_config_from "${EMACS_DIR}/tmux.conf"
echo -e "${GREEN}DONE${NC}: See ${EMACS_DIR}/README.md for how to use this emacs setup."
}
get_git_repo() {
local git_repo target_dir
git_repo="${1:?Expected git_repo in get_git_repo}"
target_dir="${2:?Expected target_dir in get_git_repo}"
if ! which git 2>/dev/null >/dev/null ; then
fail "You don't seem to have git in your \$PATH. You'll need it to clone the pairing-emacs repo."
fi
if [[ -e "$target_dir" ]] ; then
warn "Found existing ${target_dir}. Backing it up."
backup_and_remove "$target_dir"
fi
git clone --recurse-submodules -q "$git_repo" "$target_dir"
}
backup_and_remove() {
local file backup i
file="${1:?Expected file name in backup_and_remove}"
shopt -s extglob # Strip trailing '/' chars
file="${file%%+(/)}"
if [[ ! -e "$file" ]] ; then
return
fi
backup="${file}.backup"
i=1
while [[ -e "$backup" ]] ; do
backup="${file}.backup.${i}"
(( i++ ))
done
mv "$file" "$backup"
}
optionally_get_go_tools() {
if ! which go 2> /dev/null > /dev/null ; then
warn "You don't seem to have go. Skipping installing the go tools."
return 0
fi
if [[ -z "$GOPATH" ]] ; then
warn "You don't seem to have a \$GOPATH set up. Skipping installing the go tools."
return 0
fi
go get -u golang.org/x/tools/cmd/goimports \
github.com/rogpeppe/godef \
github.com/nsf/gocode \
github.com/dougm/goflymake
}
install_tmux_config_from() {
local source target
source="${1:?Expected source path in install_tmux_config_from}"
target="${HOME}/.tmux.conf"
if [[ -e "$target" ]] ; then
warn "Found an existing \$HOME/.tmux.conf. Backing it up."
backup_and_remove "$target"
fi
ln -s "$source" "$target"
}
fail() {
echo -e "${RED}FAIL${NC}:" "$@" >&2
exit 1
}
warn() {
echo -e "${YELLOW}WARNING${NC}:" "$@" >&2
}
info() {
echo -e "${BLUE}INFO${NC}:" "$@"
}
if [[ ! -z "${TESTS_ONLY:-}" ]] ; then
# We're in a test harness. Don't do anything side-effecting. Just
# load the functions for unit testing.
return 0
fi
main