#!/bin/bash # Function to check if a command is available command_exists() { command -v "$1" 2>&1 >/dev/null } # Function to install dependencies based on the package manager install_dependencies() { case $PACKAGE_MANAGER in "brew") $PACKAGE_MANAGER install "$@" ;; "apt-get") sudo $PACKAGE_MANAGER install -y "$@" ;; "yum") sudo $PACKAGE_MANAGER install -y "$@" ;; esac } # Default values for flags ENABLE_AUTO_UPDATE=true ENABLE_NOTIFICATION=true PACKAGE_MANAGER="" # Parse command-line arguments while [[ "$#" -gt 0 ]]; do case $1 in -a|--disable-auto-update) ENABLE_AUTO_UPDATE=false; shift ;; -n|--disable-notification) ENABLE_NOTIFICATION=false; shift ;; *) echo "Unknown parameter passed: $1"; exit 1 ;; esac done # Check if running on macOS or Linux if [ "$(uname)" == "Darwin" ]; then # Check if Homebrew is not installed if ! command_exists brew; then echo "Homebrew is not installed. Installing Homebrew..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" PACKAGE_MANAGER="brew" fi elif [ "$(uname)" == "Linux" ]; then # Check if on Linux and use the appropriate package manager if command_exists apt-get; then PACKAGE_MANAGER="apt-get" elif command_exists yum; then PACKAGE_MANAGER="yum" else echo "Unsupported package manager. Exiting." exit 1 fi fi # Clone or initialize dotfiles repository DOTFILES_DIR="$HOME/.dotfiles" if [ -d "$DOTFILES_DIR" ]; then if [ -d "$DOTFILES_DIR/.git" ]; then echo "Updating existing dotfiles repository..." (cd "$DOTFILES_DIR" && git pull origin master) else git -C "$DOTFILES_DIR" init git -C "$DOTFILES_DIR" clone https://github.com/jfraeys/.dotfiles.git "$DOTFILES_DIR" fi else echo "Creating dotfiles directory..." mkdir -p "$DOTFILES_DIR" git -C "$DOTFILES_DIR" init git -C "$DOTFILES_DIR" clone https://github.com/jfraeys/.dotfiles.git "$DOTFILES_DIR" fi # Check and install git and other tools if ! command_exists git; then install_dependencies git fd ripgrep fzf tree fi # Check and install zsh if ! command_exists zsh; then install_dependencies zsh # Clone Oh-My-Zsh if not already present if [ ! -d "$HOME/.oh-my-zsh" ]; then git clone https://github.com/ohmyzsh/ohmyzsh.git "$HOME/.oh-my-zsh" fi # Set Zsh as the default shell chsh -s "$(command -v zsh)" fi # Check and install tmux if ! command_exists tmux; then install_dependencies tmux fi # Install Go case $PACKAGE_MANAGER in "brew") $PACKAGE_MANAGER install go ;; "apt-get") sudo $PACKAGE_MANAGER install -y golang ;; "yum") sudo $PACKAGE_MANAGER install -y golang ;; esac # Install Python and pip case $PACKAGE_MANAGER in "brew") $PACKAGE_MANAGER install python ;; "apt-get") sudo $PACKAGE_MANAGER install -y python3 python3-pip ;; "yum") sudo $PACKAGE_MANAGER install -y python3 python3-pip ;; esac # Install some common linters (uncomment if needed) # case $PACKAGE_MANAGER in # "brew") # $PACKAGE_MANAGER install shellcheck # ;; # "apt-get") # sudo $PACKAGE_MANAGER install -y shellcheck # ;; # "yum") # sudo $PACKAGE_MANAGER install -y shellcheck # ;; # esac # Create symbolic links for dotfiles ln -s "$DOTFILES_DIR/zsh/.zshrc" ~/.zshrc ln -s "$DOTFILES_DIR/tmux/.tmux.conf" ~/.tmux.conf ln -s "$DOTFILES_DIR/nvim" ~/.config/nvim # Source configurations for the current session source ~/.zshrc tmux source ~/.tmux.conf # Inform the user and wait for input echo "Zsh, Tmux, Neovim, Go, and development tools configurations applied." # Enable Brew auto-update if the flag is set if [ "$ENABLE_AUTO_UPDATE" == true ]; then brew autoupdate --start --upgrade --cleanup fi # Enable notifications if the flag is set if [ "$ENABLE_NOTIFICATION" == true ]; then echo "Press Enter to start Zsh and Tmux." read -r else echo "Notifications are disabled. Press Enter to continue." read -r fi # Start Zsh and Tmux zsh