Skip to content

Instantly share code, notes, and snippets.

@ashikMostofaTonmoy
Created March 28, 2024 05:48
Show Gist options
  • Save ashikMostofaTonmoy/50e5dd87912c893b320ce1d6b0525234 to your computer and use it in GitHub Desktop.
Save ashikMostofaTonmoy/50e5dd87912c893b320ce1d6b0525234 to your computer and use it in GitHub Desktop.
This script works for debina and redhat based systems only. The following script does: 1. install essential tools (git and curl) 2. install zsh 3. changes shell 4. install "oh my zsh" 5. install plugins 6. sets zsh theme and enable_plugins
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
# Function to detect the Linux distribution
detect_distribution() {
if [ -f /etc/os-release ]; then
# Source the os-release file to get the distribution ID
. /etc/os-release
if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
echo "ubuntu"
elif [ "$ID" = "centos" ] || [ "$ID" = "rhel" ] || [ "$ID" = "fedora" ]; then
echo "centos"
else
echo "Unsupported distribution: $ID"
exit 1
fi
else
echo "Unsupported distribution"
exit 1
fi
}
# Install essential tools
install_essential_tools() {
distribution=$(detect_distribution)
case "$distribution" in
ubuntu)
sudo apt-get update
sudo apt-get install -y curl git
;;
centos)
sudo yum install -y curl git
;;
*)
echo "Unsupported distribution: $distribution"
exit 1
;;
esac
}
# Install Zsh based on the detected distribution
install_zsh() {
distribution=$(detect_distribution)
case "$distribution" in
ubuntu)
sudo apt-get update
sudo apt-get install -y zsh
;;
centos)
sudo yum install -y zsh
;;
*)
echo "Unsupported distribution: $distribution"
exit 1
;;
esac
}
# Change the default shell to Zsh
change_shell() {
# sudo chsh -s "$(which zsh)" "$USER"
chsh -s "$(which zsh)"
}
# Install Oh-My-Zsh
install_oh_my_zsh() {
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" < /dev/null
}
# Install additional plugins
install_plugins() {
mkdir -p $HOME/.oh-my-zsh/custom/plugins
# Autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions.git $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions
# Syntax highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
# Fast syntax highlighting
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git $HOME/.oh-my-zsh/custom/plugins/fast-syntax-highlighting
# Autocomplete
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $HOME/.oh-my-zsh/custom/plugins/zsh-autocomplete
}
# Set Zsh theme
set_zsh_theme() {
sed -i 's/ZSH_THEME=".*"/ZSH_THEME="jonathan"/' $HOME/.zshrc
}
# Enable plugins in .zshrc
enable_plugins() {
sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)/' $HOME/.zshrc
}
# Main script
install_essential_tools
install_zsh
change_shell
install_oh_my_zsh
install_plugins
set_zsh_theme
enable_plugins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment