-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·85 lines (68 loc) · 1.99 KB
/
install.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
#!/usr/bin/env bash
set -o nounset
set -o errexit
PLATFORM=$(uname)
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$NAME
elif type lsb_release >/dev/null 2>&1; then
DISTRO=$(lsb_release -si)
fi
if [[ "$PLATFORM" == "Darwin" ]]; then
READLINK=greadlink
LN=gln
else
READLINK=readlink
LN=ln
fi
# Assumptions are made that the dotfiles directory is residing under $HOME, in order to provide
# relative symlinks
if [[ -z "$($READLINK -f $0 | grep $HOME)" ]]; then
echo "$($READLINK -f $0) must reside under $HOME"
exit 1
fi
command_exists () {
type "$1" &> /dev/null ;
}
# Check for binaries on PATH that are required for installation of plugins
if ! command_exists git \
|| ! command_exists vim
then
echo "Install git and vim, then re-execute this script"
exit 1
fi
DOTFILESDIR="$(dirname $($READLINK -f $0) | sed -e s,$HOME/,, )"
MAPFILE=$HOME/$DOTFILESDIR/install.mapping
# Check out all git submodules
pushd "$HOME/$DOTFILESDIR" > /dev/null
git submodule update --init --recursive
# cd to $HOME so that we can create relative symlinks
pushd "$HOME" > /dev/null
# Add some standard directories
mkdir -p ~/bin/
mkdir -p ~/.config/nvim/
mkdir -p ~/.git-hooks/
mkdir -p ~/.ssh/c/
# Iterate over the mappings in the mapping file
for kv in $(cat $MAPFILE); do
# Split the two parts between the colon into SOURCE and DEST
IFS=":" read -ra MAP <<< "$kv"
SOURCE=${MAP[0]}
DEST=${MAP[1]}
# Check to see if there's already a symlink between the destination and source paths
if [ "$($READLINK -e "${HOME}/${DEST}")" != "$HOME/$DOTFILESDIR/$SOURCE" ]; then
# If not, create a relative symlink, backing up any old file with the same name
$LN -b -s -r "$DOTFILESDIR/$SOURCE" "$DEST"
fi
done
popd > /dev/null
# Install vim dependencies
if [[ "$PLATFORM" == "Linux" ]]; then
if ! command_exists pip3; then
sudo apt install python3-pip
fi
pip3 install --upgrade pynvim
fi
# Install vim plugins
vim +PlugInstall! +qall
echo "If this is the first time running this script, then start a new shell"