-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·157 lines (127 loc) · 3.97 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
prompt_install() {
echo -n "$1 installation was not found. Do you want to install it? (y/n)"
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
stty $old_stty_cfg && echo
if echo "$answer" | grep -iq "^y"; then
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get install $1 -y
elif [ -x "$(command -v brew)" ]; then
brew install $1
elif [ -x "$(command -v pkg)" ]; then
sudo pkg install $1
elif [ -x "$(command -v pacman)" ]; then
sudo pacman -S $1
else
echo "Could not find your package manager. Please install $1 manually."
fi
fi
}
check_installation() {
echo "Checking your $1 installation"
if ! [ -x "$(command -v $1)" ]; then
prompt_install $1
else
tput setaf 2; echo "[ok] $1 installation"
tput setaf 7;
fi
}
change_default_shell_to_zsh() {
echo
if [ -z "${SHELL##*zsh*}" ] ;then
echo "Your default shell is ZSH."
else
echo "Default shell is not zsh. Do you want to set it as default now? (y/n)"
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
stty $old_stty_cfg && echo
if echo "$answer" | grep -iq "^y"; then
chsh -s $(which zsh)
echo "Please log out and log back in to reload your default shell"
else
echo "Skipping Setting Default shell..."
fi
fi
}
backup_dotfiles() {
echo
echo "Would you like to backup your current dotfiles? (y/n) "
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y"; then
mv ~/.zshrc ~/.zshrc.old
mv ~/.tmux.conf ~/.tmux.conf.old
mv ~/.vimrc ~/.vimrc.old
else
echo "Skpping backup..."
fi
}
change_default_configuration_source() {
printf "export MACHINE_NAME=\"$($MACHINE_NAME)\" \n source '$HOME/.dotfiles/zsh/zshrc_manager.sh'" > ~/.zshrc
printf "so $HOME/.dotfiles/vim/vimrc.vim" > ~/.vimrc
printf "source-file $HOME/.dotfiles/tmux/tmux.conf" > ~/.tmux.conf
}
link_ideavimrc() {
ln -s ~/.dotfiles/idea/ideavimrc.vim ~/.ideavimrc
}
link_thinkvim_config() {
ln -s ~/.dotfiles/vim/thinkvim.d ~/.thinkvim.d
}
setup_git() {
sh ~/.dotfiles/gitconfig/setup.sh
}
install_homebrew_when_host_is_macos() {
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! [ -x "$(command -v $1)" ]; then
echo "[!] No installation of Homebrew was found"
echo "[+] Installing Homebrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo "[!] Found Homebrew Installation at $(which brew)"
fi
fi
}
function install_lunar_vim() {
bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh)
}
main() {
echo "=====Welcome to my .terminal======="
echo "This script will do the following:"
echo " 1. Check if you have zsh, tmux and vim installed"
echo " 2. Help you install it if you don't"
echo " 3. Check your default shell"
echo " 4. Try to change your default shell"
echo
echo "Do you want to continue? (y/n)"
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$(while ! head -c 1 | grep -i '[ny]'; do true; done)
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y"; then
echo
else
echo "Quitting..."
exit 0
fi
echo "[+] What's your machine name? "
read MACHINE_NAME
install_homebrew_when_host_is_macos
check_installation zsh
check_installation neovim
check_installation vim
check_installation tmux
check_installation git
check_installation exa
check_installation bat
install_lunar_vim
link_ideavimrc
setup_git
change_default_shell_to_zsh
backup_dotfiles
change_default_configuration_source
}
main