-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·141 lines (119 loc) · 4.01 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
useroot=""
if [ "$(id -u)" -ne 0 ]; then
useroot="sudo"
fi
ZSH_CUSTOM=~/river-zsh-config
CPWD=`pwd`
sysinstall()
{
if ! which $1 >/dev/null 2>&1; then
echo "install $1 ..."
if which brew >/dev/null 2>&1; then
brew install $1
fi
if which apt >/dev/null 2>&1; then
$useroot apt install $1
fi
if which pacman >/dev/null 2>&1; then
$useroot pacman -S $1
fi
if which dnf >/dev/null 2>&1; then
$useroot dnf install $1
fi
if which yum >/dev/null 2>&1; then
$useroot yum -y install $1
fi
fi
}
sysinstall zsh
sysinstall git
sysinstall tmux
if which dnf >/dev/null 2>&1; then
$useroot dnf install util-linux-user # which provides chsh
fi
# install sed on mac
if which brew >/dev/null 2>&1; then
if ! which gsed >/dev/null 2>&1; then
echo "install gnu-sed..."
brew install gnu-sed
alias sed=gsed
else
echo "use gnu-sed"
alias sed=gsed
fi
fi
# install oh-my-zsh
if [ ! -d ~/.oh-my-zsh ]; then
echo "install oh-my-zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
fi
# git clone this project;
if [ ! -d $ZSH_CUSTOM ]; then
echo "clone $ZSH_CUSTOM ..."
git clone https://github.com/revir/river-zsh-config.git $ZSH_CUSTOM || {
printf "Error: git clone river-zsh-config failed."
exit 1
}
else
cd $ZSH_CUSTOM
git pull
cd $CPWD
fi
# install zsh-syntax-highlighting
if [ ! -d ${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting ]; then
echo "clone zsh-syntax-highlighting..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting
fi
# install zsh-autosuggestions
if [ ! -d ${ZSH_CUSTOM}/plugins/zsh-autosuggestions ]; then
echo "clone zsh-autosuggestions..."
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM}/plugins/zsh-autosuggestions
fi
# change .zshrc theme
if ! grep 'ZSH_THEME="river"' ~/.zshrc >/dev/null 2>&1; then
# setup .zshrc
if which sed >/dev/null 2>&1; then
# backup .zshrc
cp ~/.zshrc ~/.zshrc.bak
echo "setup ~/.zshrc, use my ZSH_CUSTOM and ZSH_THEME ..."
code="ZSH_CUSTOM=\"$ZSH_CUSTOM\""
sed -i "/ZSH_THEME=\"robbyrussell\"/i $code" ~/.zshrc
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="river"/' ~/.zshrc
echo "NOTICE: edited ~/.zshrc, remember to run source ~/.zshrc by yourself!"
else
echo "WARN: you dont have sed, can't setup .zshrc, you should setup it by yourself!"
fi
fi
# change .zshrc plugins
if ! grep 'zsh-syntax-highlighting' ~/.zshrc >/dev/null 2>&1; then
# setup .zshrc
if which sed >/dev/null 2>&1; then
echo "setup zshrc plugins, use python node nvm z extract kubectl zsh-syntax-highlighting zsh-autosuggestions ..."
# deprecated, ohmyzsh used to be like that.
# # clever way to sed multiple lines: https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string
# # and don't cat & write to the same file at the same time!!!
# cat ~/.zshrc | tr '\n' '\r' | sed -e 's/\rplugins=(\r /\rplugins=(\r python node nvm z extract kubectl zsh-syntax-highlighting zsh-autosuggestions /' | tr '\r' '\n' > ~/.zshrc.tmp
# mv ~/.zshrc.tmp ~/.zshrc
sed -i 's/plugins=(git)/plugins=(common-aliases git python node nvm npm z extract kubectl zsh-syntax-highlighting zsh-autosuggestions tmux)/' ~/.zshrc
echo "NOTICE: edited ~/.zshrc, remember to run source ~/.zshrc by yourself!"
else
echo "WARN you dont have sed, can't setup .zshrc, you should setup it by yourself!"
fi
fi
# 加入home end,以及小键盘的支持
if ! grep ':key-binds-for-home-end-and-others' ~/.zshrc >/dev/null 2>&1; then
echo "Add some key-binds for home, end and other keys."
cat ${ZSH_CUSTOM}/key-binds.sh >> ~/.zshrc
fi
if [ ! -f $HOME/.vimrc ]; then
cp ${ZSH_CUSTOM}/.vimrc ~/
echo "Add .vimrc for home."
fi
# change soft limits on MacOS
if which brew >/dev/null 2>&1; then
if ! grep "MacOS Soft rlimits too low" ~/.zshrc >/dev/null 2>&1; then
echo "Change soft rlimits."
echo "# MacOS Soft rlimits too low. Number of files is 256, should be at least 1000" >> ~/.zshrc
echo "ulimit -n 4096" >> ~/.zshrc
fi
fi