-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
186 lines (161 loc) · 5.14 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
TEST=false
VERBOSE=false
OVERRIDE=false
LN_FLAGS=-sfFn
[ "$(uname)" = 'Linux' ] && LN_FLAGS=-sfn
for i in "$@" ; do
case $i in
"-t"|"--test")
TEST=true
;;
"-v"|"--verbose")
VERBOSE=true
;;
"-o"|"--override")
OVERRIDE=true
;;
*)
;;
esac
shift
done
unset i
get_abs_filename() {
# generate absolute path from relative path
# $1 : relative filename
# return : absolute path
# >&2 echo "ABS 0=$1"
if [ -d "$1" ]; then
# dir
# >&2 echo "ABS 1. $(cd "$1"; pwd)"
echo "$(cd "$1"; pwd)"
elif [ -f "$1" ]; then
# file
if [ "$1" = "*/*" ]; then
# >&2 echo "ABS 2. $(cd "${1%/*}"; pwd)/${1##*/}"
echo "$(cd "${1%/*}"; pwd)/${1##*/}"
else
# >&2 echo "ABS 3. $(pwd)/$1"
echo "$(pwd)/$1"
fi
fi
}
linking_me_softly() {
# $1 = source, $2 = destination
local real_source="$(get_abs_filename "$1")"
# echo "linking_me_softly: 1=$1, 2=$2, real=$real_source."
if [ -z $real_source ] ; then
[ "$VERBOSE" = "true" ] && echo "Cannot find absolute path for $1. File might not exist."
return
fi
( [ "$VERBOSE" = "true" ] || [ "$TEST" = "true" ] ) && echo "Link: $real_source => $2"
if [ -e "$2" ] ; then
if [ "$OVERRIDE" = "false" ] ; then
[ "$VERBOSE" = "true" ] && echo "Skipping: $2 already exists."
return
fi
fi
if [ "$TEST" = "true" ] ; then
echo "Test only"
# echo "Test only TEST=$TEST"
# [ "false" = "true" ] && echo "false=true"
# [ "true" = "true" ] && echo "true=true"
# [ "$TEST" = "true" ] && echo "TEST=true"
# [ "$TEST" = "false" ] && echo "TEST=false"
return
fi
ln $LN_FLAGS $real_source "$2"
}
# init the submodules
( [ "$VERBOSE" = "true" ] || [ "$TEST" = "true" ] ) && echo "Updating git submodules."
if [ "$TEST" = "false" ] ; then
echo "Updating git"
# git submodule update --init
# git submodule update --recursive --remote
fi
# file links
file_links=(bash ctags hg python tmux)
for directory in $(ls -d */) ; do
dir=${directory%%/}
[[ $VERBOSE = true ]] && echo -e "\nHandling $dir:"
if [[ -s $dir/_install.sh ]] ; then
cd $directory
source _install.sh
# this should import a _dotfiles_install_$directory function into the space
basedot=$(basename $directory)
install_func="_dotfiles_install_$basedot"
[[ $VERBOSE = true ]] && echo "Installing according to $dir/_install.sh::$install_func."
install_from="$(pwd)"
echo "install_to=$dir=$install_from"
[[ $(type -t $install_func) = 'function' ]] && eval $install_func "$install_from" "$HOME"
unset install_func
cd ..
fi
done
#####################
# supplemental bash
#####################
URL=https://raw.githubusercontent.com/git/git/master/contrib/completion
curl "$URL/git-completion.bash" --output $HOME/git-completion.bash
curl "$URL/git-completion.zsh" --output $HOME/git-completion.zsh
unset URL
#####################
# zsh. First install oh-my-zsh, then link our zshrc
# This is because oh-my-zsh overrides zshrc anyway
#####################
[ "$VERBOSE" = "true" ] && echo "Installing zshrc"
if [[ "$(uname)" = 'Darwin' || "$(uname)" = 'Linux' ]]; then
if [ -d "$HOME/.oh-my-zsh" ] ; then
[ "$VERBOSE" = "true" ] && echo "oh-my-zsh already installed at $HOME/.oh-my-zsh"
else
[ "$VERBOSE" = "true" ] && echo "Installing oh-my-zsh"
#sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
[ "$VERBOSE" = "true" ] && echo "Linking .zshrc"
linking_me_softly "zsh/.zshrc" "$HOME/.zshrc"
fi
[ "$VERBOSE" = "true" ] && echo "Installing starship"
if [[ "$(uname)" = 'Darwin' || "$(uname)" = 'Linux' ]]; then
mkdir -p "$HOME/.config"
linking_me_softly "config-extras/starship.toml" "$HOME/.config/starship.toml"
fi
###############
# git
###############
[ "$VERBOSE" = "true" ] && echo "Installing git configuration"
GIT="git-prompt.sh gitconfig gitignore_global git_template"
for f in $GIT ; do
linking_me_softly "git/.$f" $HOME/.$f
done
unset f
[ "$(uname)" = 'Darwin' ] && \
linking_me_softly "git/.gitconfig-osx" "$HOME/.gitconfig-extra"
[ "$(uname)" = 'Linux' ] && \
linking_me_softly "git/.gitconfig-linux" "$HOME/.gitconfig-extra"
unset GIT
###############
# VIM
###############
[ "$VERBOSE" = "true" ] && echo "Installing vim configuration"
linking_me_softly "vim" "$HOME/.vim"
[ "$(uname)" = 'Darwin' ] && \
linking_me_softly "vim/xvimrc.vim" "$HOME/.xvimrc"
###############
# VSCode
###############
[ "$VERBOSE" = "true" ] && echo "Linking VSCode settings"
if [ "$(uname)" = 'Darwin' ] ; then
[ "$VERBOSE" = "true" ] && echo "Linking VSCode settings"
linking_me_softly "VSCode/settings.json" "$HOME/Library/Application Support/Code/User/settings.json"
linking_me_softly "VSCode/snippets" "$HOME/Library/Application Support/Code/User/snippets"
linking_me_softly "VSCode/settings.json" "$HOME/Library/Application Support/Code - Insiders/User/settings.json"
linking_me_softly "VSCode/snippets" "$HOME/Library/Application Support/Code - Insiders/User/snippets"
fi
###############
# TMUX
###############
[ "$VERBOSE" = "true" ] && echo "Installing tmux configuration"
linking_me_softly "tmux/.tmux" "$HOME/.tmux"
linking_me_softly "tmux/.tmux.conf" "$HOME/.tmux.conf"
unset LN_FLAGS OVERRIDE TEST VERBOSE