README.md
· 505 B · Markdown
Brut
# Bash Script Installer for Zsh
The "Bash Script Installer" simplifies the setup of Zsh.
## Zsh
### Ubuntu
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
```
### WSL
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
```
### MacOS
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
```
Bash Script Installer for Zsh
The "Bash Script Installer" simplifies the setup of Zsh.
Zsh
Ubuntu
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
WSL
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
MacOS
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
zsh_macos.sh
· 5.4 KiB · Bash
Brut
#!/bin/bash
set -euo pipefail
# =============================
# COLORS & LOGGING
# =============================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log() { echo -e "${BLUE}[INFO]${NC} $*"; }
ok() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
# =============================
# CONFIG
# =============================
GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
)
# =============================
# REQUIREMENTS
# =============================
check_requirements() {
if [[ $EUID -eq 0 ]]; then
err "Do not run as root on macOS"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
install_oh_my_zsh() {
if [[ -d "$HOME/.oh-my-zsh" ]]; then
ok "Oh My Zsh already installed"
return
fi
log "Installing Oh My Zsh..."
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok "Oh My Zsh installed"
}
install_plugins() {
log "Installing plugins..."
local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
mkdir -p "$dir"
[[ -d "$dir/zsh-autosuggestions" ]] || \
git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
[[ -d "$dir/zsh-syntax-highlighting" ]] || \
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
ok "Plugins installed"
}
install_theme() {
log "Installing Spaceship theme..."
local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
local dir="$themes/spaceship-prompt"
mkdir -p "$themes"
[[ -d "$dir" ]] || \
git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
ok "Theme installed"
}
download_configs() {
log "Downloading custom config files..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
local url="$GIST_RAW_BASE/$f"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $f"
fi
done
ok "Configs downloaded (Backup at $backup)"
}
update_zshrc() {
local zshrc="$HOME/.zshrc"
log "Checking .zshrc..."
if [[ ! -f "$zshrc" ]]; then
warn ".zshrc not found. Run option 5 first."
return 1
fi
ok ".zshrc already comes from the managed gist."
ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
}
switch_shell() {
log "Starting Zsh session..."
echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
echo "----------------------------------------"
zsh -l
echo "----------------------------------------"
ok "Returned from Zsh session"
}
# =============================
# INTERACTIVE MENU
# =============================
show_menu() {
echo "==========================================="
echo "macOS Zsh Setup - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-7)"
echo " 1) Install Oh My Zsh"
echo " 2) Install plugins (autosuggestions, syntax highlighting)"
echo " 3) Install Spaceship theme"
echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)"
echo " 5) Check ~/.zshrc load order"
echo " 6) Switch to Zsh (Temporary Sub-shell)"
echo " 7) Quit"
echo "==========================================="
}
run_choices() {
local input
read -p "Select: " input
input="${input//,/ }"
local -a to_run=()
local -a to_exclude=()
for item in $input; do
if [[ "$item" == !* ]]; then
to_exclude+=("${item:1}")
elif [[ "$item" == "0" ]]; then
to_run+=(1 2 3 4 5 6)
else
to_run+=("$item")
fi
done
if [[ ${#to_run[@]} -gt 0 ]]; then
for choice in "${to_run[@]}"; do
local skip=false
if [[ ${#to_exclude[@]} -gt 0 ]]; then
for ex in "${to_exclude[@]}"; do
if [[ "$choice" == "$ex" ]]; then
skip=true
break
fi
done
fi
$skip && continue
case "$choice" in
1) install_oh_my_zsh ;;
2) install_plugins ;;
3) install_theme ;;
4) download_configs ;;
5) update_zshrc ;;
6) switch_shell ;;
7) exit 0 ;;
*) warn "Skipping invalid option: $choice" ;;
esac
echo
done
fi
}
# =============================
# MAIN
# =============================
main() {
check_requirements
while true; do
show_menu
run_choices
read -p "Do you want to run more options? (y/n): " again
[[ "$again" =~ ^[Yy]$ ]] || break
done
ok "macOS configuration complete!"
}
main "$@"
| 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 | GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw" |
| 22 | |
| 23 | CONFIG_FILES=( |
| 24 | ".alias" |
| 25 | ".func" |
| 26 | ".pathrc" |
| 27 | ".sourcerc" |
| 28 | ".vimrc" |
| 29 | ".zshrc" |
| 30 | ) |
| 31 | |
| 32 | # ============================= |
| 33 | # REQUIREMENTS |
| 34 | # ============================= |
| 35 | check_requirements() { |
| 36 | if [[ $EUID -eq 0 ]]; then |
| 37 | err "Do not run as root on macOS" |
| 38 | exit 1 |
| 39 | fi |
| 40 | } |
| 41 | |
| 42 | # ============================= |
| 43 | # INSTALLATION FUNCTIONS |
| 44 | # ============================= |
| 45 | install_oh_my_zsh() { |
| 46 | if [[ -d "$HOME/.oh-my-zsh" ]]; then |
| 47 | ok "Oh My Zsh already installed" |
| 48 | return |
| 49 | fi |
| 50 | |
| 51 | log "Installing Oh My Zsh..." |
| 52 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 53 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 54 | ok "Oh My Zsh installed" |
| 55 | } |
| 56 | |
| 57 | install_plugins() { |
| 58 | log "Installing plugins..." |
| 59 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 60 | mkdir -p "$dir" |
| 61 | |
| 62 | [[ -d "$dir/zsh-autosuggestions" ]] || \ |
| 63 | git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 64 | |
| 65 | [[ -d "$dir/zsh-syntax-highlighting" ]] || \ |
| 66 | git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 67 | |
| 68 | ok "Plugins installed" |
| 69 | } |
| 70 | |
| 71 | install_theme() { |
| 72 | log "Installing Spaceship theme..." |
| 73 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 74 | local dir="$themes/spaceship-prompt" |
| 75 | |
| 76 | mkdir -p "$themes" |
| 77 | [[ -d "$dir" ]] || \ |
| 78 | git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 79 | |
| 80 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 81 | ok "Theme installed" |
| 82 | } |
| 83 | |
| 84 | download_configs() { |
| 85 | log "Downloading custom config files..." |
| 86 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 87 | mkdir -p "$backup" |
| 88 | |
| 89 | for f in "${CONFIG_FILES[@]}"; do |
| 90 | local url="$GIST_RAW_BASE/$f" |
| 91 | local target="$HOME/$f" |
| 92 | local tmp="${target}.tmp.$$" |
| 93 | |
| 94 | if [[ -f "$target" ]]; then |
| 95 | cp "$target" "$backup/" |
| 96 | fi |
| 97 | |
| 98 | log "Fetching $f ..." |
| 99 | if curl -fsSL "$url" -o "$tmp"; then |
| 100 | mv "$tmp" "$target" |
| 101 | else |
| 102 | rm -f "$tmp" |
| 103 | warn "Failed to download $f" |
| 104 | fi |
| 105 | done |
| 106 | |
| 107 | ok "Configs downloaded (Backup at $backup)" |
| 108 | } |
| 109 | |
| 110 | update_zshrc() { |
| 111 | local zshrc="$HOME/.zshrc" |
| 112 | log "Checking .zshrc..." |
| 113 | |
| 114 | if [[ ! -f "$zshrc" ]]; then |
| 115 | warn ".zshrc not found. Run option 5 first." |
| 116 | return 1 |
| 117 | fi |
| 118 | |
| 119 | ok ".zshrc already comes from the managed gist." |
| 120 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 121 | } |
| 122 | |
| 123 | switch_shell() { |
| 124 | log "Starting Zsh session..." |
| 125 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 126 | echo "----------------------------------------" |
| 127 | zsh -l |
| 128 | echo "----------------------------------------" |
| 129 | ok "Returned from Zsh session" |
| 130 | } |
| 131 | |
| 132 | # ============================= |
| 133 | # INTERACTIVE MENU |
| 134 | # ============================= |
| 135 | show_menu() { |
| 136 | echo "===========================================" |
| 137 | echo "macOS Zsh Setup - Choose what to do" |
| 138 | echo "===========================================" |
| 139 | echo " 0) Run ALL steps (1-7)" |
| 140 | echo " 1) Install Oh My Zsh" |
| 141 | echo " 2) Install plugins (autosuggestions, syntax highlighting)" |
| 142 | echo " 3) Install Spaceship theme" |
| 143 | echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)" |
| 144 | echo " 5) Check ~/.zshrc load order" |
| 145 | echo " 6) Switch to Zsh (Temporary Sub-shell)" |
| 146 | echo " 7) Quit" |
| 147 | echo "===========================================" |
| 148 | } |
| 149 | |
| 150 | run_choices() { |
| 151 | local input |
| 152 | read -p "Select: " input |
| 153 | input="${input//,/ }" |
| 154 | |
| 155 | local -a to_run=() |
| 156 | local -a to_exclude=() |
| 157 | |
| 158 | for item in $input; do |
| 159 | if [[ "$item" == !* ]]; then |
| 160 | to_exclude+=("${item:1}") |
| 161 | elif [[ "$item" == "0" ]]; then |
| 162 | to_run+=(1 2 3 4 5 6) |
| 163 | else |
| 164 | to_run+=("$item") |
| 165 | fi |
| 166 | done |
| 167 | |
| 168 | if [[ ${#to_run[@]} -gt 0 ]]; then |
| 169 | for choice in "${to_run[@]}"; do |
| 170 | local skip=false |
| 171 | |
| 172 | if [[ ${#to_exclude[@]} -gt 0 ]]; then |
| 173 | for ex in "${to_exclude[@]}"; do |
| 174 | if [[ "$choice" == "$ex" ]]; then |
| 175 | skip=true |
| 176 | break |
| 177 | fi |
| 178 | done |
| 179 | fi |
| 180 | |
| 181 | $skip && continue |
| 182 | |
| 183 | case "$choice" in |
| 184 | 1) install_oh_my_zsh ;; |
| 185 | 2) install_plugins ;; |
| 186 | 3) install_theme ;; |
| 187 | 4) download_configs ;; |
| 188 | 5) update_zshrc ;; |
| 189 | 6) switch_shell ;; |
| 190 | 7) exit 0 ;; |
| 191 | *) warn "Skipping invalid option: $choice" ;; |
| 192 | esac |
| 193 | echo |
| 194 | done |
| 195 | fi |
| 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 "$@" |
| 213 |
zsh_ubuntu.sh
· 7.1 KiB · Bash
Brut
#!/bin/bash
set -euo pipefail
# =============================
# COLORS & LOGGING
# =============================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log() { echo -e "${BLUE}[INFO]${NC} $*"; }
ok() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
# =============================
# FLAGS & CONFIG
# =============================
SKIP_PACKAGES=false
SKIP_SHELL_CHANGE=false
INSTALL_HOMEBREW=false
GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
)
# =============================
# OS DETECTION
# =============================
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
else
echo "unknown"
fi
}
# =============================
# REQUIREMENTS
# =============================
check_requirements() {
if [[ $EUID -eq 0 ]]; then
err "Do not run as root"
exit 1
fi
if ! command -v sudo >/dev/null 2>&1; then
err "sudo required"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
update_system() {
$SKIP_PACKAGES && return
log "Updating system..."
sudo apt-get update -y
sudo apt-get upgrade -y
ok "System updated"
}
install_packages() {
$SKIP_PACKAGES && return
log "Installing core packages..."
sudo apt-get install -y \
zsh git vim curl wget unzip zip build-essential xz-utils
ok "Packages installed"
}
set_timezone() {
log "Setting timezone to Asia/Singapore..."
sudo timedatectl set-timezone Asia/Singapore
ok "Timezone set to Asia/Singapore"
}
install_homebrew() {
! $INSTALL_HOMEBREW && return
command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
log "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ok "Homebrew installed"
}
configure_shell() {
$SKIP_SHELL_CHANGE && return
log "Changing default shell to zsh..."
local zsh_path
zsh_path="$(command -v zsh)"
grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
chsh -s "$zsh_path"
ok "Shell changed (requires logout/login to take effect)"
}
install_oh_my_zsh() {
[[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
log "Installing Oh My Zsh..."
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok "Oh My Zsh installed"
}
install_plugins() {
log "Installing plugins..."
local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
mkdir -p "$dir"
[[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
[[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
ok "Plugins installed"
}
install_theme() {
log "Installing Spaceship theme..."
local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
local dir="$themes/spaceship-prompt"
mkdir -p "$themes"
[[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
ok "Theme installed"
}
download_configs() {
log "Downloading custom config files..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
local url="$GIST_RAW_BASE/$f"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $f"
fi
done
ok "Configs downloaded (Backup at $backup)"
}
update_zshrc() {
local zshrc="$HOME/.zshrc"
log "Checking .zshrc..."
if [[ ! -f "$zshrc" ]]; then
warn ".zshrc not found. Run option 9 first."
return 1
fi
ok ".zshrc already comes from the managed gist."
ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
}
switch_shell() {
log "Starting Zsh session..."
echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
echo "----------------------------------------"
zsh -l
echo "----------------------------------------"
ok "Returned from Zsh session"
}
# =============================
# INTERACTIVE MENU
# =============================
show_menu() {
echo "==========================================="
echo "Zsh Installer - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-11)"
echo " 1) Update system packages"
echo " 2) Install core packages (zsh, git, vim, etc.)"
echo " 3) Set Timezone (Asia/Singapore)"
echo " 4) Install Homebrew"
echo " 5) Configure shell (chsh - sets default shell)"
echo " 6) Install Oh My Zsh"
echo " 7) Install plugins (autosuggestions, syntax highlighting)"
echo " 8) Install Spaceship theme"
echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
echo "10) Check ~/.zshrc load order"
echo "11) Switch to Zsh (Temporary Sub-shell)"
echo "12) Quit"
echo "==========================================="
}
run_choices() {
local input
read -p "Select: " input
input="${input//,/ }"
local -a to_run=()
local -a to_exclude=()
for item in $input; do
if [[ "$item" == !* ]]; then
to_exclude+=("${item:1}")
elif [[ "$item" == "0" ]]; then
to_run+=(1 2 3 4 5 6 7 8 9 10 11)
else
to_run+=("$item")
fi
done
for choice in "${to_run[@]}"; do
local skip=false
for ex in "${to_exclude[@]}"; do
if [[ "$choice" == "$ex" ]]; then
skip=true
break
fi
done
$skip && continue
case "$choice" in
1) update_system ;;
2) install_packages ;;
3) set_timezone ;;
4) install_homebrew ;;
5) configure_shell ;;
6) install_oh_my_zsh ;;
7) install_plugins ;;
8) install_theme ;;
9) download_configs ;;
10) update_zshrc ;;
11) switch_shell ;;
12) log "Exiting..."; exit 0 ;;
*) warn "Skipping invalid option: $choice" ;;
esac
echo
done
}
# =============================
# MAIN
# =============================
main() {
check_requirements
while true; do
show_menu
run_choices
read -p "Do you want to run more options? (y/n): " again
[[ "$again" =~ ^[Yy]$ ]] || break
done
ok "Zsh installation/configuration complete!"
}
main "$@"
| 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_SHELL_CHANGE=false |
| 23 | INSTALL_HOMEBREW=false |
| 24 | |
| 25 | GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw" |
| 26 | CONFIG_FILES=( |
| 27 | ".alias" |
| 28 | ".func" |
| 29 | ".pathrc" |
| 30 | ".sourcerc" |
| 31 | ".vimrc" |
| 32 | ".zshrc" |
| 33 | ) |
| 34 | |
| 35 | # ============================= |
| 36 | # OS DETECTION |
| 37 | # ============================= |
| 38 | detect_os() { |
| 39 | if [ -f /etc/os-release ]; then |
| 40 | . /etc/os-release |
| 41 | echo "$ID" |
| 42 | else |
| 43 | echo "unknown" |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | # ============================= |
| 48 | # REQUIREMENTS |
| 49 | # ============================= |
| 50 | check_requirements() { |
| 51 | if [[ $EUID -eq 0 ]]; then |
| 52 | err "Do not run as root" |
| 53 | exit 1 |
| 54 | fi |
| 55 | if ! command -v sudo >/dev/null 2>&1; then |
| 56 | err "sudo required" |
| 57 | exit 1 |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | # ============================= |
| 62 | # INSTALLATION FUNCTIONS |
| 63 | # ============================= |
| 64 | update_system() { |
| 65 | $SKIP_PACKAGES && return |
| 66 | log "Updating system..." |
| 67 | sudo apt-get update -y |
| 68 | sudo apt-get upgrade -y |
| 69 | ok "System updated" |
| 70 | } |
| 71 | |
| 72 | install_packages() { |
| 73 | $SKIP_PACKAGES && return |
| 74 | log "Installing core packages..." |
| 75 | sudo apt-get install -y \ |
| 76 | zsh git vim curl wget unzip zip build-essential xz-utils |
| 77 | ok "Packages installed" |
| 78 | } |
| 79 | |
| 80 | set_timezone() { |
| 81 | log "Setting timezone to Asia/Singapore..." |
| 82 | sudo timedatectl set-timezone Asia/Singapore |
| 83 | ok "Timezone set to Asia/Singapore" |
| 84 | } |
| 85 | |
| 86 | install_homebrew() { |
| 87 | ! $INSTALL_HOMEBREW && return |
| 88 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 89 | log "Installing Homebrew..." |
| 90 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 91 | ok "Homebrew installed" |
| 92 | } |
| 93 | |
| 94 | configure_shell() { |
| 95 | $SKIP_SHELL_CHANGE && return |
| 96 | log "Changing default shell to zsh..." |
| 97 | local zsh_path |
| 98 | zsh_path="$(command -v zsh)" |
| 99 | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 100 | chsh -s "$zsh_path" |
| 101 | ok "Shell changed (requires logout/login to take effect)" |
| 102 | } |
| 103 | |
| 104 | install_oh_my_zsh() { |
| 105 | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return |
| 106 | log "Installing Oh My Zsh..." |
| 107 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 108 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 109 | ok "Oh My Zsh installed" |
| 110 | } |
| 111 | |
| 112 | install_plugins() { |
| 113 | log "Installing plugins..." |
| 114 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 115 | mkdir -p "$dir" |
| 116 | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 117 | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 118 | ok "Plugins installed" |
| 119 | } |
| 120 | |
| 121 | install_theme() { |
| 122 | log "Installing Spaceship theme..." |
| 123 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 124 | local dir="$themes/spaceship-prompt" |
| 125 | mkdir -p "$themes" |
| 126 | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 127 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 128 | ok "Theme installed" |
| 129 | } |
| 130 | |
| 131 | download_configs() { |
| 132 | log "Downloading custom config files..." |
| 133 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 134 | mkdir -p "$backup" |
| 135 | |
| 136 | for f in "${CONFIG_FILES[@]}"; do |
| 137 | local url="$GIST_RAW_BASE/$f" |
| 138 | local target="$HOME/$f" |
| 139 | local tmp="${target}.tmp.$$" |
| 140 | |
| 141 | if [[ -f "$target" ]]; then |
| 142 | cp "$target" "$backup/" |
| 143 | fi |
| 144 | |
| 145 | log "Fetching $f ..." |
| 146 | if curl -fsSL "$url" -o "$tmp"; then |
| 147 | mv "$tmp" "$target" |
| 148 | else |
| 149 | rm -f "$tmp" |
| 150 | warn "Failed to download $f" |
| 151 | fi |
| 152 | done |
| 153 | |
| 154 | ok "Configs downloaded (Backup at $backup)" |
| 155 | } |
| 156 | |
| 157 | update_zshrc() { |
| 158 | local zshrc="$HOME/.zshrc" |
| 159 | log "Checking .zshrc..." |
| 160 | |
| 161 | if [[ ! -f "$zshrc" ]]; then |
| 162 | warn ".zshrc not found. Run option 9 first." |
| 163 | return 1 |
| 164 | fi |
| 165 | |
| 166 | ok ".zshrc already comes from the managed gist." |
| 167 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 168 | } |
| 169 | |
| 170 | switch_shell() { |
| 171 | log "Starting Zsh session..." |
| 172 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 173 | echo "----------------------------------------" |
| 174 | zsh -l |
| 175 | echo "----------------------------------------" |
| 176 | ok "Returned from Zsh session" |
| 177 | } |
| 178 | |
| 179 | # ============================= |
| 180 | # INTERACTIVE MENU |
| 181 | # ============================= |
| 182 | show_menu() { |
| 183 | echo "===========================================" |
| 184 | echo "Zsh Installer - Choose what to do" |
| 185 | echo "===========================================" |
| 186 | echo " 0) Run ALL steps (1-11)" |
| 187 | echo " 1) Update system packages" |
| 188 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 189 | echo " 3) Set Timezone (Asia/Singapore)" |
| 190 | echo " 4) Install Homebrew" |
| 191 | echo " 5) Configure shell (chsh - sets default shell)" |
| 192 | echo " 6) Install Oh My Zsh" |
| 193 | echo " 7) Install plugins (autosuggestions, syntax highlighting)" |
| 194 | echo " 8) Install Spaceship theme" |
| 195 | echo " 9) Download custom configs (~/.alias, .vimrc, etc.)" |
| 196 | echo "10) Check ~/.zshrc load order" |
| 197 | echo "11) Switch to Zsh (Temporary Sub-shell)" |
| 198 | echo "12) Quit" |
| 199 | echo "===========================================" |
| 200 | } |
| 201 | |
| 202 | run_choices() { |
| 203 | local input |
| 204 | read -p "Select: " input |
| 205 | input="${input//,/ }" |
| 206 | |
| 207 | local -a to_run=() |
| 208 | local -a to_exclude=() |
| 209 | |
| 210 | for item in $input; do |
| 211 | if [[ "$item" == !* ]]; then |
| 212 | to_exclude+=("${item:1}") |
| 213 | elif [[ "$item" == "0" ]]; then |
| 214 | to_run+=(1 2 3 4 5 6 7 8 9 10 11) |
| 215 | else |
| 216 | to_run+=("$item") |
| 217 | fi |
| 218 | done |
| 219 | |
| 220 | for choice in "${to_run[@]}"; do |
| 221 | local skip=false |
| 222 | |
| 223 | for ex in "${to_exclude[@]}"; do |
| 224 | if [[ "$choice" == "$ex" ]]; then |
| 225 | skip=true |
| 226 | break |
| 227 | fi |
| 228 | done |
| 229 | |
| 230 | $skip && continue |
| 231 | |
| 232 | case "$choice" in |
| 233 | 1) update_system ;; |
| 234 | 2) install_packages ;; |
| 235 | 3) set_timezone ;; |
| 236 | 4) install_homebrew ;; |
| 237 | 5) configure_shell ;; |
| 238 | 6) install_oh_my_zsh ;; |
| 239 | 7) install_plugins ;; |
| 240 | 8) install_theme ;; |
| 241 | 9) download_configs ;; |
| 242 | 10) update_zshrc ;; |
| 243 | 11) switch_shell ;; |
| 244 | 12) log "Exiting..."; exit 0 ;; |
| 245 | *) warn "Skipping invalid option: $choice" ;; |
| 246 | esac |
| 247 | echo |
| 248 | done |
| 249 | } |
| 250 | |
| 251 | # ============================= |
| 252 | # MAIN |
| 253 | # ============================= |
| 254 | main() { |
| 255 | check_requirements |
| 256 | while true; do |
| 257 | show_menu |
| 258 | run_choices |
| 259 | read -p "Do you want to run more options? (y/n): " again |
| 260 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 261 | done |
| 262 | ok "Zsh installation/configuration complete!" |
| 263 | } |
| 264 | |
| 265 | main "$@" |
zsh_wsl.sh
· 7.5 KiB · Bash
Brut
#!/bin/bash
set -euo pipefail
# =============================
# COLORS & LOGGING
# =============================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log() { echo -e "${BLUE}[INFO]${NC} $*"; }
ok() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
# =============================
# FLAGS & CONFIG
# =============================
SKIP_PACKAGES=false
SKIP_SHELL_CHANGE=false
INSTALL_HOMEBREW=false
GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
)
# =============================
# PLATFORM DETECTION
# =============================
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
else
echo "unknown"
fi
}
is_wsl() {
grep -qi "microsoft" /proc/version 2>/dev/null
}
# =============================
# REQUIREMENTS
# =============================
check_requirements() {
if [[ $EUID -eq 0 ]]; then
err "Do not run as root"
exit 1
fi
if ! command -v sudo >/dev/null 2>&1; then
err "sudo required"
exit 1
fi
if ! is_wsl; then
err "This installer is intended for WSL"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
update_system() {
$SKIP_PACKAGES && return
log "Updating system..."
sudo apt-get update -y
sudo apt-get upgrade -y
ok "System updated"
}
install_packages() {
$SKIP_PACKAGES && return
log "Installing core packages..."
sudo apt-get install -y \
zsh git vim curl wget unzip zip build-essential xz-utils
ok "Packages installed"
}
set_timezone() {
log "Checking timezone configuration..."
if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then
sudo timedatectl set-timezone Asia/Singapore
ok "Timezone set to Asia/Singapore"
return
fi
warn "Skipping timezone change: timedatectl is not available in this WSL environment"
}
install_homebrew() {
! $INSTALL_HOMEBREW && return
command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
log "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ok "Homebrew installed"
}
configure_shell() {
$SKIP_SHELL_CHANGE && return
log "Changing default shell to zsh..."
local zsh_path
zsh_path="$(command -v zsh)"
grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
chsh -s "$zsh_path"
ok "Shell changed (open a new WSL session for it to take effect)"
}
install_oh_my_zsh() {
[[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
log "Installing Oh My Zsh..."
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok "Oh My Zsh installed"
}
install_plugins() {
log "Installing plugins..."
local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
mkdir -p "$dir"
[[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
[[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
ok "Plugins installed"
}
install_theme() {
log "Installing Spaceship theme..."
local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
local dir="$themes/spaceship-prompt"
mkdir -p "$themes"
[[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
ok "Theme installed"
}
download_configs() {
log "Downloading custom config files..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
local url="$GIST_RAW_BASE/$f"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $f"
fi
done
ok "Configs downloaded (Backup at $backup)"
}
update_zshrc() {
local zshrc="$HOME/.zshrc"
log "Checking .zshrc..."
if [[ ! -f "$zshrc" ]]; then
warn ".zshrc not found. Run option 9 first."
return 1
fi
ok ".zshrc already comes from the managed gist."
ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
}
switch_shell() {
log "Starting Zsh session..."
echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
echo "----------------------------------------"
zsh -l
echo "----------------------------------------"
ok "Returned from Zsh session"
}
# =============================
# INTERACTIVE MENU
# =============================
show_menu() {
echo "==========================================="
echo "WSL Zsh Installer - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-11)"
echo " 1) Update system packages"
echo " 2) Install core packages (zsh, git, vim, etc.)"
echo " 3) Set Timezone (best effort)"
echo " 4) Install Homebrew"
echo " 5) Configure shell (chsh - sets default shell)"
echo " 6) Install Oh My Zsh"
echo " 7) Install plugins (autosuggestions, syntax highlighting)"
echo " 8) Install Spaceship theme"
echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
echo "10) Check ~/.zshrc load order"
echo "11) Switch to Zsh (Temporary Sub-shell)"
echo "12) Quit"
echo "==========================================="
}
run_choices() {
local input
read -p "Select: " input
input="${input//,/ }"
local -a to_run=()
local -a to_exclude=()
for item in $input; do
if [[ "$item" == !* ]]; then
to_exclude+=("${item:1}")
elif [[ "$item" == "0" ]]; then
to_run+=(1 2 3 4 5 6 7 8 9 10 11)
else
to_run+=("$item")
fi
done
for choice in "${to_run[@]}"; do
local skip=false
for ex in "${to_exclude[@]}"; do
if [[ "$choice" == "$ex" ]]; then
skip=true
break
fi
done
$skip && continue
case "$choice" in
1) update_system ;;
2) install_packages ;;
3) set_timezone ;;
4) install_homebrew ;;
5) configure_shell ;;
6) install_oh_my_zsh ;;
7) install_plugins ;;
8) install_theme ;;
9) download_configs ;;
10) update_zshrc ;;
11) switch_shell ;;
12) log "Exiting..."; exit 0 ;;
*) warn "Skipping invalid option: $choice" ;;
esac
echo
done
}
# =============================
# MAIN
# =============================
main() {
check_requirements
while true; do
show_menu
run_choices
read -p "Do you want to run more options? (y/n): " again
[[ "$again" =~ ^[Yy]$ ]] || break
done
ok "WSL Zsh installation/configuration complete!"
}
main "$@"
| 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_SHELL_CHANGE=false |
| 23 | INSTALL_HOMEBREW=false |
| 24 | |
| 25 | GIST_RAW_BASE="https://gist.githubusercontent.com/weehong/c430fefc6e90428dfe6811e0766decf4/raw" |
| 26 | CONFIG_FILES=( |
| 27 | ".alias" |
| 28 | ".func" |
| 29 | ".pathrc" |
| 30 | ".sourcerc" |
| 31 | ".vimrc" |
| 32 | ".zshrc" |
| 33 | ) |
| 34 | |
| 35 | # ============================= |
| 36 | # PLATFORM DETECTION |
| 37 | # ============================= |
| 38 | detect_os() { |
| 39 | if [ -f /etc/os-release ]; then |
| 40 | . /etc/os-release |
| 41 | echo "$ID" |
| 42 | else |
| 43 | echo "unknown" |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | is_wsl() { |
| 48 | grep -qi "microsoft" /proc/version 2>/dev/null |
| 49 | } |
| 50 | |
| 51 | # ============================= |
| 52 | # REQUIREMENTS |
| 53 | # ============================= |
| 54 | check_requirements() { |
| 55 | if [[ $EUID -eq 0 ]]; then |
| 56 | err "Do not run as root" |
| 57 | exit 1 |
| 58 | fi |
| 59 | if ! command -v sudo >/dev/null 2>&1; then |
| 60 | err "sudo required" |
| 61 | exit 1 |
| 62 | fi |
| 63 | if ! is_wsl; then |
| 64 | err "This installer is intended for WSL" |
| 65 | exit 1 |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | # ============================= |
| 70 | # INSTALLATION FUNCTIONS |
| 71 | # ============================= |
| 72 | update_system() { |
| 73 | $SKIP_PACKAGES && return |
| 74 | log "Updating system..." |
| 75 | sudo apt-get update -y |
| 76 | sudo apt-get upgrade -y |
| 77 | ok "System updated" |
| 78 | } |
| 79 | |
| 80 | install_packages() { |
| 81 | $SKIP_PACKAGES && return |
| 82 | log "Installing core packages..." |
| 83 | sudo apt-get install -y \ |
| 84 | zsh git vim curl wget unzip zip build-essential xz-utils |
| 85 | ok "Packages installed" |
| 86 | } |
| 87 | |
| 88 | set_timezone() { |
| 89 | log "Checking timezone configuration..." |
| 90 | if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then |
| 91 | sudo timedatectl set-timezone Asia/Singapore |
| 92 | ok "Timezone set to Asia/Singapore" |
| 93 | return |
| 94 | fi |
| 95 | |
| 96 | warn "Skipping timezone change: timedatectl is not available in this WSL environment" |
| 97 | } |
| 98 | |
| 99 | install_homebrew() { |
| 100 | ! $INSTALL_HOMEBREW && return |
| 101 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 102 | log "Installing Homebrew..." |
| 103 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 104 | ok "Homebrew installed" |
| 105 | } |
| 106 | |
| 107 | configure_shell() { |
| 108 | $SKIP_SHELL_CHANGE && return |
| 109 | log "Changing default shell to zsh..." |
| 110 | local zsh_path |
| 111 | zsh_path="$(command -v zsh)" |
| 112 | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 113 | chsh -s "$zsh_path" |
| 114 | ok "Shell changed (open a new WSL session for it to take effect)" |
| 115 | } |
| 116 | |
| 117 | install_oh_my_zsh() { |
| 118 | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return |
| 119 | log "Installing Oh My Zsh..." |
| 120 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 121 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 122 | ok "Oh My Zsh installed" |
| 123 | } |
| 124 | |
| 125 | install_plugins() { |
| 126 | log "Installing plugins..." |
| 127 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 128 | mkdir -p "$dir" |
| 129 | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 130 | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 131 | ok "Plugins installed" |
| 132 | } |
| 133 | |
| 134 | install_theme() { |
| 135 | log "Installing Spaceship theme..." |
| 136 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 137 | local dir="$themes/spaceship-prompt" |
| 138 | mkdir -p "$themes" |
| 139 | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 140 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 141 | ok "Theme installed" |
| 142 | } |
| 143 | |
| 144 | download_configs() { |
| 145 | log "Downloading custom config files..." |
| 146 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 147 | mkdir -p "$backup" |
| 148 | |
| 149 | for f in "${CONFIG_FILES[@]}"; do |
| 150 | local url="$GIST_RAW_BASE/$f" |
| 151 | local target="$HOME/$f" |
| 152 | local tmp="${target}.tmp.$$" |
| 153 | |
| 154 | if [[ -f "$target" ]]; then |
| 155 | cp "$target" "$backup/" |
| 156 | fi |
| 157 | |
| 158 | log "Fetching $f ..." |
| 159 | if curl -fsSL "$url" -o "$tmp"; then |
| 160 | mv "$tmp" "$target" |
| 161 | else |
| 162 | rm -f "$tmp" |
| 163 | warn "Failed to download $f" |
| 164 | fi |
| 165 | done |
| 166 | |
| 167 | ok "Configs downloaded (Backup at $backup)" |
| 168 | } |
| 169 | |
| 170 | update_zshrc() { |
| 171 | local zshrc="$HOME/.zshrc" |
| 172 | log "Checking .zshrc..." |
| 173 | |
| 174 | if [[ ! -f "$zshrc" ]]; then |
| 175 | warn ".zshrc not found. Run option 9 first." |
| 176 | return 1 |
| 177 | fi |
| 178 | |
| 179 | ok ".zshrc already comes from the managed gist." |
| 180 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 181 | } |
| 182 | |
| 183 | switch_shell() { |
| 184 | log "Starting Zsh session..." |
| 185 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 186 | echo "----------------------------------------" |
| 187 | zsh -l |
| 188 | echo "----------------------------------------" |
| 189 | ok "Returned from Zsh session" |
| 190 | } |
| 191 | |
| 192 | # ============================= |
| 193 | # INTERACTIVE MENU |
| 194 | # ============================= |
| 195 | show_menu() { |
| 196 | echo "===========================================" |
| 197 | echo "WSL Zsh Installer - Choose what to do" |
| 198 | echo "===========================================" |
| 199 | echo " 0) Run ALL steps (1-11)" |
| 200 | echo " 1) Update system packages" |
| 201 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 202 | echo " 3) Set Timezone (best effort)" |
| 203 | echo " 4) Install Homebrew" |
| 204 | echo " 5) Configure shell (chsh - sets default shell)" |
| 205 | echo " 6) Install Oh My Zsh" |
| 206 | echo " 7) Install plugins (autosuggestions, syntax highlighting)" |
| 207 | echo " 8) Install Spaceship theme" |
| 208 | echo " 9) Download custom configs (~/.alias, .vimrc, etc.)" |
| 209 | echo "10) Check ~/.zshrc load order" |
| 210 | echo "11) Switch to Zsh (Temporary Sub-shell)" |
| 211 | echo "12) Quit" |
| 212 | echo "===========================================" |
| 213 | } |
| 214 | |
| 215 | run_choices() { |
| 216 | local input |
| 217 | read -p "Select: " input |
| 218 | input="${input//,/ }" |
| 219 | |
| 220 | local -a to_run=() |
| 221 | local -a to_exclude=() |
| 222 | |
| 223 | for item in $input; do |
| 224 | if [[ "$item" == !* ]]; then |
| 225 | to_exclude+=("${item:1}") |
| 226 | elif [[ "$item" == "0" ]]; then |
| 227 | to_run+=(1 2 3 4 5 6 7 8 9 10 11) |
| 228 | else |
| 229 | to_run+=("$item") |
| 230 | fi |
| 231 | done |
| 232 | |
| 233 | for choice in "${to_run[@]}"; do |
| 234 | local skip=false |
| 235 | |
| 236 | for ex in "${to_exclude[@]}"; do |
| 237 | if [[ "$choice" == "$ex" ]]; then |
| 238 | skip=true |
| 239 | break |
| 240 | fi |
| 241 | done |
| 242 | |
| 243 | $skip && continue |
| 244 | |
| 245 | case "$choice" in |
| 246 | 1) update_system ;; |
| 247 | 2) install_packages ;; |
| 248 | 3) set_timezone ;; |
| 249 | 4) install_homebrew ;; |
| 250 | 5) configure_shell ;; |
| 251 | 6) install_oh_my_zsh ;; |
| 252 | 7) install_plugins ;; |
| 253 | 8) install_theme ;; |
| 254 | 9) download_configs ;; |
| 255 | 10) update_zshrc ;; |
| 256 | 11) switch_shell ;; |
| 257 | 12) log "Exiting..."; exit 0 ;; |
| 258 | *) warn "Skipping invalid option: $choice" ;; |
| 259 | esac |
| 260 | echo |
| 261 | done |
| 262 | } |
| 263 | |
| 264 | # ============================= |
| 265 | # MAIN |
| 266 | # ============================= |
| 267 | main() { |
| 268 | check_requirements |
| 269 | while true; do |
| 270 | show_menu |
| 271 | run_choices |
| 272 | read -p "Do you want to run more options? (y/n): " again |
| 273 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 274 | done |
| 275 | ok "WSL Zsh installation/configuration complete!" |
| 276 | } |
| 277 | |
| 278 | main "$@" |