weehong revised this gist 1 month ago. Go to revision
1 file changed, 29 insertions, 1 deletion
zsh_macos.sh
| @@ -202,4 +202,32 @@ run_choices() { | |||
| 202 | 202 | ||
| 203 | 203 | case "$choice" in | |
| 204 | 204 | 1) configure_git ;; | |
| 205 | - | 2) install_oh_my_ | |
| 205 | + | 2) install_oh_my_zsh ;; | |
| 206 | + | 3) install_plugins ;; | |
| 207 | + | 4) install_theme ;; | |
| 208 | + | 5) download_configs ;; | |
| 209 | + | 6) update_zshrc ;; | |
| 210 | + | 7) switch_shell ;; | |
| 211 | + | 8) log "Exiting..."; exit 0 ;; | |
| 212 | + | *) warn "Skipping invalid option: $choice" ;; | |
| 213 | + | esac | |
| 214 | + | echo | |
| 215 | + | done | |
| 216 | + | fi | |
| 217 | + | } | |
| 218 | + | ||
| 219 | + | # ============================= | |
| 220 | + | # MAIN | |
| 221 | + | # ============================= | |
| 222 | + | main() { | |
| 223 | + | check_requirements | |
| 224 | + | while true; do | |
| 225 | + | show_menu | |
| 226 | + | run_choices | |
| 227 | + | read -p "Do you want to run more options? (y/n): " again | |
| 228 | + | [[ "$again" =~ ^[Yy]$ ]] || break | |
| 229 | + | done | |
| 230 | + | ok "macOS configuration complete!" | |
| 231 | + | } | |
| 232 | + | ||
| 233 | + | main "$@" | |
weehong revised this gist 1 month ago. Go to revision
1 file changed, 17 insertions, 43 deletions
zsh_macos.sh
| @@ -184,48 +184,22 @@ run_choices() { | |||
| 184 | 184 | fi | |
| 185 | 185 | done | |
| 186 | 186 | ||
| 187 | - | # Loop through the intended runs and apply the exclusions | |
| 188 | - | for choice in "${to_run[@]}"; do | |
| 189 | - | ||
| 190 | - | # Check if the current choice is in the exclusion array | |
| 191 | - | local skip=false | |
| 192 | - | for ex in "${to_exclude[@]}"; do | |
| 193 | - | if [[ "$choice" == "$ex" ]]; then | |
| 194 | - | skip=true | |
| 195 | - | break | |
| 187 | + | # Protect against empty arrays crashing older bash versions with 'set -u' | |
| 188 | + | if [[ ${#to_run[@]} -gt 0 ]]; then | |
| 189 | + | for choice in "${to_run[@]}"; do | |
| 190 | + | ||
| 191 | + | local skip=false | |
| 192 | + | if [[ ${#to_exclude[@]} -gt 0 ]]; then | |
| 193 | + | for ex in "${to_exclude[@]}"; do | |
| 194 | + | if [[ "$choice" == "$ex" ]]; then | |
| 195 | + | skip=true | |
| 196 | + | break | |
| 197 | + | fi | |
| 198 | + | done | |
| 196 | 199 | fi | |
| 197 | - | done | |
| 198 | - | ||
| 199 | - | # If skip is true, jump to the next iteration of the loop without doing anything | |
| 200 | - | $skip && continue | |
| 201 | - | ||
| 202 | - | case "$choice" in | |
| 203 | - | 1) configure_git ;; | |
| 204 | - | 2) install_oh_my_zsh ;; | |
| 205 | - | 3) install_plugins ;; | |
| 206 | - | 4) install_theme ;; | |
| 207 | - | 5) download_configs ;; | |
| 208 | - | 6) update_zshrc ;; | |
| 209 | - | 7) switch_shell ;; | |
| 210 | - | 8) log "Exiting..."; exit 0 ;; | |
| 211 | - | *) warn "Skipping invalid option: $choice" ;; | |
| 212 | - | esac | |
| 213 | - | echo | |
| 214 | - | done | |
| 215 | - | } | |
| 216 | - | ||
| 217 | - | # ============================= | |
| 218 | - | # MAIN | |
| 219 | - | # ============================= | |
| 220 | - | main() { | |
| 221 | - | check_requirements | |
| 222 | - | while true; do | |
| 223 | - | show_menu | |
| 224 | - | run_choices | |
| 225 | - | read -p "Do you want to run more options? (y/n): " again | |
| 226 | - | [[ "$again" =~ ^[Yy]$ ]] || break | |
| 227 | - | done | |
| 228 | - | ok "macOS configuration complete!" | |
| 229 | - | } | |
| 200 | + | ||
| 201 | + | $skip && continue | |
| 230 | 202 | ||
| 231 | - | main "$@" | |
| 203 | + | case "$choice" in | |
| 204 | + | 1) configure_git ;; | |
| 205 | + | 2) install_oh_my_ | |
weehong revised this gist 1 month ago. Go to revision
1 file changed, 19 insertions
zsh_macos.sh
| @@ -83,6 +83,21 @@ install_theme() { | |||
| 83 | 83 | ok "Theme installed" | |
| 84 | 84 | } | |
| 85 | 85 | ||
| 86 | + | clean_macos_aliases() { | |
| 87 | + | local alias_file="$HOME/.alias" | |
| 88 | + | if [[ -f "$alias_file" ]]; then | |
| 89 | + | log "Patching .alias for macOS (removing apt-get and xclip blocks)..." | |
| 90 | + | ||
| 91 | + | # Delete the multiline apt-get block (from the comment down to the final command) | |
| 92 | + | sed -i '' '/# System update & cleanup/,/sudo apt-get clean/d' "$alias_file" | |
| 93 | + | ||
| 94 | + | # Delete the xclip block | |
| 95 | + | sed -i '' '/# xclip shortcuts/,/xclip -selection clipboard/d' "$alias_file" | |
| 96 | + | ||
| 97 | + | ok "macOS incompatibilities removed from .alias" | |
| 98 | + | fi | |
| 99 | + | } | |
| 100 | + | ||
| 86 | 101 | download_configs() { | |
| 87 | 102 | log "Downloading custom config files..." | |
| 88 | 103 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" | |
| @@ -98,6 +113,10 @@ download_configs() { | |||
| 98 | 113 | log "Fetching $f ..." | |
| 99 | 114 | curl -fsSL "$url" -o "$HOME/$f" || warn "Failed to download $f" | |
| 100 | 115 | done | |
| 116 | + | ||
| 117 | + | # Automatically clean up the macOS incompatible aliases after downloading | |
| 118 | + | clean_macos_aliases | |
| 119 | + | ||
| 101 | 120 | ok "Configs downloaded (Backup at $backup)" | |
| 102 | 121 | } | |
| 103 | 122 | ||
weehong revised this gist 1 month ago. Go to revision
1 file changed, 5 insertions, 2 deletions
README.md
| @@ -2,8 +2,11 @@ | |||
| 2 | 2 | The "Bash Script Installer" simplifies the setup of Zsh. | |
| 3 | 3 | ||
| 4 | 4 | ## Zsh | |
| 5 | - | ``` | |
| 5 | + | ### Ubuntu | |
| 6 | + | ```zsh | |
| 6 | 7 | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)" | |
| 8 | + | ``` | |
| 9 | + | ### MacOS | |
| 10 | + | ```zsh | |
| 7 | 11 | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)" | |
| 8 | - | ||
| 9 | 12 | ``` | |
weehong revised this gist 1 month ago. Go to revision
3 files changed, 253 insertions, 8 deletions
README.md
| @@ -3,5 +3,7 @@ The "Bash Script Installer" simplifies the setup of Zsh. | |||
| 3 | 3 | ||
| 4 | 4 | ## Zsh | |
| 5 | 5 | ``` | |
| 6 | - | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh.sh)" | |
| 6 | + | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)" | |
| 7 | + | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)" | |
| 8 | + | ||
| 7 | 9 | ``` | |
zsh_macos.sh(file created)
| @@ -0,0 +1,212 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | set -euo pipefail | |
| 3 | + | ||
| 4 | + | # ============================= | |
| 5 | + | # COLORS & LOGGING | |
| 6 | + | # ============================= | |
| 7 | + | RED='\033[0;31m' | |
| 8 | + | GREEN='\033[0;32m' | |
| 9 | + | YELLOW='\033[1;33m' | |
| 10 | + | BLUE='\033[0;34m' | |
| 11 | + | NC='\033[0m' | |
| 12 | + | ||
| 13 | + | log() { echo -e "${BLUE}[INFO]${NC} $*"; } | |
| 14 | + | ok() { echo -e "${GREEN}[OK]${NC} $*"; } | |
| 15 | + | warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } | |
| 16 | + | err() { echo -e "${RED}[ERROR]${NC} $*" >&2; } | |
| 17 | + | ||
| 18 | + | # ============================= | |
| 19 | + | # CONFIG | |
| 20 | + | # ============================= | |
| 21 | + | CONFIG_FILES=( | |
| 22 | + | ".alias|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/alias" | |
| 23 | + | ".func|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/func" | |
| 24 | + | ".pathrc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/pathrc" | |
| 25 | + | ".sourcerc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/sourcerc" | |
| 26 | + | ".vimrc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/vimrc" | |
| 27 | + | ".zshrc|https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/zshrc" | |
| 28 | + | ) | |
| 29 | + | ||
| 30 | + | # ============================= | |
| 31 | + | # REQUIREMENTS | |
| 32 | + | # ============================= | |
| 33 | + | check_requirements() { | |
| 34 | + | if [[ $EUID -eq 0 ]]; then | |
| 35 | + | err "Do not run as root on macOS" | |
| 36 | + | exit 1 | |
| 37 | + | fi | |
| 38 | + | } | |
| 39 | + | ||
| 40 | + | # ============================= | |
| 41 | + | # INSTALLATION FUNCTIONS | |
| 42 | + | # ============================= | |
| 43 | + | configure_git() { | |
| 44 | + | log "Configuring Git..." | |
| 45 | + | read -p "Git name (leave empty to skip): " name | |
| 46 | + | read -p "Git email (leave empty to skip): " email | |
| 47 | + | ||
| 48 | + | if [[ -n "$name" ]]; then | |
| 49 | + | git config --global user.name "$name" | |
| 50 | + | fi | |
| 51 | + | if [[ -n "$email" ]]; then | |
| 52 | + | git config --global user.email "$email" | |
| 53 | + | fi | |
| 54 | + | ok "Git configured" | |
| 55 | + | } | |
| 56 | + | ||
| 57 | + | install_oh_my_zsh() { | |
| 58 | + | if [[ -d "$HOME/.oh-my-zsh" ]]; then | |
| 59 | + | ok "Oh My Zsh already installed" | |
| 60 | + | return | |
| 61 | + | fi | |
| 62 | + | ||
| 63 | + | log "Installing Oh My Zsh..." | |
| 64 | + | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ | |
| 65 | + | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| 66 | + | ok "Oh My Zsh installed" | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | install_plugins() { | |
| 70 | + | log "Installing plugins..." | |
| 71 | + | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" | |
| 72 | + | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" | |
| 73 | + | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" | |
| 74 | + | ok "Plugins installed" | |
| 75 | + | } | |
| 76 | + | ||
| 77 | + | install_theme() { | |
| 78 | + | log "Installing Spaceship theme..." | |
| 79 | + | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" | |
| 80 | + | local dir="$themes/spaceship-prompt" | |
| 81 | + | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 | |
| 82 | + | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" | |
| 83 | + | ok "Theme installed" | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | download_configs() { | |
| 87 | + | log "Downloading custom config files..." | |
| 88 | + | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" | |
| 89 | + | mkdir -p "$backup" | |
| 90 | + | ||
| 91 | + | for entry in "${CONFIG_FILES[@]}"; do | |
| 92 | + | local f="${entry%%|*}" | |
| 93 | + | local url="${entry##*|}" | |
| 94 | + | ||
| 95 | + | if [[ -f "$HOME/$f" ]]; then | |
| 96 | + | cp "$HOME/$f" "$backup/" | |
| 97 | + | fi | |
| 98 | + | log "Fetching $f ..." | |
| 99 | + | curl -fsSL "$url" -o "$HOME/$f" || warn "Failed to download $f" | |
| 100 | + | done | |
| 101 | + | ok "Configs downloaded (Backup at $backup)" | |
| 102 | + | } | |
| 103 | + | ||
| 104 | + | update_zshrc() { | |
| 105 | + | local zshrc="$HOME/.zshrc" | |
| 106 | + | log "Updating .zshrc..." | |
| 107 | + | ||
| 108 | + | if [[ ! -f "$zshrc" ]]; then | |
| 109 | + | warn ".zshrc not found, creating new one..." | |
| 110 | + | touch "$zshrc" | |
| 111 | + | fi | |
| 112 | + | ||
| 113 | + | # macOS BSD sed requires '-i ''' for in-place editing | |
| 114 | + | grep -q 'ZSH_THEME="spaceship"' "$zshrc" || sed -i '' 's/ZSH_THEME=".*"/ZSH_THEME="spaceship"/' "$zshrc" | |
| 115 | + | grep -q 'zsh-autosuggestions' "$zshrc" || sed -i '' 's/plugins=(/plugins=(zsh-autosuggestions /' "$zshrc" | |
| 116 | + | grep -q 'zsh-syntax-highlighting' "$zshrc" || sed -i '' 's/plugins=(/plugins=(zsh-syntax-highlighting /' "$zshrc" | |
| 117 | + | ok ".zshrc updated with plugins and theme" | |
| 118 | + | } | |
| 119 | + | ||
| 120 | + | switch_shell() { | |
| 121 | + | log "Starting Zsh session..." | |
| 122 | + | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" | |
| 123 | + | echo "----------------------------------------" | |
| 124 | + | zsh -l | |
| 125 | + | echo "----------------------------------------" | |
| 126 | + | ok "Returned from Zsh session" | |
| 127 | + | } | |
| 128 | + | ||
| 129 | + | # ============================= | |
| 130 | + | # INTERACTIVE MENU | |
| 131 | + | # ============================= | |
| 132 | + | show_menu() { | |
| 133 | + | echo "===========================================" | |
| 134 | + | echo "macOS Zsh Setup - Choose what to do" | |
| 135 | + | echo "===========================================" | |
| 136 | + | echo " 0) Run ALL steps (1-7)" | |
| 137 | + | echo " 1) Configure Git" | |
| 138 | + | echo " 2) Install Oh My Zsh" | |
| 139 | + | echo " 3) Install plugins (autosuggestions, syntax highlighting)" | |
| 140 | + | echo " 4) Install Spaceship theme" | |
| 141 | + | echo " 5) Download custom configs (~/.alias, .vimrc, etc.)" | |
| 142 | + | echo " 6) Update ~/.zshrc for plugins & theme" | |
| 143 | + | echo " 7) Switch to Zsh (Temporary Sub-shell)" | |
| 144 | + | echo " 8) Quit" | |
| 145 | + | echo "===========================================" | |
| 146 | + | echo "Inputs: '0' (All), '1 3 4' (Specific), '0 !1 !5' (All except 1 and 5)" | |
| 147 | + | } | |
| 148 | + | ||
| 149 | + | run_choices() { | |
| 150 | + | local input | |
| 151 | + | read -p "Select: " input | |
| 152 | + | input="${input//,/ }" # replace commas with spaces if used | |
| 153 | + | ||
| 154 | + | local -a to_run=() | |
| 155 | + | local -a to_exclude=() | |
| 156 | + | ||
| 157 | + | # Parse positive selections and negative exclusions | |
| 158 | + | for item in $input; do | |
| 159 | + | if [[ "$item" == !* ]]; then | |
| 160 | + | to_exclude+=("${item:1}") # Strip the '!' character | |
| 161 | + | elif [[ "$item" == "0" ]]; then | |
| 162 | + | to_run+=(1 2 3 4 5 6 7) | |
| 163 | + | else | |
| 164 | + | to_run+=("$item") | |
| 165 | + | fi | |
| 166 | + | done | |
| 167 | + | ||
| 168 | + | # Loop through the intended runs and apply the exclusions | |
| 169 | + | for choice in "${to_run[@]}"; do | |
| 170 | + | ||
| 171 | + | # Check if the current choice is in the exclusion array | |
| 172 | + | local skip=false | |
| 173 | + | for ex in "${to_exclude[@]}"; do | |
| 174 | + | if [[ "$choice" == "$ex" ]]; then | |
| 175 | + | skip=true | |
| 176 | + | break | |
| 177 | + | fi | |
| 178 | + | done | |
| 179 | + | ||
| 180 | + | # If skip is true, jump to the next iteration of the loop without doing anything | |
| 181 | + | $skip && continue | |
| 182 | + | ||
| 183 | + | case "$choice" in | |
| 184 | + | 1) configure_git ;; | |
| 185 | + | 2) install_oh_my_zsh ;; | |
| 186 | + | 3) install_plugins ;; | |
| 187 | + | 4) install_theme ;; | |
| 188 | + | 5) download_configs ;; | |
| 189 | + | 6) update_zshrc ;; | |
| 190 | + | 7) switch_shell ;; | |
| 191 | + | 8) log "Exiting..."; exit 0 ;; | |
| 192 | + | *) warn "Skipping invalid option: $choice" ;; | |
| 193 | + | esac | |
| 194 | + | echo | |
| 195 | + | done | |
| 196 | + | } | |
| 197 | + | ||
| 198 | + | # ============================= | |
| 199 | + | # MAIN | |
| 200 | + | # ============================= | |
| 201 | + | main() { | |
| 202 | + | check_requirements | |
| 203 | + | while true; do | |
| 204 | + | show_menu | |
| 205 | + | run_choices | |
| 206 | + | read -p "Do you want to run more options? (y/n): " again | |
| 207 | + | [[ "$again" =~ ^[Yy]$ ]] || break | |
| 208 | + | done | |
| 209 | + | ok "macOS configuration complete!" | |
| 210 | + | } | |
| 211 | + | ||
| 212 | + | main "$@" | |
zsh.sh renamed to zsh_ubuntu.sh
| @@ -21,8 +21,6 @@ err() { echo -e "${RED}[ERROR]${NC} $*" >&2; } | |||
| 21 | 21 | SKIP_PACKAGES=false | |
| 22 | 22 | SKIP_GIT_CONFIG=false | |
| 23 | 23 | SKIP_SHELL_CHANGE=false | |
| 24 | - | # This flag is for non-interactive mode. | |
| 25 | - | # Interactive menu options will override this. | |
| 26 | 24 | CUSTOM_CONFIG=false | |
| 27 | 25 | SKIP_XCLIP=false | |
| 28 | 26 | INSTALL_HOMEBREW=false | |
| @@ -52,8 +50,15 @@ detect_os() { | |||
| 52 | 50 | # REQUIREMENTS | |
| 53 | 51 | # ============================= | |
| 54 | 52 | check_requirements() { | |
| 55 | - | [[ $EUID -eq 0 ]] && err "Do not run as root" && exit 1 | |
| 56 | - | command -v sudo >/dev/null || { err "sudo required"; exit 1; } | |
| 53 | + | # Fixed to prevent silent failure with 'set -e' | |
| 54 | + | if [[ $EUID -eq 0 ]]; then | |
| 55 | + | err "Do not run as root" | |
| 56 | + | exit 1 | |
| 57 | + | fi | |
| 58 | + | if ! command -v sudo >/dev/null; then | |
| 59 | + | err "sudo required" | |
| 60 | + | exit 1 | |
| 61 | + | fi | |
| 57 | 62 | } | |
| 58 | 63 | ||
| 59 | 64 | # ============================= | |
| @@ -150,7 +155,6 @@ install_theme() { | |||
| 150 | 155 | } | |
| 151 | 156 | ||
| 152 | 157 | download_configs() { | |
| 153 | - | # Guard clause removed so menu selection works | |
| 154 | 158 | log "Downloading custom config files..." | |
| 155 | 159 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" | |
| 156 | 160 | mkdir -p "$backup" | |
| @@ -202,6 +206,7 @@ show_menu() { | |||
| 202 | 206 | echo "===========================================" | |
| 203 | 207 | echo "Zsh Installer - Choose what to do" | |
| 204 | 208 | echo "===========================================" | |
| 209 | + | echo " 0) Run ALL steps (1-13)" | |
| 205 | 210 | echo " 1) Update system packages" | |
| 206 | 211 | echo " 2) Install core packages (zsh, git, vim, etc.)" | |
| 207 | 212 | echo " 3) Set Timezone (Asia/Singapore)" | |
| @@ -217,7 +222,7 @@ show_menu() { | |||
| 217 | 222 | echo "13) Switch to Zsh (Temporary Sub-shell)" | |
| 218 | 223 | echo "14) Quit" | |
| 219 | 224 | echo "===========================================" | |
| 220 | - | echo "You can enter multiple numbers at once (e.g., 2,3,7,8)" | |
| 225 | + | echo "Inputs: '0' (All), '2 3 7' (Specific), '0 !4 !6' (All except 4 and 6)" | |
| 221 | 226 | } | |
| 222 | 227 | ||
| 223 | 228 | run_choices() { | |
| @@ -225,7 +230,33 @@ run_choices() { | |||
| 225 | 230 | read -p "Select: " input | |
| 226 | 231 | input="${input//,/ }" # replace commas with spaces | |
| 227 | 232 | ||
| 228 | - | for choice in $input; do | |
| 233 | + | local -a to_run=() | |
| 234 | + | local -a to_exclude=() | |
| 235 | + | ||
| 236 | + | # Parse positive selections and negative exclusions | |
| 237 | + | for item in $input; do | |
| 238 | + | if [[ "$item" == !* ]]; then | |
| 239 | + | to_exclude+=("${item:1}") # Strip the '!' character | |
| 240 | + | elif [[ "$item" == "0" ]]; then | |
| 241 | + | to_run+=(1 2 3 4 5 6 7 8 9 10 11 12 13) | |
| 242 | + | else | |
| 243 | + | to_run+=("$item") | |
| 244 | + | fi | |
| 245 | + | done | |
| 246 | + | ||
| 247 | + | # Loop through intended runs and apply exclusions | |
| 248 | + | for choice in "${to_run[@]}"; do | |
| 249 | + | ||
| 250 | + | local skip=false | |
| 251 | + | for ex in "${to_exclude[@]}"; do | |
| 252 | + | if [[ "$choice" == "$ex" ]]; then | |
| 253 | + | skip=true | |
| 254 | + | break | |
| 255 | + | fi | |
| 256 | + | done | |
| 257 | + | ||
| 258 | + | $skip && continue | |
| 259 | + | ||
| 229 | 260 | case "$choice" in | |
| 230 | 261 | 1) update_system ;; | |
| 231 | 262 | 2) install_packages ;; | |
weehong revised this gist 1 month ago. Go to revision
No changes
weehong revised this gist 1 month ago. Go to revision
1 file changed, 3 insertions, 3 deletions
README.md
| @@ -1,7 +1,7 @@ | |||
| 1 | - | # Bash Script Installer for Zsh, Go, Python, GNU GCC and .NET | |
| 2 | - | The "Bash Script Installer" simplifies the setup of Zsh, Go, Python, GNU GCC, and .NET on Unix-based systems, providing a user-friendly, automated installation process for developers. | |
| 1 | + | # Bash Script Installer for Zsh | |
| 2 | + | The "Bash Script Installer" simplifies the setup of Zsh. | |
| 3 | 3 | ||
| 4 | - | ## ZSH | |
| 4 | + | ## Zsh | |
| 5 | 5 | ``` | |
| 6 | 6 | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh.sh)" | |
| 7 | 7 | ``` | |
weehong revised this gist 1 month ago. Go to revision
1 file changed, 1 insertion, 1 deletion
README.md
| @@ -3,5 +3,5 @@ The "Bash Script Installer" simplifies the setup of Zsh, Go, Python, GNU GCC, an | |||
| 3 | 3 | ||
| 4 | 4 | ## ZSH | |
| 5 | 5 | ``` | |
| 6 | - | bash -c "$(curl -fsSL https://gist.githubusercontent.com/weehongkoh/e56d8161fa47e3ac8416ad8340ee3f82/raw/zsh_ubuntu.sh)" | |
| 6 | + | bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh.sh)" | |
| 7 | 7 | ``` | |
weehong revised this gist 1 month ago. Go to revision
1 file changed, 264 insertions
zsh.sh(file created)
| @@ -0,0 +1,264 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | set -euo pipefail | |
| 3 | + | ||
| 4 | + | # ============================= | |
| 5 | + | # COLORS & LOGGING | |
| 6 | + | # ============================= | |
| 7 | + | RED='\033[0;31m' | |
| 8 | + | GREEN='\033[0;32m' | |
| 9 | + | YELLOW='\033[1;33m' | |
| 10 | + | BLUE='\033[0;34m' | |
| 11 | + | NC='\033[0m' | |
| 12 | + | ||
| 13 | + | log() { echo -e "${BLUE}[INFO]${NC} $*"; } | |
| 14 | + | ok() { echo -e "${GREEN}[OK]${NC} $*"; } | |
| 15 | + | warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } | |
| 16 | + | err() { echo -e "${RED}[ERROR]${NC} $*" >&2; } | |
| 17 | + | ||
| 18 | + | # ============================= | |
| 19 | + | # FLAGS & CONFIG | |
| 20 | + | # ============================= | |
| 21 | + | SKIP_PACKAGES=false | |
| 22 | + | SKIP_GIT_CONFIG=false | |
| 23 | + | SKIP_SHELL_CHANGE=false | |
| 24 | + | # This flag is for non-interactive mode. | |
| 25 | + | # Interactive menu options will override this. | |
| 26 | + | CUSTOM_CONFIG=false | |
| 27 | + | SKIP_XCLIP=false | |
| 28 | + | INSTALL_HOMEBREW=false | |
| 29 | + | ||
| 30 | + | declare -A CONFIG_FILES=( | |
| 31 | + | [".alias"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/alias" | |
| 32 | + | [".func"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/func" | |
| 33 | + | [".pathrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/pathrc" | |
| 34 | + | [".sourcerc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/sourcerc" | |
| 35 | + | [".vimrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/vimrc" | |
| 36 | + | [".zshrc"]="https://gist.githubusercontent.com/weehongkoh/72bdb76beacacf2ca3dd39a72395b9ee/raw/zshrc" | |
| 37 | + | ) | |
| 38 | + | ||
| 39 | + | # ============================= | |
| 40 | + | # OS DETECTION | |
| 41 | + | # ============================= | |
| 42 | + | detect_os() { | |
| 43 | + | if [ -f /etc/os-release ]; then | |
| 44 | + | . /etc/os-release | |
| 45 | + | echo "$ID" | |
| 46 | + | else | |
| 47 | + | echo "unknown" | |
| 48 | + | fi | |
| 49 | + | } | |
| 50 | + | ||
| 51 | + | # ============================= | |
| 52 | + | # REQUIREMENTS | |
| 53 | + | # ============================= | |
| 54 | + | check_requirements() { | |
| 55 | + | [[ $EUID -eq 0 ]] && err "Do not run as root" && exit 1 | |
| 56 | + | command -v sudo >/dev/null || { err "sudo required"; exit 1; } | |
| 57 | + | } | |
| 58 | + | ||
| 59 | + | # ============================= | |
| 60 | + | # INSTALLATION FUNCTIONS | |
| 61 | + | # ============================= | |
| 62 | + | update_system() { | |
| 63 | + | $SKIP_PACKAGES && return | |
| 64 | + | log "Updating system..." | |
| 65 | + | sudo apt-get update -y | |
| 66 | + | sudo apt-get upgrade -y | |
| 67 | + | ok "System updated" | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | install_packages() { | |
| 71 | + | $SKIP_PACKAGES && return | |
| 72 | + | log "Installing core packages..." | |
| 73 | + | sudo apt-get install -y \ | |
| 74 | + | zsh git vim curl wget unzip zip build-essential xz-utils | |
| 75 | + | ok "Packages installed" | |
| 76 | + | } | |
| 77 | + | ||
| 78 | + | set_timezone() { | |
| 79 | + | log "Setting timezone to Asia/Singapore..." | |
| 80 | + | sudo timedatectl set-timezone Asia/Singapore | |
| 81 | + | ok "Timezone set to Asia/Singapore" | |
| 82 | + | } | |
| 83 | + | ||
| 84 | + | install_xclip() { | |
| 85 | + | local os | |
| 86 | + | os=$(detect_os) | |
| 87 | + | [[ "$os" != "ubuntu" && "$os" != "debian" ]] && return 0 | |
| 88 | + | $SKIP_XCLIP && return 0 | |
| 89 | + | command -v xclip >/dev/null && ok "xclip already installed" && return 0 | |
| 90 | + | ||
| 91 | + | read -r -p "Install xclip? (y/N): " r | |
| 92 | + | case "$r" in | |
| 93 | + | [Yy]) sudo apt-get install -y xclip; ok "xclip installed" ;; | |
| 94 | + | *) log "Skipping xclip installation" ;; | |
| 95 | + | esac | |
| 96 | + | } | |
| 97 | + | ||
| 98 | + | configure_git() { | |
| 99 | + | $SKIP_GIT_CONFIG && return | |
| 100 | + | log "Configuring Git..." | |
| 101 | + | read -p "Git name (leave empty to skip): " name | |
| 102 | + | read -p "Git email (leave empty to skip): " email | |
| 103 | + | [[ -n "$name" ]] && git config --global user.name "$name" | |
| 104 | + | [[ -n "$email" ]] && git config --global user.email "$email" | |
| 105 | + | ok "Git configured" | |
| 106 | + | } | |
| 107 | + | ||
| 108 | + | install_homebrew() { | |
| 109 | + | ! $INSTALL_HOMEBREW && return | |
| 110 | + | command -v brew >/dev/null && ok "Homebrew already installed" && return | |
| 111 | + | log "Installing Homebrew..." | |
| 112 | + | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| 113 | + | ok "Homebrew installed" | |
| 114 | + | } | |
| 115 | + | ||
| 116 | + | configure_shell() { | |
| 117 | + | $SKIP_SHELL_CHANGE && return | |
| 118 | + | log "Changing default shell to zsh..." | |
| 119 | + | local zsh_path | |
| 120 | + | zsh_path=$(command -v zsh) | |
| 121 | + | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null | |
| 122 | + | sudo chsh -s "$zsh_path" "$USER" | |
| 123 | + | ok "Shell changed (requires logout/login to take effect)" | |
| 124 | + | } | |
| 125 | + | ||
| 126 | + | install_oh_my_zsh() { | |
| 127 | + | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return | |
| 128 | + | log "Installing Oh My Zsh..." | |
| 129 | + | # Keep zshrc ensures we don't blow away configs if they exist | |
| 130 | + | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ | |
| 131 | + | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| 132 | + | ok "Oh My Zsh installed" | |
| 133 | + | } | |
| 134 | + | ||
| 135 | + | install_plugins() { | |
| 136 | + | log "Installing plugins..." | |
| 137 | + | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" | |
| 138 | + | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" | |
| 139 | + | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" | |
| 140 | + | ok "Plugins installed" | |
| 141 | + | } | |
| 142 | + | ||
| 143 | + | install_theme() { | |
| 144 | + | log "Installing Spaceship theme..." | |
| 145 | + | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" | |
| 146 | + | local dir="$themes/spaceship-prompt" | |
| 147 | + | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 | |
| 148 | + | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" | |
| 149 | + | ok "Theme installed" | |
| 150 | + | } | |
| 151 | + | ||
| 152 | + | download_configs() { | |
| 153 | + | # Guard clause removed so menu selection works | |
| 154 | + | log "Downloading custom config files..." | |
| 155 | + | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" | |
| 156 | + | mkdir -p "$backup" | |
| 157 | + | for f in "${!CONFIG_FILES[@]}"; do | |
| 158 | + | if [[ -f "$HOME/$f" ]]; then | |
| 159 | + | cp "$HOME/$f" "$backup/" | |
| 160 | + | fi | |
| 161 | + | log "Fetching $f ..." | |
| 162 | + | curl -fsSL "${CONFIG_FILES[$f]}" -o "$HOME/$f" || warn "Failed to download $f" | |
| 163 | + | done | |
| 164 | + | ok "Configs downloaded (Backup at $backup)" | |
| 165 | + | } | |
| 166 | + | ||
| 167 | + | update_zshrc() { | |
| 168 | + | local zshrc="$HOME/.zshrc" | |
| 169 | + | log "Updating .zshrc..." | |
| 170 | + | ||
| 171 | + | # Create zshrc if missing to prevent errors | |
| 172 | + | if [[ ! -f "$zshrc" ]]; then | |
| 173 | + | warn ".zshrc not found, creating new one..." | |
| 174 | + | touch "$zshrc" | |
| 175 | + | fi | |
| 176 | + | ||
| 177 | + | # Use || true to prevent 'set -e' from exiting if grep finds nothing | |
| 178 | + | grep -q 'ZSH_THEME="spaceship"' "$zshrc" || sed -i 's/ZSH_THEME=".*"/ZSH_THEME="spaceship"/' "$zshrc" | |
| 179 | + | grep -q 'zsh-autosuggestions' "$zshrc" || sed -i 's/plugins=(/plugins=(zsh-autosuggestions /' "$zshrc" | |
| 180 | + | grep -q 'zsh-syntax-highlighting' "$zshrc" || sed -i 's/plugins=(/plugins=(zsh-syntax-highlighting /' "$zshrc" | |
| 181 | + | ok ".zshrc updated with plugins and theme" | |
| 182 | + | } | |
| 183 | + | ||
| 184 | + | switch_shell() { | |
| 185 | + | $SKIP_SHELL_CHANGE && return | |
| 186 | + | ||
| 187 | + | log "Starting Zsh session..." | |
| 188 | + | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" | |
| 189 | + | echo "----------------------------------------" | |
| 190 | + | ||
| 191 | + | # Run zsh as a subprocess, not exec | |
| 192 | + | zsh -l | |
| 193 | + | ||
| 194 | + | echo "----------------------------------------" | |
| 195 | + | ok "Returned from Zsh session" | |
| 196 | + | } | |
| 197 | + | ||
| 198 | + | # ============================= | |
| 199 | + | # INTERACTIVE MENU | |
| 200 | + | # ============================= | |
| 201 | + | show_menu() { | |
| 202 | + | echo "===========================================" | |
| 203 | + | echo "Zsh Installer - Choose what to do" | |
| 204 | + | echo "===========================================" | |
| 205 | + | echo " 1) Update system packages" | |
| 206 | + | echo " 2) Install core packages (zsh, git, vim, etc.)" | |
| 207 | + | echo " 3) Set Timezone (Asia/Singapore)" | |
| 208 | + | echo " 4) Install xclip" | |
| 209 | + | echo " 5) Configure Git" | |
| 210 | + | echo " 6) Install Homebrew" | |
| 211 | + | echo " 7) Configure shell (chsh - sets default shell)" | |
| 212 | + | echo " 8) Install Oh My Zsh" | |
| 213 | + | echo " 9) Install plugins (autosuggestions, syntax highlighting)" | |
| 214 | + | echo "10) Install Spaceship theme" | |
| 215 | + | echo "11) Download custom configs (~/.alias, .vimrc, etc.)" | |
| 216 | + | echo "12) Update ~/.zshrc for plugins & theme" | |
| 217 | + | echo "13) Switch to Zsh (Temporary Sub-shell)" | |
| 218 | + | echo "14) Quit" | |
| 219 | + | echo "===========================================" | |
| 220 | + | echo "You can enter multiple numbers at once (e.g., 2,3,7,8)" | |
| 221 | + | } | |
| 222 | + | ||
| 223 | + | run_choices() { | |
| 224 | + | local input | |
| 225 | + | read -p "Select: " input | |
| 226 | + | input="${input//,/ }" # replace commas with spaces | |
| 227 | + | ||
| 228 | + | for choice in $input; do | |
| 229 | + | case "$choice" in | |
| 230 | + | 1) update_system ;; | |
| 231 | + | 2) install_packages ;; | |
| 232 | + | 3) set_timezone ;; | |
| 233 | + | 4) install_xclip ;; | |
| 234 | + | 5) configure_git ;; | |
| 235 | + | 6) install_homebrew ;; | |
| 236 | + | 7) configure_shell ;; | |
| 237 | + | 8) install_oh_my_zsh ;; | |
| 238 | + | 9) install_plugins ;; | |
| 239 | + | 10) install_theme ;; | |
| 240 | + | 11) download_configs ;; | |
| 241 | + | 12) update_zshrc ;; | |
| 242 | + | 13) switch_shell ;; | |
| 243 | + | 14) log "Exiting..."; exit 0 ;; | |
| 244 | + | *) warn "Skipping invalid option: $choice" ;; | |
| 245 | + | esac | |
| 246 | + | echo | |
| 247 | + | done | |
| 248 | + | } | |
| 249 | + | ||
| 250 | + | # ============================= | |
| 251 | + | # MAIN | |
| 252 | + | # ============================= | |
| 253 | + | main() { | |
| 254 | + | check_requirements | |
| 255 | + | while true; do | |
| 256 | + | show_menu | |
| 257 | + | run_choices | |
| 258 | + | read -p "Do you want to run more options? (y/n): " again | |
| 259 | + | [[ "$again" =~ ^[Yy]$ ]] || break | |
| 260 | + | done | |
| 261 | + | ok "Zsh installation/configuration complete!" | |
| 262 | + | } | |
| 263 | + | ||
| 264 | + | main "$@" | |
weehong revised this gist 1 month ago. Go to revision
1 file changed, 7 insertions
README.md(file created)
| @@ -0,0 +1,7 @@ | |||
| 1 | + | # Bash Script Installer for Zsh, Go, Python, GNU GCC and .NET | |
| 2 | + | The "Bash Script Installer" simplifies the setup of Zsh, Go, Python, GNU GCC, and .NET on Unix-based systems, providing a user-friendly, automated installation process for developers. | |
| 3 | + | ||
| 4 | + | ## ZSH | |
| 5 | + | ``` | |
| 6 | + | bash -c "$(curl -fsSL https://gist.githubusercontent.com/weehongkoh/e56d8161fa47e3ac8416ad8340ee3f82/raw/zsh_ubuntu.sh)" | |
| 7 | + | ``` | |