Skip to content

Instantly share code, notes, and snippets.

@Adrian-2105
Last active February 8, 2025 19:28
Show Gist options
  • Save Adrian-2105/bb66b9d5bab0c90de2c9d68f7b4c5db0 to your computer and use it in GitHub Desktop.
Save Adrian-2105/bb66b9d5bab0c90de2c9d68f7b4c5db0 to your computer and use it in GitHub Desktop.
Script to auto-install my ZSH basic settings
#!/bin/bash
ZSH_CONFIG=~/.zshrc
PLUGINS=~/.local/zsh_plugins
if [[ $EUID -eq 0 ]]; then
echo "This script must not be executed using sudo directly. Exiting..."
exit 1
fi
echo "This configuration has been set in Kubuntu 20.04"
echo "During the installation process you will be asked to interact in some moments"
echo "Also, if in some moment a ZSH is opened, just close it using: exit"
echo
echo "This script MUST be run with the next command to completely install ZSH for your current user:"
echo " bash install_terminal_plugins.sh"
echo
read -p "Do you want to continue? [Press enter or abort with Ctrl+C]" user_input
########################################
# Prerequisites #
########################################
sudo apt-get update
sudo apt-get install -y curl unzip git
########################################
# ZSH Installation & Configuration #
########################################
echo "Installing ZSH"
sudo apt-get install -y zsh fonts-powerline || exit 1
echo
echo "ZSH will now be open for the first time."
echo "Mark the option (0) to just configure ~/.zshrc file and exit"
read -p "[Press enter to continue]" user_input
zsh -c "autoload -Uz zsh-newuser-install && zsh-newuser-install -f" || exit 1
echo
echo "Load same variables as /bin/bash in ZSH to avoid conflicts"
echo "emulate sh -c 'source /etc/profile'" | sudo tee -a /etc/zsh/zprofile >/dev/null || exit 1
echo
echo "Adding custom keybindings to remove complete words with Ctrl + Backspace/Delete"
echo "# CUSTOM KEYBINDING" >> $ZSH_CONFIG || exit 1
echo "bindkey '^H' backward-kill-word # Ctrl + Backspace" >> $ZSH_CONFIG || exit 1
echo "bindkey '5~' kill-word # Ctrl + Delete" >> $ZSH_CONFIG || exit 1
########################################
# ZSH Plugins & Oh My ZSH #
########################################
echo
echo "Installing Oh My ZSH (a plugin framework for ZSH)"
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" || exit 1
echo
echo "Installing Oh My ZSH plugins (now starts the good part)"
echo
echo "Installing theme powerlevel10k (a really fancy theme :D)"
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k || exit 1
sed -i 's/ZSH_THEME="[^"]*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' $ZSH_CONFIG
echo
echo "Installing zsh-syntax-highlighting"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting || exit 1
sed -i "s/plugins=(\(.*\))/plugins=(\1 zsh-syntax-highlighting)/" $ZSH_CONFIG || exit 1
echo
echo "Installing zsh-autosuggestions"
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions || exit 1
sed -i "s/plugins=(\(.*\))/plugins=(\1 zsh-autosuggestions)/" $ZSH_CONFIG || exit 1
echo
echo "Configuring dirhistory"
sed -i "s/plugins=(\(.*\))/plugins=(\1 dirhistory)/" $ZSH_CONFIG || exit 1
########################################
# Setting extra plugins & Aliases #
########################################
echo
echo "Installing Micro (modern & simple terminal editor, using modern shortcuts)"
sudo apt-get install -y micro || exit 1
echo
echo "Installing batcat (bat: cat, but improved)"
sudo apt-get install -y bat || exit 1
echo
echo "Installing exa (ls improved)"
EXA_VERSION=$(curl -s "https://api.github.com/repos/ogham/exa/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+') || exit 1
curl -Lo exa.zip "https://github.com/ogham/exa/releases/latest/download/exa-linux-x86_64-v${EXA_VERSION}.zip" || exit 1
sudo unzip -q -o exa.zip bin/exa -d /usr/local || exit 1
rm -rf exa.zip
echo
echo "Installing diff-so-fancy (sustitute for classic 'git diff' view)"
git clone https://github.com/so-fancy/diff-so-fancy $PLUGINS/diff-so-fancy
echo "# Adding diff-so-fancy to the PATH" >> $ZSH_CONFIG
echo "export PATH=$PLUGINS/diff-so-fancy:$PATH" >> $ZSH_CONFIG
diff-so-fancy --set-defaults
echo
echo "Installing enhancd + fzf (improved 'cd' command')"
sudo apt-get install fzf
git clone https://github.com/babarot/enhancd $PLUGINS/enhancd
echo "# enhancd (fzf) configuration" >> $ZSH_CONFIG
echo "source $PLUGINS/enhancd/init.sh" >> $ZSH_CONFIG
echo "export ENHANCD_FILTER=\"fzf +x --delimiter / --with-nth -3.. --border rounded --tabstop 4 --height 40% --layout reverse --preview='exa --tree --group-directories-first --level 1 {}'\"" >> $ZSH_CONFIG
echo 'alias bat="batcat"' >> $ZSH_CONFIG || exit 1
echo 'alias ll="exa -lh"' >> $ZSH_CONFIG || exit 1
echo 'alias tree="exa -lh --tree"' >> $ZSH_CONFIG || exit 1
########################################
# End! #
########################################
echo
echo
echo "INSTALLATION FINISHED!!!"
echo
echo "Next time you open ZSH you will be prompted to configure your powerlevel10k theme"
echo "Just apply your preferred configuration :)"
echo
echo "It is recommended to restart your session to apply all the changes. If you find some problem,"
echo "disable again ZSH with: chsh -s /bin/bash"
echo
echo "New commands installed/improved:"
echo " - micro : modern terminal editor, using modern common keyboards shortcuts"
echo " - ll / tree : list files with improved presentation using EXA"
echo " - bat : improved cat command"
echo " - git diff : now it uses an improved diff viewer"
echo " - cd : now it uses an advanced file finder, check this repo for full documentation https://github.com/babarot/enhancd"
echo
echo "New shortcuts:"
echo " - RightArrow: autocomplete command"
echo " - Alt + UpArrow: move to the parent directory (as 'cd ..')"
echo " - Alt + LeftArrow / RightArrow: move back to the previous visited directory"
echo " - Alt + Down: move to the first child directory"
@Adrian-2105
Copy link
Author

Recommended font to use in order to maximize compatibility: MesloLGS Nerd Font

Install all of the fonts listed below:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment