-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.zsh
executable file
·97 lines (82 loc) · 2.21 KB
/
install.zsh
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
#!/usr/bin/env zsh
# Shamelessly stole from https://github.com/rwjblue/dotfiles/blob/master/install.zsh
#
set -e # fail if anything exits non-zero
DOTFILES=$(dirname ${(%):-%x})
abspath() {
# generate absolute path from relative path
# $1 : relative filename
# return : absolute path
if [ -d "$1" ]; then
# dir
(cd "$1"; pwd)
elif [ -f "$1" ]; then
# file
if [[ $1 = /* ]]; then
echo "$1"
elif [[ $1 == */* ]]; then
echo "$(cd "${1%/*}"; pwd)/${1##*/}"
else
echo "$(pwd)/$1"
fi
fi
}
link-dotfile() {
local SOURCE=$1
local TARGET=$2
local ABSOLUTE_SOURCE=$(abspath $DOTFILES/$SOURCE)
if [ "$FORCE" = "true" ]; then
rm -rf $TARGET
fi
if [ -e $TARGET ]; then
if [ -L $TARGET ]; then
current=$(readlink $TARGET)
if [ $current != $ABSOLUTE_SOURCE ]; then
echo "$TARGET already exists and is symlinked to $current"
fi
else
echo "$TARGET already exists"
fi
else
echo "creating link for $TARGET"
mkdir -p $(dirname $TARGET)
ln -s $ABSOLUTE_SOURCE $TARGET
fi
}
copy-dotfile() {
local SOURCE=$1
local TARGET=$2
local ABSOLUTE_SOURCE=$(abspath $DOTFILES/$SOURCE)
if [ "$FORCE" = "true" ]; then
rm -rf $TARGET
fi
if [ -e $TARGET ]; then
echo "$TARGET already exists";
else
echo "creating $TARGET"
mkdir -p $(dirname $TARGET)
cp $ABSOLUTE_SOURCE $TARGET
fi
}
if [[ "$OSTYPE" == darwin* ]]; then
if ! command -v brew >/dev/null; then
echo "Installing Homebrew ..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install zplug fzf ripgrep fasd
else
if [[ ! -d $HOME/.zplug ]]; then
echo "Installing zplug"
git clone https://github.com/zplug/zplug.git $HOME/.zplug
fi
if [[ ! -d $HOME/.fzf ]]; then
echo "Installing fzf"
git clone https://github.com/junegunn/fzf.git $HOME/.fzf
$HOME/.fzf/install
fi
sudo add-apt-repository ppa:aacebedo/fasd && sudo apt-get update && sudo apt-get install fasd
fi
link-dotfile "zsh/zshrc" "$HOME/.zshrc"
link-dotfile "git/gitconfig" "$HOME/.gitconfig"
link-dotfile "git/gitignore_global" "$HOME/.gitignore_global"
link-dotfile "vim/vimrc" "$HOME/.vimrc"