diff --git a/main.sh b/main.sh index b73504f..2807cb2 100755 --- a/main.sh +++ b/main.sh @@ -1,130 +1,273 @@ #!/bin/bash +# Get the script directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + # add a function to the script: prompt_for_multiselect -source ./prompt_for_multiselect.sh +source "${SCRIPT_DIR}/prompt_for_multiselect.sh" + +# Color definitions for better CLI experience +if [[ -t 1 ]]; then + RED='\033[0;31m' + GREEN='\033[0;32m' + YELLOW='\033[1;33m' + BLUE='\033[0;34m' + MAGENTA='\033[0;35m' + CYAN='\033[0;36m' + BOLD='\033[1m' + NC='\033[0m' # No Color +else + RED='' + GREEN='' + YELLOW='' + BLUE='' + MAGENTA='' + CYAN='' + BOLD='' + NC='' +fi + +# Helper functions for better CLI output +print_header() { + echo "" + echo -e "${BOLD}${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BOLD}${CYAN}$1${NC}" + echo -e "${BOLD}${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo "" +} + +print_step() { + echo -e "${BOLD}${MAGENTA}► Step ${step}/${numberStep}:${NC} ${BOLD}$1${NC}" +} + +print_success() { + echo -e "${GREEN}✓${NC} $1" +} + +print_info() { + echo -e "${BLUE}ℹ${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}⚠${NC} $1" +} + +print_error() { + echo -e "${RED}✗${NC} $1" +} + +print_section() { + echo "" + echo -e "${CYAN}▸ $1${NC}" +} + +# Show usage information +show_usage() { + cat << EOF +${BOLD}Dotfiles Setup Script${NC} +${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC} + +This script will help you set up your development environment with: + • Brew - Package manager for macOS + • Git - Version control system + • Zsh - Shell with Oh My Zsh framework + • ASDF - Runtime version manager + • Neovim - Text editor + • Various development tools and applications + +${BOLD}Usage:${NC} + ./main.sh [OPTIONS] + +${BOLD}Options:${NC} + -h, --help Show this help message + -y, --yes Skip interactive selection (install recommended defaults) + +${BOLD}Interactive Mode:${NC} + Without options, you'll see an interactive menu to select what to install. + Use arrow keys to navigate, space to select/deselect, enter to confirm. + +EOF +} + +# Parse command line arguments +SKIP_INTERACTIVE=false +while [[ $# -gt 0 ]]; do + case $1 in + -h|--help) + show_usage + exit 0 + ;; + -y|--yes) + SKIP_INTERACTIVE=true + shift + ;; + *) + echo -e "${RED}Unknown option: $1${NC}" + show_usage + exit 1 + ;; + esac +done # echo "############################################################################" # echo "#### INIT STEP COUNTER" -let numberStep=0 # will be defined by result of prompt_for_multiselect -let step=0 +((numberStep=0)) # will be defined by result of prompt_for_multiselect +((step=0)) # echo "############################################################################" export DOTFILE_PATH=${PWD} +# Track installed components for summary +declare -a INSTALLED_COMPONENTS=() +declare -a SKIPPED_COMPONENTS=() +declare -a FAILED_COMPONENTS=() + installBrew() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Brew" - echo "############################################################################" + print_header "Install Brew" + print_step "Installing Homebrew package manager" + # if brew is not installed install it else skip if ! command -v brew &> /dev/null; then - echo "Installing Brew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + print_info "Installing Brew..." + if /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; then + print_success "Brew installed successfully" + INSTALLED_COMPONENTS+=("Brew") + else + print_error "Failed to install Brew" + FAILED_COMPONENTS+=("Brew") + return 1 + fi else - echo "Brew detected. install skipped" + print_warning "Brew already installed, skipping" + SKIPPED_COMPONENTS+=("Brew") fi } installGit() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install git" - echo "############################################################################" - brew install git - read -p "What is your username? " USERNAME; - echo ""; - git config --global user.name $USERNAME - read -p "What is your email? " EMAIL; - echo ""; - git config --global user.email $EMAIL + print_header "Install Git" + print_step "Installing Git version control system" + + if brew install git; then + print_success "Git installed successfully" + echo "" + # Use printf for more reliable color output + printf "%b" "${CYAN}What is your Git username?${NC} " + read -r USERNAME + echo ""; + git config --global user.name "$USERNAME" + printf "%b" "${CYAN}What is your Git email?${NC} " + read -r EMAIL + echo ""; + git config --global user.email "$EMAIL" + print_success "Git configured with username: $USERNAME and email: $EMAIL" + INSTALLED_COMPONENTS+=("Git") + else + print_error "Failed to install Git" + FAILED_COMPONENTS+=("Git") + return 1 + fi } installZsh() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install ZSH" - echo "############################################################################" - echo "############################################################################" - echo "#### Clean Existing ZSH " - echo "############################################################################" + print_header "Install ZSH & Oh My Zsh" + print_step "Installing Zsh shell with Oh My Zsh framework" + + print_section "Cleaning existing ZSH installation" # clean zsh theme cache - echo "-- Clean zsh theme cache" - rm -f $HOME/.cache/p10k-instant-prompt-* + print_info "Cleaning zsh theme cache" + rm -f "$HOME"/.cache/p10k-instant-prompt-* # clean oh-my-zsh - echo "-- Clean oh-my-zsh" - [ -d ${HOME}/.oh-my-zsh ] && rm -Rf ${HOME}/.oh-my-zsh + print_info "Cleaning oh-my-zsh" + [ -d "${HOME}/.oh-my-zsh" ] && rm -Rf "${HOME}/.oh-my-zsh" # clean zsh config # echo "-- Clean zsh config" # [ -f ${HOME}/.custom.zsh ] && rm ${HOME}/.custom.zsh - echo "############################################################################" - echo "#### Install ZSH" - echo "############################################################################" + print_section "Installing ZSH" if [ "$(uname)" == "Darwin" ]; then if brew list zsh &>/dev/null; then brew reinstall zsh else brew install zsh fi - elif [ "$(expr substr $(uname) 1 5)" == "Linux" ]; then + elif [[ "$(uname)" == Linux* ]]; then sudo apt-get install -y zsh fi + print_success "Zsh installed" # save script path (supposing we run it from the dotfiles root) - echo "export DOTFILE_PATH=\"${PWD}\"" > ${HOME}/.dotfiles-config-path.zsh + echo "export DOTFILE_PATH=\"${PWD}\"" > "${HOME}/.dotfiles-config-path.zsh" # if link to custom.zsh is not there create it - [ ! -f ${HOME}/.custom.zsh ] && cp ${PWD}/zsh/custom.zsh ${HOME}/.custom.zsh - - echo "############################################################################" - echo "#### Install Oh My Zsh" - echo "############################################################################" - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended - - echo "############################################################################" - echo "#### Create link to zsh config" - echo "############################################################################" - [ -f ${HOME}/.zshrc ] && rm ${HOME}/.zshrc - ln -s ${PWD}/zsh/zshrc ${HOME}/.zshrc - [ -f ${HOME}/.zlogin ] && rm ${HOME}/.zlogin - ln -s ${PWD}/zsh/zlogin ${HOME}/.zlogin - - echo "############################################################################" - echo "### Install Plugins for Zsh" - echo "############################################################################" - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting - git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/zsh-autosuggestions + [ ! -f "${HOME}/.custom.zsh" ] && cp "${PWD}/zsh/custom.zsh" "${HOME}/.custom.zsh" + + print_section "Installing Oh My Zsh" + if sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended; then + print_success "Oh My Zsh installed" + else + print_warning "Oh My Zsh installation encountered an issue" + fi + + print_section "Creating symbolic links to zsh config" + [ -f "${HOME}/.zshrc" ] && rm "${HOME}/.zshrc" + ln -s "${PWD}/zsh/zshrc" "${HOME}/.zshrc" + [ -f "${HOME}/.zlogin" ] && rm "${HOME}/.zlogin" + ln -s "${PWD}/zsh/zlogin" "${HOME}/.zlogin" + print_success "Config files linked" + + print_section "Installing Zsh plugins" + [ ! -d "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" ] && \ + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" && \ + print_success "Installed zsh-syntax-highlighting" + [ ! -d "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" ] && \ + git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" && \ + print_success "Installed zsh-autosuggestions" if [ "$(uname)" == "Darwin" ]; then brew install coreutils fi - git clone https://github.com/supercrabtree/k ${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/k + [ ! -d "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/k" ] && \ + git clone https://github.com/supercrabtree/k "${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/plugins/k" && \ + print_success "Installed k plugin" - echo "############################################################################" - echo "### Install Theme PowerLevel10k for Zsh" - echo "############################################################################" - git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k + print_section "Installing PowerLevel10k theme" + [ ! -d "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" ] && \ + git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" && \ + print_success "PowerLevel10k theme installed" - echo "############################################################################" - echo "#### Install Nerd Font" - echo "############################################################################" + print_section "Installing Nerd Font" if [ "$(uname)" == "Darwin" ]; then - cd ${HOME}/Library/Fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/DroidSansMono/DroidSansMNerdFontMono-Regular.otf - elif [ "$(expr substr $(uname) 1 5)" == "Linux" ]; then - [ ! -d ${HOME}/.local/share/fonts ] && mkdir -p ${HOME}/.local/share/fonts - cd ${HOME}/.local/share/fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/DroidSansMono/DroidSansMNerdFontMono-Regular.otf + if (cd "${HOME}/Library/Fonts" && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/DroidSansMono/DroidSansMNerdFontMono-Regular.otf); then + print_success "Nerd Font installed" + else + print_warning "Nerd Font installation failed" + fi + elif [[ "$(uname)" == Linux* ]]; then + [ ! -d "${HOME}/.local/share/fonts" ] && mkdir -p "${HOME}/.local/share/fonts" + if (cd "${HOME}/.local/share/fonts" && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/DroidSansMono/DroidSansMNerdFontMono-Regular.otf); then + print_success "Nerd Font installed" + else + print_warning "Nerd Font installation failed" + fi fi + + INSTALLED_COMPONENTS+=("Zsh + Oh My Zsh") } installAsdf() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Clean Existing ASDF" - echo "############################################################################" + print_header "Install ASDF" + print_step "Installing ASDF version manager" + + print_section "Installing ASDF" if brew list asdf &>/dev/null; then brew reinstall asdf else brew install asdf fi + print_success "ASDF installed" # # Add node # if [ "$(uname)" == "Darwin" ]; then @@ -134,54 +277,59 @@ installAsdf() { # fi ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Add ASDF plugins" - echo "############################################################################" - zsh -c "asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git" - # zsh -c '${ASDF_DATA_DIR:=${DOTFILE_PATH}/Tools/asdf}/plugins/nodejs/bin/import-release-team-keyring' + print_section "Adding ASDF plugins" + + print_info "Adding nodejs plugin..." + zsh -c "asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git" || true zsh -c "asdf install nodejs latest" + print_success "Node.js installed" - zsh -c "asdf plugin add pnpm https://github.com/jonathanmorley/asdf-pnpm.git" + print_info "Adding pnpm plugin..." + zsh -c "asdf plugin add pnpm https://github.com/jonathanmorley/asdf-pnpm.git" || true zsh -c "asdf install pnpm latest" + print_success "pnpm installed" - # zsh -c "asdf plugin add yarn https://github.com/twuni/asdf-yarn.git" - # zsh -c "asdf install yarn latest" - # zsh -c "asdf global yarn latest" + print_info "Adding python plugin..." + zsh -c "asdf plugin add python" || true + print_success "Python plugin added" - zsh -c "asdf plugin add python" - - zsh -c "asdf plugin add java https://github.com/halcyon/asdf-java.git" - # if needed to change the version asdf list all java |grep adoptopenjdk-11 + print_info "Adding java plugin..." + zsh -c "asdf plugin add java https://github.com/halcyon/asdf-java.git" || true zsh -c "asdf install java adoptopenjdk-11.0.27+6" + print_success "Java installed" + + INSTALLED_COMPONENTS+=("ASDF + Node.js + pnpm + Java") } installSoftwarePro(){ ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Professional" - echo "############################################################################" + print_header "Install Professional Software" + print_step "Installing professional development applications" + + print_info "Installing applications via Homebrew..." brew install --cask visual-studio-code --appdir=/Applications/Developments brew install --cask iterm2 --appdir=/Applications/Developments brew install --cask sublime-text --appdir=/Applications/Developments brew install --cask docker --appdir=/Applications/Developments brew install --cask mylio --appdir=/Applications/Developments - # Tools brew install --cask rectangle --appdir=/Applications/Tools brew install --cask cakebrew --appdir=/Applications/Tools brew install --cask grandperspective --appdir=/Applications/Tools - # Other brew install --cask --no-quarantine spotify --appdir=/Applications/Others brew install --cask --no-quarantine vivaldi --appdir=/Applications/Others - # Communication brew install --cask --no-quarantine whatsapp --appdir=/Applications/Communications brew install --cask --no-quarantine discord --appdir=/Applications/Communications + + print_success "Professional software installed" + INSTALLED_COMPONENTS+=("Professional Software") } installSoftwareDevelopment(){ ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Developments" - echo "############################################################################" + print_header "Install Development Software" + print_step "Installing development applications" + + print_info "Installing development tools..." brew install --cask visual-studio-code --appdir=/Applications/Developments brew install --cask iterm2 --appdir=/Applications/Developments brew install --cask wave --appdir=/Applications/Developments @@ -190,62 +338,79 @@ installSoftwareDevelopment(){ brew install --cask notion --appdir=/Applications/Developments brew install --cask anki --appdir=/Applications/Developments brew install --cask mylio --appdir=/Applications/Developments + + print_success "Development software installed" + INSTALLED_COMPONENTS+=("Development Software") } installSofwareLLM(){ ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: LLMs" - echo "############################################################################" + print_header "Install LLM Software" + print_step "Installing Large Language Model tools" + + print_info "Installing LM Studio and Ollama..." brew install --cask lm-studio --appdir=/Applications/Developments brew install --cask ollama --appdir=/Applications/Developments brew install ollama + + print_info "Pulling Llama3 models..." ollama pull llama3:instruct ollama pull llama3:latest - + + print_success "LLM software installed" + INSTALLED_COMPONENTS+=("LLM Tools") } installSoftwareTools() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Tools" - echo "############################################################################" + print_header "Install Utility Tools" + print_step "Installing utility applications" + + print_info "Installing system tools..." brew install --cask rectangle --appdir=/Applications/Tools - # brew install --cask raycast --appdir=/Applications/Tools - brew install --cask oversight --appdir=/Applications/Tools #appdir not working - brew install --cask logi-options-plus --appdir=/Applications/Tools #appdir not working - # brew install --cask jdownloader --appdir=/Applications/Tools #appdir not working - ## brew install --cask battery --appdir=/Applications/Tools # replace by Aldente via setapp - brew install --cask background-music --appdir=/Applications/Tools #still maintained? yes in 2025 + brew install --cask oversight --appdir=/Applications/Tools + brew install --cask logi-options-plus --appdir=/Applications/Tools + brew install --cask background-music --appdir=/Applications/Tools brew install --cask grandperspective --appdir=/Applications/Tools brew install --cask pearcleaner --appdir=/Applications/Tools brew install --cask clop --appdir=/Applications/Tools + + print_success "Utility tools installed" + INSTALLED_COMPONENTS+=("Utility Tools") } installSoftwareCommunication() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Communication" - echo "############################################################################" + print_header "Install Communication Software" + print_step "Installing communication applications" + + print_info "Installing communication tools..." brew install --cask slack --appdir=/Applications/Communications brew install --cask whatsapp --appdir=/Applications/Communications brew install --cask discord --appdir=/Applications/Communications - #brew install --cask legcord --appdir=/Applications/Communications + + print_success "Communication software installed" + INSTALLED_COMPONENTS+=("Communication Software") } installSoftwareOffice() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Office" - echo "############################################################################" - brew install --cask microsoft-office --appdir=/Applications/Office #appdir not working + print_header "Install Office Software" + print_step "Installing Microsoft Office" + + print_info "Installing Microsoft Office..." + brew install --cask microsoft-office --appdir=/Applications/Office + + print_success "Office software installed" + INSTALLED_COMPONENTS+=("Office Software") } installSoftwareGames() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Games" - echo "############################################################################" + print_header "Install Gaming Software" + print_step "Installing gaming applications" + + print_info "Installing gaming platforms and tools..." brew install --cask --no-quarantine nvidia-geforce-now --appdir=/Applications/Games brew install --cask --no-quarantine epic-games --appdir=/Applications/Games brew install --cask --no-quarantine steam --appdir=/Applications/Games @@ -253,17 +418,19 @@ installSoftwareGames() { brew install --cask --no-quarantine scummvm --appdir=/Applications/Games brew install --cask obs --appdir=/Applications/Games brew install --cask --no-quarantine openemu --appdir=/Applications/Games - brew install --cask sony-ps-remote-play --appdir=/Applications/Games #appdir not working (move it manually) + brew install --cask sony-ps-remote-play --appdir=/Applications/Games brew install --cask moonlight --appdir=/Applications/Games - # brew install --cask whisky --appdir=/Applications/Games # deprecated or disabled - # brew install --cask chiaki --appdir=/Applications/Games # deprecated or disabled + + print_success "Gaming software installed" + INSTALLED_COMPONENTS+=("Gaming Software") } installSoftwareOthers() { ((step++)) - echo "############################################################################" - echo "#### ${step} / ${numberStep} - Install Software: Others" - echo "############################################################################" + print_header "Install Other Software" + print_step "Installing miscellaneous applications" + + print_info "Installing media and other applications..." brew install --cask --no-quarantine spotify --appdir=/Applications/Others brew install --cask calibre --appdir=/Applications/Others brew install --cask kindle-previewer --appdir=/Applications/Others @@ -271,18 +438,50 @@ installSoftwareOthers() { brew install --cask hakuneko --appdir=/Applications/Others brew install --cask affinity --appdir=/Applications/Others brew install --cask --no-quarantine vivaldi --appdir=/Applications/Others - # brew install --cask pixelorama --appdir=/Applications/Others # deprecated or disabled + + print_success "Other software installed" + INSTALLED_COMPONENTS+=("Other Software") } -prompt_for_multiselect result "Install brew;install Git;install Zsh;install Asdf;install Software: Development;install Software: Tools;install Software: Communication;install Software: Office;install Software: Games;install Software: Others;install Software: LLM;install Software: Pro" "true;true;true;true;;;;;;;;" +# Display welcome banner +clear +cat << "EOF" +╔══════════════════════════════════════════════════════════════════════════════╗ +║ ║ +║ 🚀 DOTFILES SETUP SCRIPT 🚀 ║ +║ ║ +║ Configure your development environment with ease ║ +║ ║ +╚══════════════════════════════════════════════════════════════════════════════╝ +EOF +echo "" + +if [ "$SKIP_INTERACTIVE" = true ]; then + print_info "Running in non-interactive mode with default selections" + # Set default selections (brew, git, zsh, asdf enabled) + result=(true true true true false false false false false false false false) +else + print_info "Select the components you want to install:" + echo "" + prompt_for_multiselect result "Install brew;install Git;install Zsh;install Asdf;install Software: Development;install Software: Tools;install Software: Communication;install Software: Office;install Software: Games;install Software: Others;install Software: LLM;install Software: Pro" "true;true;true;true;;;;;;;;" +fi for option in "${result[@]}"; do if [[ $option == true ]]; then ((numberStep++)) fi done -echo numberStep: $numberStep + +if [ $numberStep -eq 0 ]; then + print_warning "No components selected. Exiting." + exit 0 +fi + +print_info "Total steps to execute: $numberStep" +echo "" +sleep 1 + # Call the functions depending on the result for i in "${!result[@]}"; do if [[ ${result[$i]} == true ]]; then @@ -301,4 +500,44 @@ for i in "${!result[@]}"; do 11) installSoftwarePro ;; esac fi -done \ No newline at end of file +done + +# Display summary +echo "" +print_header "Installation Summary" +echo "" + +if [ ${#INSTALLED_COMPONENTS[@]} -gt 0 ]; then + echo -e "${BOLD}${GREEN}✓ Successfully Installed:${NC}" + for component in "${INSTALLED_COMPONENTS[@]}"; do + echo -e " ${GREEN}✓${NC} $component" + done + echo "" +fi + +if [ ${#SKIPPED_COMPONENTS[@]} -gt 0 ]; then + echo -e "${BOLD}${YELLOW}⊘ Skipped (already installed):${NC}" + for component in "${SKIPPED_COMPONENTS[@]}"; do + echo -e " ${YELLOW}⊘${NC} $component" + done + echo "" +fi + +if [ ${#FAILED_COMPONENTS[@]} -gt 0 ]; then + echo -e "${BOLD}${RED}✗ Failed to Install:${NC}" + for component in "${FAILED_COMPONENTS[@]}"; do + echo -e " ${RED}✗${NC} $component" + done + echo "" + print_error "Some components failed to install. Please check the output above for details." + exit 1 +else + echo -e "${BOLD}${GREEN}🎉 All selected components installed successfully!${NC}" + echo "" + print_info "Next steps:" + echo " 1. Restart your terminal or run: source ~/.zshrc" + echo " 2. Configure PowerLevel10k theme by running: p10k configure" + echo " 3. Customize your settings in ~/.custom.zsh" + echo "" + print_success "Setup complete! Happy coding! 🚀" +fi \ No newline at end of file diff --git a/prompt_for_multiselect.sh b/prompt_for_multiselect.sh index 1ededf0..3a6d485 100755 --- a/prompt_for_multiselect.sh +++ b/prompt_for_multiselect.sh @@ -1,13 +1,15 @@ +#!/bin/bash + function prompt_for_multiselect { # little helpers for terminal print control and key input ESC=$( printf "\033") - cursor_blink_on() { printf "$ESC[?25h"; } - cursor_blink_off() { printf "$ESC[?25l"; } - cursor_to() { printf "$ESC[$1;${2:-1}H"; } - print_inactive() { printf "$2 $1 "; } - print_active() { printf "$2 $ESC[7m $1 $ESC[27m"; } - get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; } + cursor_blink_on() { printf "%s[?25h" "$ESC"; } + cursor_blink_off() { printf "%s[?25l" "$ESC"; } + cursor_to() { printf "%s[%s;%sH" "$ESC" "$1" "${2:-1}"; } + print_inactive() { printf "%s %s " "$2" "$1"; } + print_active() { printf "%s %s[7m %s %s[27m" "$2" "$ESC" "$1" "$ESC"; } + get_cursor_row() { IFS=';' read -rsdR -p $'\E[6n' ROW COL; echo "${ROW#*[}"; } key_input() { local key IFS= read -rsn1 key 2>/dev/null >&2 @@ -28,7 +30,7 @@ function prompt_for_multiselect { else arr[option]=true fi - eval $arr_name='("${arr[@]}")' + eval "$arr_name"='("${arr[@]}")' } local retval=$1 @@ -49,8 +51,9 @@ function prompt_for_multiselect { done # determine current screen position for overwriting the options - local lastrow=`get_cursor_row` - local startrow=$(($lastrow - ${#options[@]})) + local lastrow + lastrow=$(get_cursor_row) + local startrow=$((lastrow - ${#options[@]})) # ensure cursor and input echoing back on upon a ctrl+c during read -s trap "cursor_blink_on; stty echo; printf '\n'; exit" 2 @@ -66,7 +69,7 @@ function prompt_for_multiselect { prefix="[x]" fi - cursor_to $(($startrow + $idx)) + cursor_to $((startrow + idx)) if [ $idx -eq $active ]; then print_active "$option" "$prefix" else @@ -76,7 +79,7 @@ function prompt_for_multiselect { done # user key control - case `key_input` in + case $(key_input) in space) toggle_option selected $active;; enter) break;; up) ((active--)); @@ -87,11 +90,11 @@ function prompt_for_multiselect { done # cursor position back to normal - cursor_to $lastrow + cursor_to "$lastrow" printf "\n" cursor_blink_on - eval $retval='("${selected[@]}")' + eval "$retval"='("${selected[@]}")' } # prompt_for_multiselect result "Option 1;Option 2;Option 3" "true;;true" diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 113147a..0f52e8c 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -1,3 +1,4 @@ +#!/bin/zsh # ############################################################################ # ALIAS (COMMONS) # ------------------------------------------------------------ @@ -40,9 +41,9 @@ function git-prune-branches() { # Switch to an existing default branch for branch in "${default_branches[@]}"; do - if git show-ref --verify --quiet refs/heads/$branch; then + if git show-ref --verify --quiet "refs/heads/$branch"; then echo "Switching to $branch branch..." - git checkout $branch + git checkout "$branch" break fi done @@ -51,21 +52,20 @@ function git-prune-branches() { git fetch -p echo "Running pruning of local branches" - for branch in $(git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1 }'); do - git branch -d $branch 2>/dev/null - if [ $? -ne 0 ]; then + while IFS= read -r branch; do + if ! git branch -d "$branch" 2>/dev/null; then echo "The branch '$branch' is not fully merged." while true; do echo -n "Do you want to force delete it? (y/n) " - read confirm + read -r confirm case $confirm in - [Yy]* ) git branch -D $branch; break;; + [Yy]* ) git branch -D "$branch"; break;; [Nn]* ) echo "Skipping branch '$branch'"; break;; * ) echo "Please answer yes or no.";; esac done fi - done + done < <(git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1 }') } alias gpb='git-prune-branches' diff --git a/zsh/zlogin b/zsh/zlogin index e22ddaa..f9017e6 100644 --- a/zsh/zlogin +++ b/zsh/zlogin @@ -1 +1 @@ -export PATH="/usr/local/sbin:/opt/homebrew/sbin:/opt/homebrew/bin":$PATH \ No newline at end of file +export PATH="/usr/local/sbin:/opt/homebrew/sbin:/opt/homebrew/bin:$PATH" \ No newline at end of file diff --git a/zsh/zshrc b/zsh/zshrc index ebc8413..2d98109 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -50,18 +50,18 @@ HIST_STAMPS="dd/mm/yyyy" # Add wisely, as too many plugins slow down shell startup. plugins=(git vscode k zsh-autosuggestions zsh-syntax-highlighting) -source $ZSH/oh-my-zsh.sh +source "$ZSH/oh-my-zsh.sh" # Plugins -source ${HOME}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh -source ${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh -source ${HOME}/.oh-my-zsh/custom/plugins/k/k.plugin.zsh +source "${HOME}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" +source "${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" +source "${HOME}/.oh-my-zsh/custom/plugins/k/k.plugin.zsh" # Others -source $HOME/.dotfiles-config-path.zsh -source $DOTFILE_PATH/zsh/p10k.zsh -source $DOTFILE_PATH/zsh/aliases.zsh +source "$HOME/.dotfiles-config-path.zsh" +source "$DOTFILE_PATH/zsh/p10k.zsh" +source "$DOTFILE_PATH/zsh/aliases.zsh" -source $HOME/.custom.zsh +source "$HOME/.custom.zsh" export ASDF_NPM_DEFAULT_PACKAGES_FILE=${DOTFILE_PATH}/asdf/default-npm-package