Skip to content

Instantly share code, notes, and snippets.

@axhello
Last active December 9, 2019 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axhello/4a1f977cadddde41e6341f060ecf1e08 to your computer and use it in GitHub Desktop.
Save axhello/4a1f977cadddde41e6341f060ecf1e08 to your computer and use it in GitHub Desktop.
zsh安装
#!/bin/bash
# usage:
# curl -fsSL https://gist.githubusercontent.com/axhello/4a1f977cadddde41e6341f060ecf1e08/raw/ -o zsh.sh && sudo bash zsh.sh
install_zsh(){
echo "[!] ENTER exit manually!"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
}
install_zsh_plugins(){
# install zsh-autosuggestions
if [ ! -d "~/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
else
echo "zsh-autosuggestions existed..."
fi
# install zsh-syntax-highlighting
if [ ! -d "~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
else
echo "[*] ~/.zsh/zsh-syntax-highlighting exists...."
fi
}
config_change_default_shell(){
# change zsh to default shell
sudo chsh -s /bin/zsh
}
get_dist_name() {
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
DISTRO='CentOS'
PM='yum'
elif grep -Eqi "Red Hat Enterprise Linux Server" /etc/issue || grep -Eq "Red Hat Enterprise Linux Server" /etc/*-release; then
DISTRO='RHEL'
PM='yum'
elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; then
DISTRO='Aliyun'
PM='yum'
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
DISTRO='Fedora'
PM='yum'
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
DISTRO='Debian'
PM='apt'
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
DISTRO='Ubuntu'
PM='apt'
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
DISTRO='Raspbian'
PM='apt'
else
DISTRO='unknow'
fi
}
install_config() {
get_dist_name
# install zsh
if [ "${PM}" = "yum" ]; then
sudo yum update -y
sudo yum install git zsh vim autojump-zsh -y
elif [ "${PM}" = "apt" ]; then
sudo apt-get update -y
sudo apt-get install git zsh vim autojump -y
fi
# install oh-my-zsh
if [ ! -d "~/.zshrc" ]; then
install_zsh
fi
install_zsh_plugins
echo "[!] plugins=(git autojump zsh-autosuggestions zsh-syntax-highlighting)"
echo "[!] need to add plugin in ~/.zshrc and logoff manually!"
}
install_config
config_change_default_shell
uninstall() {
if [ "${PM}" = "yum" ]; then
yum remove zsh autojump-zsh -y
elif [ "${PM}" = "apt" ]; then
apt-get remove --purge zsh autojump -y
apt-get autoremove -y
fi
rm -rf ~/.oh-my-zsh
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment