forked from MrPickles/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·129 lines (111 loc) · 3.2 KB
/
setup.sh
File metadata and controls
executable file
·129 lines (111 loc) · 3.2 KB
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
#!/bin/bash
# Initialization script to symlink the dotfiles.
# Based off https://github.com/nicksp/dotfiles/blob/master/setup.sh.
print_success() {
# Print output in green
printf "\e[0;32m [✔] $1\e[0m\n"
}
print_error() {
# Print output in red
printf "\e[0;31m [✖] $1 $2\e[0m\n"
}
print_question() {
# Print output in yellow
printf "\e[0;33m [?] $1\e[0m"
}
execute() {
$1 &> /dev/null
print_result $? "${2:-$1}"
}
print_result() {
[ $1 -eq 0 ] \
&& print_success "$2" \
|| print_error "$2"
[ "$3" == "true" ] && [ $1 -ne 0 ] \
&& exit
}
ask_for_confirmation() {
print_question "$1 [y/N] "
read -n 1
printf "\n"
}
answer_is_yes() {
[[ "$REPLY" =~ ^[Yy]$ ]] \
&& return 0 \
|| return 1
}
install_zsh () {
# Test to see if zshell is installed. If it is:
if [ -f /bin/zsh -o -f /usr/bin/zsh ]; then
# Install Oh My Zsh if it isn't already present
if [[ ! -d $HOME/.oh-my-zsh/ ]]; then
echo "Switching to oh-my-zsh. Please re-run this script afterwards!"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
fi
# Set the default shell to zsh if it isn't currently set to zsh
if [[ ! $(echo $SHELL) == $(which zsh) ]]; then
chsh -s $(which zsh)
fi
else
# If zsh isn't installed, get the platform of the current machine
platform=$(uname);
# If the platform is Linux, try an apt-get to install zsh and then recurse
if [[ $platform == 'Linux' ]]; then
if [[ -f /etc/redhat-release ]]; then
sudo yum install zsh
install_zsh
fi
if [[ -f /etc/debian_version ]]; then
sudo apt-get install zsh
install_zsh
fi
# If the platform is OS X, tell the user to install zsh :)
elif [[ $platform == 'Darwin' ]]; then
echo "We'll install zsh, then re-run this script!"
brew install zsh
exit
fi
fi
}
declare -a FILES_TO_SYMLINK=(
'editor/vim'
'editor/vimrc'
'git/gitattributes'
'git/gitconfig'
'git/gitignore'
'shell/dircolors'
'shell/gdbinit'
'shell/tmux.conf'
'shell/tmux-power'
'shell/zshrc'
'shell/zsh'
'bin'
)
# Prompt to switch to zsh and oh-my-zsh if not active on terminal.
if [ ! -f /bin/zsh -a ! -f /usr/bin/zsh -o ! -d $HOME/.oh-my-zsh/ ]; then
ask_for_confirmation "Switch to zsh and oh-my-zsh?"
if answer_is_yes; then
install_zsh
fi
fi
for i in ${FILES_TO_SYMLINK[@]}; do
sourceFile="$(pwd)/$i"
targetFile="$HOME/.$(printf "%s" "$i" | sed "s/.*\/\(.*\)/\1/g")"
if [ ! -e "$targetFile" ]; then
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"
elif [ "$(readlink "$targetFile")" == "$sourceFile" ]; then
print_success "$targetFile → $sourceFile"
else
ask_for_confirmation "'$targetFile' already exists, do you want to overwrite it?"
if answer_is_yes; then
rm -rf "$targetFile"
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"
else
print_error "$targetFile → $sourceFile"
fi
fi
done
# Link custom zsh theme.
sourceFile="$(pwd)/themes/krockpot.zsh-theme"
targetFile="$HOME/.oh-my-zsh/custom/krockpot.zsh-theme"
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"