forked from Parth/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·100 lines (90 loc) · 2.51 KB
/
deploy
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
prompt_install() {
echo -n "$1 is not installed. Would you like to install it? (y/n) " >&2
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
# This could def use community support
case "$(uname -s)" in
Darwin)
brew install $1
;;
Linux)
sudo apt install $1 -y
;;
FreeBSD)
sudo pkg install $1
;;
*)
echo "Operating system not recognized, please install $1 manually, then re-run this script."
exit 1
;;
esac
fi
}
check_for_software() {
echo "Checking to see if $1 is installed"
if ! [ -x "$(command -v $1)" ]; then
prompt_install $1
else
echo "$1 is installed."
fi
}
check_default_shell() {
if [ -z "${SHELL##*zsh*}" ] ;then
echo "Default shell is zsh."
else
echo -n "Default shell is not zsh. Do you want to chsh -s \$(which zsh)? (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)
else
echo "Warning: Your configuration won't work properly. If you exec zsh, it'll exec tmux which will exec your default shell which isn't zsh."
fi
fi
}
echo "We're going to do the following:"
echo "1. Check to make sure you have zsh, vim, and tmux installed"
echo "2. We'll help you install them if you don't"
echo "3. We're going to check to see if your default shell is zsh"
echo "4. We'll try to change it if it's not"
echo "Let's get started? (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, nothing was changed."
exit 0
fi
check_for_software zsh
echo
check_for_software vim
echo
check_for_software tmux
echo
check_default_shell
echo
echo -n "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 -e "\nNot backing up old dotfiles."
fi
printf "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
echo
echo "Please log out and log back in for default shell to be initialized."