#!/usr/bin/bash # Detect fish shell and ask user to switch to bash (bash-only syntax) if [ -n "${FISH_VERSION:-}" ] || case "$SHELL" in *fish*) ;; *) false ;; esac; then echo "Warning: fish shell detected." echo "This script is written for bash and may have syntax issues under fish." echo "Please switch to bash first and re-run it, e.g.: bash $0" read -r -p "Press Enter to continue anyway, or Ctrl+C to cancel..." /dev/null && command -v git >/dev/null && command -v curl >/dev/null && command -v fzf >/dev/null; then if command -v pacman >/dev/null; then echo "pacman detected. Installing prerequisites" sudo pacman -S zsh git curl fzf --noconfirm fi if command -v apt >/dev/null; then echo "apt detected. Installing prerequisites" sudo apt install git curl zsh fzf -y fi fi zsh=$(which zsh) # Do not print commands set +x echo ' --------------- Oh-My-zsh Install --------------- ' # Print commands set -x # Disable exit on error set +eu rm -rf ~/.oh-my-zsh # Enable exit on error set -eu # Do not print commands set +x # Install oh-my-zsh without entering zsh CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended # Print commands set -x # Install Oh-My-Zsh plugins git clone https://github.com/zsh-users/zsh-history-substring-search.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions git clone https://github.com/z-shell/zsh-eza.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-eza git clone --depth 1 https://github.com/unixorn/fzf-zsh-plugin.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fzf-zsh-plugin git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting git clone --depth 1 https://github.com/marlonrichert/zsh-autocomplete.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autocomplete # Disable exit on error set +eu # Backup old config file if it exists cp ~/.zshrc ~/.zshrc{,.bak} -r # Enable exit on error set -eu # Download and replace config file curl -fsSL https://raw.githubusercontent.com/alvinlollo/Single-install-script/refs/heads/main/configs/.zshrc -o ~/.zshrc # Download generic fzf configuration curl -fsSL https://raw.githubusercontent.com/alvinlollo/Single-install-script/refs/heads/main/configs/.fzf.zsh -o ~/.fzf.zsh # Setup fzf mkdir -p ~/.fzf/shell touch ~/.fzf/shell/key-bindings.zsh # Do not print commands set +x # If this user's login shell is already "zsh", do not attempt to switch. if [ "$(basename -- "$SHELL")" = "zsh" ]; then echo "You already have zsh as the default shell" echo "Successfully installed zsh configuration" exit 0 # Exit as success fi if command -v chsh >/dev/null; then echo "chsh command does not exist." echo "Please change your shell manually" sleep 5 && exit 0 fi echo "Changing your shell to $zsh..." if ! echo "+ sudo -k chsh -s "$zsh" "$USER"" && sudo -k chsh -s "$zsh" "$USER"; then # -k forces password prompt echo "Next command may fail." echo "+ chsh -s \"$(which zsh)\" \"$USER\"" chsh -s "$(which zsh)" "$USER" # run chsh normally may fail fi # Check if the shell change was successful if [ $? -ne 0 ]; then echo "chsh command unsuccessful. Change your default shell manually:" echo "chsh -s \"$(which zsh)\" \"$USER\"" else export SHELL="$zsh" echo "Shell successfully changed to '$zsh'." fi echo "Successfully installed zsh"