-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·167 lines (149 loc) · 4.99 KB
/
setup
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
#!/usr/bin/env bash
# yadrlite
# Optimized Dotfiles
# # # # # # # # # # # # # # #
# # Options
# # # # # # # # # # # # # # #
USEREPO=yes
dir=~/.yadrlite
dotfiles_old=backup
action="${1:-install}"
declare -a files=('vim vimrc tmux.conf profile bash_profile bashrc vimrc.after emacs emacs.d')
declare -a tmuxplugins=('https://github.com/tmux-plugins/tmux-resurrect.git')
# # Routines
# # # # # # # # # # # # # # #
function installed {
local inststatus=yes
if [[ $($1 2>&1) =~ (not found) ]]; then
local inststatus=no
fi
echo "$inststatus"
}
function update {
local dirs=$1
cd $dirs
local plugindirs=(*/)
for pdir in "${plugindirs[@]}"; do
cd $dirs/$pdir
echo "Updating $pdir..."
if [ -d ".git" ]; then
git pull --rebase
fi
done
}
# # Remove
# # # # # # # # # # # # # # #
if [ "$action" == "remove" ]; then
echo "# # Removing Dotfiles and Restoring Settings"
echo "# # # # # # # # # # # # # # # # # # # # # #"
for cfile in ${files[@]}; do
rm -rf ~/.$cfile 2>/dev/null
mv $dir/$dotfiles_old/.$cfile ~/ 2>/dev/null
done
rm -rf $dir 2>/dev/null
echo ""
echo "Your original dotfiles have been restored. Please restart"
echo "the terminal or re-login to supress error messages."
echo ""
fi
# # Update
# # # # # # # # # # # # # # #
if [ "$action" == "update" ]; then
echo "# # Updating Dotfiles"
echo "# # # # # # # # # # # # # # # # # # # # # #"
if [ ! -f $dir/setup ]; then
action=install
else
cd $dir
git pull --rebase
update $dir/tmux/plugin
echo "The update is finished."
fi
fi
# # Install
# # # # # # # # # # # # # # #
if [ "$action" == "install" ]; then
echo "# # Installing Dotfiles"
echo "# # # # # # # # # # # # # # # # # # # # # #"
if [ -f $dir/setup ]; then
echo ""
echo "YADRLite is already installed."
exit
fi
if ! [ -x "$(command -v git)" ]; then
echo ""
echo "'Git' doesn't seem to be installed. Install it. :)"
exit
fi
if [ "$USEREPO" == "yes" ]; then
git clone https://github.com/bridgesense/dotfiles.git $dir
else
if [ ! -f setup ]; then
git clone https://github.com/bridgesense/dotfiles.git $dir
else
cp -R . $dir
fi
fi
echo "# # Backing up current configurations"
echo "# # # # # # # # # # # # # # # # # # # # # #"
cd $dir
cat ~/.bashrc > $dir/bashrc 2>/dev/null
cat ~/.bash_profile > $dir/bash_profile 2>/dev/null
mkdir -p $dotfiles_old 2>/dev/null
for cfile in ${files[@]}; do
mv ~/.$cfile $dir/$dotfiles_old/ 2>/dev/null
done
echo "# # Vim, Emacs and Tmux Configurations"
echo "# # # # # # # # # # # # # # # # # # # # # #"
cat $dir/vim/vimrc >> $dir/vimrc 2>/dev/null
cat $dir/vim/vimrc.after >> $dir/vimrc.after 2>/dev/null
cp $dir/emacs.d/emacs.init $dir/emacs
mkdir -p $dir/emacs.d/.extension
unzip $dir/workstation/extension/xdebug-vscode-plugin.zip -d $dir/emacs.d/.extension
sed -i "s@multi-term-program.*@multi-term-program \"$(which bash)\")@" $dir/emacs 2>/dev/null
cat $dir/tmux/tmux.conf > $dir/tmux.conf
echo "set-option -g default-shell \$SHELL" >> $dir/tmux.conf
if [[ "$(uname)" == "Linux" || "$(uname)" == "FreeBSD" ]]; then
echo "Gnu/Linux detected..."
echo '# tmux status options'>> $dir/tmux.conf
echo "run-shell $dir/tmux/airline-hybrid-patched.tmux">> $dir/tmux.conf
else
rm -rf $dir
echo "Please look into Linux. Your OS isn't supported yet."
exit
fi
echo "# # Loading plugins"
echo "# # # # # # # # # # # # # # # # # # # # # #"
mkdir $dir/tmux/plugin 2>/dev/null
cd $dir/tmux/plugin
for tplug in "${tmuxplugins[@]}"; do
echo "git clone $tplug"
git clone $tplug
done
# covers injection into most existing configurations
if ! grep -q "~/.bashrc" $dir/bash_profile && ! grep -q "~/.bash_profile" $dir/bashrc; then
cat $dir/bash/bashrc >> $dir/bashrc 2>/dev/null
echo "source ~/.bashrc" >> $dir/bash_profile 2>/dev/null
elif ! grep -q "~/.bashrc" $dir/bash_profile; then
cat $dir/bash/bashrc >> $dir/bash_profile 2>/dev/null
else
cat $dir/bash/bashrc >> $dir/bashrc 2>/dev/null
fi
# fixes sourcing of bashrc within tmux
sed -i "s@.*\..*/etc/bashrc@ source /etc/bashrc@g" $dir/bashrc
sed -i "s@.*\..*~\.bashrc@ source ~/.bashrc@g" $dir/bash_profile
echo "# # Building Symbolic Links"
echo "# # # # # # # # # # # # # # # # # # # # # #"
cd $dir
mkdir -p $dotfiles_old 2>/dev/null
for cfile in ${files[@]}; do
ln -s $dir/$cfile ~/.$cfile
done
echo ""
echo "This script does not install ack, emacs, silversearcher, tmux or"
echo "Vim with Lua support. That's something you might look into."
echo ""
echo "The dotfiles are installed. Restart the terminal or re-login to"
echo "remote deployment to see changes."
echo ""
fi