forked from Parth/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·156 lines (139 loc) · 4.04 KB
/
deploy
File metadata and controls
executable file
·156 lines (139 loc) · 4.04 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
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
#!/bin/sh
prompt_install() {
echo -n "install $1? (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
if [ -x "$(command -v brew)" ]; then
brew install $1
elif [ -x "$(command -v pacman)" ]; then
sudo pacman -S $1
elif [ -x "$(command -v apt)" ]; then
sudo apt install $1
else
echo "Package system could not be infered. Install $1 and launch deploy again."
fi
fi
}
check_for_software() {
echo -n "Checking if $1 is installed: "
if ! [ -x "$(command -v $1)" ]; then
echo "✗ no"
prompt_install $1
else
echo "✓ ok"
fi
}
check_default_shell() {
echo -n "Checking default shell: "
if [ -z "${SHELL##*zsh*}" ] ;then
echo "✓ zsh"
else
echo -n "✗ it is not zsh. Change this? (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) && echo " ... ✓ ok"
fi
fi
}
vim_plugin_prompt_install() {
if [ -e ~/.vim/bundle/$(basename $1) ]; then
echo " . $(basename $1 | sed -e 's/.git//'): ✓ ok"
else
echo -n " . $(basename $1 | sed -e 's/.git//'): ✗ Instalall? (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
if echo "$answer" | grep -iq "^y" ;then
git clone $1 ~/.vim/bundle/$(basename $1)
else
echo "Ignoring"
fi
fi
}
vim_plugins_install() {
echo "Checking for vim-pathogen (https://github.com/tpope/vim-pathogen)"
if [ -e ~/.vim/autoload/pathogen.vim ]; then
echo "pathogen is installed"
else
echo "couldn't find pathogen. Install it?"
if ! [ -x "$(command -v curl)" ]; then
echo "Ops! Missing the command 'curl'."
prompt_install curl
fi
mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
fi
echo "Installing vim plugins:"
vim_plugin_prompt_install https://github.com/leafgarland/typescript-vim.git
vim_plugin_prompt_install https://github.com/scrooloose/nerdtree.git
vim_plugin_prompt_install https://tpope.io/vim/surround.git
}
asdf_vm_install() {
echo -n "Checking for asdf-vm: "
if [ -e ~/.asdf ]; then
echo "✓ ok"
else
echo -n "✗ nope. Installing ... "
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.0
[ 0 -eq $? ] && echo "✓ ok"
fi
}
echo "Deploying dotfiles is about"
echo "1. Checking for useful apps:"
echo " . zsh, vim, tmux, xclip, eza, zoxide"
echo " . git, tig, curl"
echo " . asdf"
echo "2. Install what may be missing"
echo "3. Check and define zsh as default shell, if necessary"
echo "5. Install pathogen and some vim plugins"
echo "Let's start? (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 "Leaving, nothing has been changed."
exit 0
fi
check_for_software zsh
check_for_software vim
check_for_software tmux
check_for_software eza
check_for_software curl
check_for_software git
check_for_software tig
check_for_software zoxide
asdf_vm_install
echo
check_default_shell
vim_plugins_install
echo
echo -n "Would you like to save (rename to *.old) 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 ~/.zprofile ~/.zprofile.old
mv ~/.tmux.conf ~/.tmux.conf.old
mv ~/.tigrc ~/.tigrc.old
mv ~/.vimrc ~/.vimrc.old
else
echo -e "\nOld dotfiles will be overwritten."
fi
printf "source '$HOME/dotfiles/zsh/zshrc_manager.sh'" > ~/.zshrc
printf "source '$HOME/dotfiles/profile.sh'" > ~/.zprofile
ln -s ./tigrc ~/.tigrc
printf "so $HOME/dotfiles/vim/vimrc.vim" > ~/.vimrc
printf "source-file $HOME/dotfiles/tmux/tmux.conf" > ~/.tmux.conf
echo
echo "Logout or restart to get new configurations running. Enjoy!"