Last active
September 17, 2024 06:01
-
-
Save theprantadutta/68aed92bbdbc9e312c853885910e5196 to your computer and use it in GitHub Desktop.
A bash script that installs Zsh, Oh My Zsh, Powerlevel10k theme, and Zsh Autosuggestions with comments and colorful echo statements for Ubuntu. To directly install this, first run ```curl -O https://gist.githubusercontent.com/theprantadutta/68aed92bbdbc9e312c853885910e5196/raw/install-zsh.sh && chmod +x install-zsh.sh && ./install-zsh.sh```.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Colors for echo statements | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
# Step 0: Check if the script is being run with sudo privileges | |
if [ "$(id -u)" -ne 0 ]; then | |
echo -e "${RED}This script requires sudo privileges. Please run it with 'sudo' or as root.${NC}" | |
exit 1 | |
fi | |
echo -e "${GREEN}Starting the installation of Zsh, Oh My Zsh, Powerlevel10k, and Zsh Autosuggestions...${NC}" | |
# Step 1: Install Zsh | |
echo -e "${YELLOW}Installing Zsh...${NC}" | |
sudo apt update && sudo apt install -y zsh | |
echo -e "${GREEN}Zsh installation completed!${NC}" | |
# Step 2: Set Zsh as the default shell | |
echo -e "${YELLOW}Setting Zsh as the default shell...${NC}" | |
chsh -s $(which zsh) | |
echo -e "${GREEN}Zsh has been set as the default shell!${NC}" | |
# Start a new Zsh session to run the rest of the commands | |
echo -e "${YELLOW}Switching to Zsh for the remaining setup...${NC}" | |
zsh <<'EOF' | |
# Step 3: Install Oh My Zsh | |
echo -e "${YELLOW}Installing Oh My Zsh...${NC}" | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
echo -e "${GREEN}Oh My Zsh installed successfully!${NC}" | |
# Step 4: Install Powerlevel10k theme | |
echo -e "${YELLOW}Installing Powerlevel10k theme...${NC}" | |
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k | |
echo -e "${GREEN}Powerlevel10k theme installed!${NC}" | |
# Step 5: Set Powerlevel10k as the default theme | |
echo -e "${YELLOW}Setting Powerlevel10k as the default theme in ~/.zshrc...${NC}" | |
if grep -q "ZSH_THEME=" ~/.zshrc; then | |
# If ZSH_THEME exists, replace it | |
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc | |
else | |
# If ZSH_THEME does not exist, append it | |
echo 'ZSH_THEME="powerlevel10k/powerlevel10k"' >> ~/.zshrc | |
fi | |
echo -e "${GREEN}Powerlevel10k theme is now set as the default theme!${NC}" | |
# Step 6: Install Zsh Autosuggestions plugin | |
echo -e "${YELLOW}Installing Zsh Autosuggestions plugin...${NC}" | |
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions | |
echo -e "${GREEN}Zsh Autosuggestions plugin installed!${NC}" | |
# Step 7: Add Zsh Autosuggestions to the plugins list in ~/.zshrc | |
echo -e "${YELLOW}Adding Zsh Autosuggestions to the plugins list...${NC}" | |
if grep -q "plugins=(" ~/.zshrc; then | |
# Add zsh-autosuggestions to the existing plugins list | |
sed -i 's/plugins=(/plugins=(zsh-autosuggestions /' ~/.zshrc | |
else | |
# If no plugins list is found, add it | |
echo 'plugins=(git zsh-autosuggestions)' >> ~/.zshrc | |
fi | |
echo -e "${GREEN}Zsh Autosuggestions added to the plugins list!${NC}" | |
# Step 8: Apply changes | |
echo -e "${YELLOW}Applying the changes by reloading ~/.zshrc...${NC}" | |
source ~/.zshrc | |
echo -e "${GREEN}All done! Zsh with Powerlevel10k and Zsh Autosuggestions is now configured!${NC}" | |
# End of Zsh commands | |
EOF | |
echo -e "${YELLOW}Please restart your terminal to fully apply the changes.${NC}" | |
zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment