README.md
· 802 B · Markdown
Raw
# 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)"
```
### Configuration
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
```
### Prompt theme
Run the installer theme option and select either Spaceship or Starship. Starship uses the managed config at `~/.config/starship.toml`.
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)"
Configuration
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/config.sh)"
Prompt theme
Run the installer theme option and select either Spaceship or Starship. Starship uses the managed config at ~/.config/starship.toml.
alias
· 1.1 KiB · Text
Raw
# =============================================================================
# OS-SPECIFIC ALIASES
# =============================================================================
if [[ "$OSTYPE" == "linux-gnu"* ]] && command -v apt-get >/dev/null 2>&1; then
# Linux Only System update & cleanup
alias uu='sudo apt-get update && \
sudo apt-get upgrade -y && \
sudo apt-get full-upgrade -y && \
sudo apt-get autoremove -y && \
sudo apt-get autoclean -y && \
sudo apt-get clean'
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS Only
alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
fi
# =============================================================================
# UNIVERSAL GIT ALIASES (Fixed: Removed broken "$@" from aliases)
# =============================================================================
alias gph='git push'
alias gco='git checkout'
alias gbh='git branch'
alias gmt='git commit'
alias gpl='git pull'
alias grb='git rebase'
alias grt='git reset'
alias gst='git status'
alias grmrf='git checkout -- . && git clean -fd'
| 1 | # ============================================================================= |
| 2 | # OS-SPECIFIC ALIASES |
| 3 | # ============================================================================= |
| 4 | if [[ "$OSTYPE" == "linux-gnu"* ]] && command -v apt-get >/dev/null 2>&1; then |
| 5 | # Linux Only System update & cleanup |
| 6 | alias uu='sudo apt-get update && \ |
| 7 | sudo apt-get upgrade -y && \ |
| 8 | sudo apt-get full-upgrade -y && \ |
| 9 | sudo apt-get autoremove -y && \ |
| 10 | sudo apt-get autoclean -y && \ |
| 11 | sudo apt-get clean' |
| 12 | elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 13 | # macOS Only |
| 14 | alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder' |
| 15 | fi |
| 16 | |
| 17 | # ============================================================================= |
| 18 | # UNIVERSAL GIT ALIASES (Fixed: Removed broken "$@" from aliases) |
| 19 | # ============================================================================= |
| 20 | alias gph='git push' |
| 21 | alias gco='git checkout' |
| 22 | alias gbh='git branch' |
| 23 | alias gmt='git commit' |
| 24 | alias gpl='git pull' |
| 25 | alias grb='git rebase' |
| 26 | alias grt='git reset' |
| 27 | alias gst='git status' |
| 28 | alias grmrf='git checkout -- . && git clean -fd' |
config.sh
· 932 B · Bash
Raw
#!/bin/bash
set -euo pipefail
# Configuration
GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
".config/starship.toml"
)
echo "Starting configuration download..."
for f in "${CONFIG_FILES[@]}"; do
# Remove the leading dot for the URL path
remote_name="${f#.}"
[[ "$f" == ".config/starship.toml" ]] && remote_name="starship.toml"
url="$GIST_RAW_BASE/$remote_name"
target="$HOME/$f"
echo "Downloading $f..."
mkdir -p "$(dirname "$target")"
# Use -f to fail silently on server errors, -s for silent, -L to follow redirects
if curl -fsSL "$url" -o "$target"; then
echo "Successfully updated $target"
else
echo "Error: Failed to download $f from $url" >&2
fi
done
echo "Done! All configuration files have been replaced."
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Configuration |
| 5 | GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 6 | CONFIG_FILES=( |
| 7 | ".alias" |
| 8 | ".func" |
| 9 | ".pathrc" |
| 10 | ".sourcerc" |
| 11 | ".vimrc" |
| 12 | ".zshrc" |
| 13 | ".config/starship.toml" |
| 14 | ) |
| 15 | |
| 16 | echo "Starting configuration download..." |
| 17 | |
| 18 | for f in "${CONFIG_FILES[@]}"; do |
| 19 | # Remove the leading dot for the URL path |
| 20 | remote_name="${f#.}" |
| 21 | [[ "$f" == ".config/starship.toml" ]] && remote_name="starship.toml" |
| 22 | url="$GIST_RAW_BASE/$remote_name" |
| 23 | target="$HOME/$f" |
| 24 | |
| 25 | echo "Downloading $f..." |
| 26 | mkdir -p "$(dirname "$target")" |
| 27 | |
| 28 | # Use -f to fail silently on server errors, -s for silent, -L to follow redirects |
| 29 | if curl -fsSL "$url" -o "$target"; then |
| 30 | echo "Successfully updated $target" |
| 31 | else |
| 32 | echo "Error: Failed to download $f from $url" >&2 |
| 33 | fi |
| 34 | done |
| 35 | |
| 36 | echo "Done! All configuration files have been replaced." |
| 37 |
func
· 6.9 KiB · Text
Raw
# =============================================================================
# CUSTOM FUNCTIONS
# =============================================================================
# -----------------------------------------------------------------------------
# Function: clip (Cross-platform clipboard)
# -----------------------------------------------------------------------------
clip() {
local cmd
local args=()
if command -v pbcopy >/dev/null 2>&1; then
cmd="pbcopy" # macOS
elif grep -qi "microsoft" /proc/version 2>/dev/null && command -v clip.exe >/dev/null 2>&1; then
cmd="clip.exe" # WSL
elif [ "$XDG_SESSION_TYPE" = "wayland" ] && command -v wl-copy >/dev/null 2>&1; then
cmd="wl-copy" # Linux Wayland
elif command -v xclip >/dev/null 2>&1; then
cmd="xclip" # Linux X11 (Fallback 1)
args=("-selection" "clipboard")
elif command -v xsel >/dev/null 2>&1; then
cmd="xsel" # Linux X11 (Fallback 2)
args=("--clipboard" "--input")
else
printf "Error: No supported clipboard utility found.\n" >&2
return 1
fi
if [ $# -gt 0 ]; then
if [ -f "$1" ]; then
"$cmd" "${args[@]}" < "$1"
echo "Copied contents of '$1' to clipboard."
else
printf "Error: File '%s' not found.\n" "$1" >&2
return 1
fi
else
"$cmd" "${args[@]}"
fi
}
# -----------------------------------------------------------------------------
# Function: open_file (Cross-platform file/directory opener)
# -----------------------------------------------------------------------------
open_file() {
local target="${1:-.}"
if [[ "$OSTYPE" == "darwin"* ]]; then
command open "$target"
elif grep -qi "microsoft" /proc/version 2>/dev/null; then
if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then
explorer.exe "$(wslpath -w "$target")"
else
printf "Error: 'wslpath' or 'explorer.exe' not found.\n" >&2
return 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v xdg-open >/dev/null 2>&1; then
xdg-open "$target"
else
printf "Error: 'xdg-open' not found.\n" >&2
return 1
fi
fi
}
alias open='open_file'
# -----------------------------------------------------------------------------
# Function: clear_history (Supports shell and Claude)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Function: clear_history (Supports shell and Claude)
# -----------------------------------------------------------------------------
clear_history() {
case "$1" in
claude)
if [ -d "$HOME/.claude/projects" ]; then
# Use 'yes' to skip prompts and -f to ignore non-existent files
yes | rm -rf "$HOME/.claude/projects"/*
echo "Claude project history/cache cleared."
fi
;;
*)
# 1. Truncate the file
: > "$HISTFILE"
# 2. Clear RAM by briefly setting history size to 0
local old_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$old_histsize
echo "Shell history cleared."
;;
esac
}
# -----------------------------------------------------------------------------
# Function: claude (Includes --yolo and clear shortcuts)
# -----------------------------------------------------------------------------
claude() {
# Shortcut for clearing cache
if [[ "$1" == "clear" ]]; then
clear_history claude
return 0
fi
# Check if binary exists
if ! whence -p claude >/dev/null 2>&1; then
printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2
return 1
fi
# Handle --yolo mode
if [[ "$1" == "--yolo" ]]; then
shift
command claude --dangerously-skip-permissions "$@"
return $?
fi
command claude "$@"
}
# -----------------------------------------------------------------------------
# Function: create (Efficiently create file + parent dirs)
# -----------------------------------------------------------------------------
create() {
if ! command -v install >/dev/null 2>&1; then
printf "Error: 'install' coreutil is not available.\n" >&2
return 1
fi
if [ $# -eq 0 ]; then
printf "Usage: create <file> [file ...]\n" >&2
return 2
fi
for p in "$@"; do
# Expand tilde manually if shell doesn't
[[ "$p" == "~/"* ]] && p="${HOME}/${p#\~/}"
if [ -z "$p" ] || [ "$p" = "/" ]; then
printf "create: refusing to operate on '%s'\n" "$p" >&2
continue
fi
if [ -e "$p" ]; then
printf "create: '%s' already exists. Skipping.\n" "$p" >&2
continue
fi
if install -D /dev/null "$p"; then
echo "Created '$p'"
fi
done
}
# -----------------------------------------------------------------------------
# Function: check_port
# -----------------------------------------------------------------------------
check_port() {
local PORT=$1
if [ -z "$PORT" ]; then
printf "Usage: check_port <port_number>\n" >&2
return 1
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
lsof -i :"$PORT" || echo "Port $PORT is FREE"
else
sudo ss -tulnp | grep ":$PORT " || echo "Port $PORT is FREE"
fi
}
# -----------------------------------------------------------------------------
# Function: append_path (Adds to session PATH if exists)
# -----------------------------------------------------------------------------
append_path() {
local dir="$1"
if [ -d "$dir" ]; then
case ":$PATH:" in
*":$dir:"*) ;;
*) PATH="$PATH:$dir" ;;
esac
elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then
echo "Warning: $dir does not exist." >&2
fi
}
# -----------------------------------------------------------------------------
# Function: add_path_to_config (Fixed awk/sed injection)
# -----------------------------------------------------------------------------
add_path_to_config() {
local new_path="$1"
local config_file="$HOME/.bashrc"
[[ "$SHELL" == *"zsh"* ]] && config_file="$HOME/.zshrc"
if [ -z "$new_path" ]; then
printf "Usage: add_path_to_config <directory>\n" >&2
return 1
fi
new_path="${new_path/#\~/$HOME}"
if [ ! -d "$new_path" ]; then
printf "Warning: '%s' does not exist. Add anyway? (y/N) " "$new_path"
read -r REPLY
[[ ! $REPLY =~ ^[Yy]$ ]] && return 1
fi
# Check if already exists in file
if grep -Fq "append_path \"$new_path\"" "$config_file"; then
printf "Notice: Already in %s.\n" "$config_file"
return 0
fi
# Robust Injection: Use sed to insert before export PATH or just append
if grep -q "^export PATH" "$config_file"; then
sed -i.bak "/^export PATH/i append_path \"$new_path\"" "$config_file"
else
echo "append_path \"$new_path\"" >> "$config_file"
echo "export PATH" >> "$config_file"
fi
printf "✅ Success: Added to %s\n" "$config_file"
append_path "$new_path" && export PATH
}
| 1 | # ============================================================================= |
| 2 | # CUSTOM FUNCTIONS |
| 3 | # ============================================================================= |
| 4 | |
| 5 | # ----------------------------------------------------------------------------- |
| 6 | # Function: clip (Cross-platform clipboard) |
| 7 | # ----------------------------------------------------------------------------- |
| 8 | clip() { |
| 9 | local cmd |
| 10 | local args=() |
| 11 | |
| 12 | if command -v pbcopy >/dev/null 2>&1; then |
| 13 | cmd="pbcopy" # macOS |
| 14 | elif grep -qi "microsoft" /proc/version 2>/dev/null && command -v clip.exe >/dev/null 2>&1; then |
| 15 | cmd="clip.exe" # WSL |
| 16 | elif [ "$XDG_SESSION_TYPE" = "wayland" ] && command -v wl-copy >/dev/null 2>&1; then |
| 17 | cmd="wl-copy" # Linux Wayland |
| 18 | elif command -v xclip >/dev/null 2>&1; then |
| 19 | cmd="xclip" # Linux X11 (Fallback 1) |
| 20 | args=("-selection" "clipboard") |
| 21 | elif command -v xsel >/dev/null 2>&1; then |
| 22 | cmd="xsel" # Linux X11 (Fallback 2) |
| 23 | args=("--clipboard" "--input") |
| 24 | else |
| 25 | printf "Error: No supported clipboard utility found.\n" >&2 |
| 26 | return 1 |
| 27 | fi |
| 28 | |
| 29 | if [ $# -gt 0 ]; then |
| 30 | if [ -f "$1" ]; then |
| 31 | "$cmd" "${args[@]}" < "$1" |
| 32 | echo "Copied contents of '$1' to clipboard." |
| 33 | else |
| 34 | printf "Error: File '%s' not found.\n" "$1" >&2 |
| 35 | return 1 |
| 36 | fi |
| 37 | else |
| 38 | "$cmd" "${args[@]}" |
| 39 | fi |
| 40 | } |
| 41 | |
| 42 | # ----------------------------------------------------------------------------- |
| 43 | # Function: open_file (Cross-platform file/directory opener) |
| 44 | # ----------------------------------------------------------------------------- |
| 45 | open_file() { |
| 46 | local target="${1:-.}" |
| 47 | |
| 48 | if [[ "$OSTYPE" == "darwin"* ]]; then |
| 49 | command open "$target" |
| 50 | elif grep -qi "microsoft" /proc/version 2>/dev/null; then |
| 51 | if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then |
| 52 | explorer.exe "$(wslpath -w "$target")" |
| 53 | else |
| 54 | printf "Error: 'wslpath' or 'explorer.exe' not found.\n" >&2 |
| 55 | return 1 |
| 56 | fi |
| 57 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 58 | if command -v xdg-open >/dev/null 2>&1; then |
| 59 | xdg-open "$target" |
| 60 | else |
| 61 | printf "Error: 'xdg-open' not found.\n" >&2 |
| 62 | return 1 |
| 63 | fi |
| 64 | fi |
| 65 | } |
| 66 | alias open='open_file' |
| 67 | |
| 68 | # ----------------------------------------------------------------------------- |
| 69 | # Function: clear_history (Supports shell and Claude) |
| 70 | # ----------------------------------------------------------------------------- |
| 71 | # ----------------------------------------------------------------------------- |
| 72 | # Function: clear_history (Supports shell and Claude) |
| 73 | # ----------------------------------------------------------------------------- |
| 74 | clear_history() { |
| 75 | case "$1" in |
| 76 | claude) |
| 77 | if [ -d "$HOME/.claude/projects" ]; then |
| 78 | # Use 'yes' to skip prompts and -f to ignore non-existent files |
| 79 | yes | rm -rf "$HOME/.claude/projects"/* |
| 80 | echo "Claude project history/cache cleared." |
| 81 | fi |
| 82 | ;; |
| 83 | |
| 84 | *) |
| 85 | # 1. Truncate the file |
| 86 | : > "$HISTFILE" |
| 87 | |
| 88 | # 2. Clear RAM by briefly setting history size to 0 |
| 89 | local old_histsize=$HISTSIZE |
| 90 | HISTSIZE=0 |
| 91 | HISTSIZE=$old_histsize |
| 92 | |
| 93 | echo "Shell history cleared." |
| 94 | ;; |
| 95 | esac |
| 96 | } |
| 97 | |
| 98 | # ----------------------------------------------------------------------------- |
| 99 | # Function: claude (Includes --yolo and clear shortcuts) |
| 100 | # ----------------------------------------------------------------------------- |
| 101 | claude() { |
| 102 | # Shortcut for clearing cache |
| 103 | if [[ "$1" == "clear" ]]; then |
| 104 | clear_history claude |
| 105 | return 0 |
| 106 | fi |
| 107 | |
| 108 | # Check if binary exists |
| 109 | if ! whence -p claude >/dev/null 2>&1; then |
| 110 | printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2 |
| 111 | return 1 |
| 112 | fi |
| 113 | |
| 114 | # Handle --yolo mode |
| 115 | if [[ "$1" == "--yolo" ]]; then |
| 116 | shift |
| 117 | command claude --dangerously-skip-permissions "$@" |
| 118 | return $? |
| 119 | fi |
| 120 | |
| 121 | command claude "$@" |
| 122 | } |
| 123 | |
| 124 | # ----------------------------------------------------------------------------- |
| 125 | # Function: create (Efficiently create file + parent dirs) |
| 126 | # ----------------------------------------------------------------------------- |
| 127 | create() { |
| 128 | if ! command -v install >/dev/null 2>&1; then |
| 129 | printf "Error: 'install' coreutil is not available.\n" >&2 |
| 130 | return 1 |
| 131 | fi |
| 132 | |
| 133 | if [ $# -eq 0 ]; then |
| 134 | printf "Usage: create <file> [file ...]\n" >&2 |
| 135 | return 2 |
| 136 | fi |
| 137 | |
| 138 | for p in "$@"; do |
| 139 | # Expand tilde manually if shell doesn't |
| 140 | [[ "$p" == "~/"* ]] && p="${HOME}/${p#\~/}" |
| 141 | |
| 142 | if [ -z "$p" ] || [ "$p" = "/" ]; then |
| 143 | printf "create: refusing to operate on '%s'\n" "$p" >&2 |
| 144 | continue |
| 145 | fi |
| 146 | |
| 147 | if [ -e "$p" ]; then |
| 148 | printf "create: '%s' already exists. Skipping.\n" "$p" >&2 |
| 149 | continue |
| 150 | fi |
| 151 | |
| 152 | if install -D /dev/null "$p"; then |
| 153 | echo "Created '$p'" |
| 154 | fi |
| 155 | done |
| 156 | } |
| 157 | |
| 158 | # ----------------------------------------------------------------------------- |
| 159 | # Function: check_port |
| 160 | # ----------------------------------------------------------------------------- |
| 161 | check_port() { |
| 162 | local PORT=$1 |
| 163 | if [ -z "$PORT" ]; then |
| 164 | printf "Usage: check_port <port_number>\n" >&2 |
| 165 | return 1 |
| 166 | fi |
| 167 | |
| 168 | if [[ "$OSTYPE" == "darwin"* ]]; then |
| 169 | lsof -i :"$PORT" || echo "Port $PORT is FREE" |
| 170 | else |
| 171 | sudo ss -tulnp | grep ":$PORT " || echo "Port $PORT is FREE" |
| 172 | fi |
| 173 | } |
| 174 | |
| 175 | # ----------------------------------------------------------------------------- |
| 176 | # Function: append_path (Adds to session PATH if exists) |
| 177 | # ----------------------------------------------------------------------------- |
| 178 | append_path() { |
| 179 | local dir="$1" |
| 180 | if [ -d "$dir" ]; then |
| 181 | case ":$PATH:" in |
| 182 | *":$dir:"*) ;; |
| 183 | *) PATH="$PATH:$dir" ;; |
| 184 | esac |
| 185 | elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then |
| 186 | echo "Warning: $dir does not exist." >&2 |
| 187 | fi |
| 188 | } |
| 189 | |
| 190 | # ----------------------------------------------------------------------------- |
| 191 | # Function: add_path_to_config (Fixed awk/sed injection) |
| 192 | # ----------------------------------------------------------------------------- |
| 193 | add_path_to_config() { |
| 194 | local new_path="$1" |
| 195 | local config_file="$HOME/.bashrc" |
| 196 | [[ "$SHELL" == *"zsh"* ]] && config_file="$HOME/.zshrc" |
| 197 | |
| 198 | if [ -z "$new_path" ]; then |
| 199 | printf "Usage: add_path_to_config <directory>\n" >&2 |
| 200 | return 1 |
| 201 | fi |
| 202 | |
| 203 | new_path="${new_path/#\~/$HOME}" |
| 204 | |
| 205 | if [ ! -d "$new_path" ]; then |
| 206 | printf "Warning: '%s' does not exist. Add anyway? (y/N) " "$new_path" |
| 207 | read -r REPLY |
| 208 | [[ ! $REPLY =~ ^[Yy]$ ]] && return 1 |
| 209 | fi |
| 210 | |
| 211 | # Check if already exists in file |
| 212 | if grep -Fq "append_path \"$new_path\"" "$config_file"; then |
| 213 | printf "Notice: Already in %s.\n" "$config_file" |
| 214 | return 0 |
| 215 | fi |
| 216 | |
| 217 | # Robust Injection: Use sed to insert before export PATH or just append |
| 218 | if grep -q "^export PATH" "$config_file"; then |
| 219 | sed -i.bak "/^export PATH/i append_path \"$new_path\"" "$config_file" |
| 220 | else |
| 221 | echo "append_path \"$new_path\"" >> "$config_file" |
| 222 | echo "export PATH" >> "$config_file" |
| 223 | fi |
| 224 | |
| 225 | printf "✅ Success: Added to %s\n" "$config_file" |
| 226 | append_path "$new_path" && export PATH |
| 227 | } |
pathrc
· 782 B · Text
Raw
# =============================================================================
# ENVIRONMENT & PATH CONFIGURATION
# =============================================================================
# 1. Source functions first
if [[ -f "$HOME/.func" && -r "$HOME/.func" ]]; then
source "$HOME/.func"
fi
# 2. Define Root Variables
export DOTNET_ROOT="$HOME/.dotnet"
# 3. PATH INITIALIZATION
# -----------------------------------------------------------------------------
append_path "$HOME/.local/bin"
append_path "$DOTNET_ROOT"
append_path "$DOTNET_ROOT/tools"
append_path "$HOME/.opencode/bin"
append_path "$HOME/Flutter/bin"
# macOS specific paths
if [[ "$OSTYPE" == "darwin"* ]]; then
append_path "/Applications/Espanso.app/Contents/MacOS"
fi
# Finalize PATH
export PATH
| 1 | # ============================================================================= |
| 2 | # ENVIRONMENT & PATH CONFIGURATION |
| 3 | # ============================================================================= |
| 4 | |
| 5 | # 1. Source functions first |
| 6 | if [[ -f "$HOME/.func" && -r "$HOME/.func" ]]; then |
| 7 | source "$HOME/.func" |
| 8 | fi |
| 9 | |
| 10 | # 2. Define Root Variables |
| 11 | export DOTNET_ROOT="$HOME/.dotnet" |
| 12 | |
| 13 | # 3. PATH INITIALIZATION |
| 14 | # ----------------------------------------------------------------------------- |
| 15 | append_path "$HOME/.local/bin" |
| 16 | append_path "$DOTNET_ROOT" |
| 17 | append_path "$DOTNET_ROOT/tools" |
| 18 | append_path "$HOME/.opencode/bin" |
| 19 | append_path "$HOME/Flutter/bin" |
| 20 | |
| 21 | # macOS specific paths |
| 22 | if [[ "$OSTYPE" == "darwin"* ]]; then |
| 23 | append_path "/Applications/Espanso.app/Contents/MacOS" |
| 24 | fi |
| 25 | |
| 26 | # Finalize PATH |
| 27 | export PATH |
sourcerc
· 2.2 KiB · Text
Raw
# =============================================================================
# FILE: ~/.sourcerc
# Description: Initializes third-party package managers and Oh My Zsh.
# =============================================================================
# Source the custom environment setup file if it exists and is not empty
if [[ -f "$HOME/.local/bin/env" && -r "$HOME/.local/bin/env" ]]; then
source "$HOME/.local/bin/env"
fi
# Source the SDKMAN initialization script if it exists and is not empty
if [[ -f "$HOME/.sdkman/bin/sdkman-init.sh" && -r "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
source "$HOME/.sdkman/bin/sdkman-init.sh"
fi
# Source the NVM initialization script if it exists and is not empty
if [[ -f "$HOME/.nvm/nvm.sh" && -r "$HOME/.nvm/nvm.sh" ]]; then
source "$HOME/.nvm/nvm.sh"
fi
# =============================================================================
# CLAUDE CODE / AI GATEWAY
# =============================================================================
export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic"
# =============================================================================
# OH MY ZSH
# =============================================================================
if [[ -f "$HOME/.oh-my-zsh/oh-my-zsh.sh" && -r "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then
source "$HOME/.oh-my-zsh/oh-my-zsh.sh"
else
echo "Warning: Oh My Zsh not found or is empty."
fi
# =============================================================================
# GOOGLE CLOUD SDK
# =============================================================================
if [[ -f "$HOME/google-cloud-sdk/path.zsh.inc" ]]; then
source "$HOME/google-cloud-sdk/path.zsh.inc"
fi
if [[ -f "$HOME/google-cloud-sdk/completion.zsh.inc" ]]; then
source "$HOME/google-cloud-sdk/completion.zsh.inc"
fi
# =============================================================================
# NVM (Node Version Manager)
# =============================================================================
export NVM_DIR="$HOME/.nvm"
[[ -f "$NVM_DIR/nvm.sh" && -r "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh"
[[ -f "$NVM_DIR/bash_completion" && -r "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion"
| 1 | # ============================================================================= |
| 2 | # FILE: ~/.sourcerc |
| 3 | # Description: Initializes third-party package managers and Oh My Zsh. |
| 4 | # ============================================================================= |
| 5 | |
| 6 | # Source the custom environment setup file if it exists and is not empty |
| 7 | if [[ -f "$HOME/.local/bin/env" && -r "$HOME/.local/bin/env" ]]; then |
| 8 | source "$HOME/.local/bin/env" |
| 9 | fi |
| 10 | |
| 11 | # Source the SDKMAN initialization script if it exists and is not empty |
| 12 | if [[ -f "$HOME/.sdkman/bin/sdkman-init.sh" && -r "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then |
| 13 | source "$HOME/.sdkman/bin/sdkman-init.sh" |
| 14 | fi |
| 15 | |
| 16 | # Source the NVM initialization script if it exists and is not empty |
| 17 | if [[ -f "$HOME/.nvm/nvm.sh" && -r "$HOME/.nvm/nvm.sh" ]]; then |
| 18 | source "$HOME/.nvm/nvm.sh" |
| 19 | fi |
| 20 | |
| 21 | # ============================================================================= |
| 22 | # CLAUDE CODE / AI GATEWAY |
| 23 | # ============================================================================= |
| 24 | export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic" |
| 25 | |
| 26 | # ============================================================================= |
| 27 | # OH MY ZSH |
| 28 | # ============================================================================= |
| 29 | if [[ -f "$HOME/.oh-my-zsh/oh-my-zsh.sh" && -r "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then |
| 30 | source "$HOME/.oh-my-zsh/oh-my-zsh.sh" |
| 31 | else |
| 32 | echo "Warning: Oh My Zsh not found or is empty." |
| 33 | fi |
| 34 | |
| 35 | # ============================================================================= |
| 36 | # GOOGLE CLOUD SDK |
| 37 | # ============================================================================= |
| 38 | if [[ -f "$HOME/google-cloud-sdk/path.zsh.inc" ]]; then |
| 39 | source "$HOME/google-cloud-sdk/path.zsh.inc" |
| 40 | fi |
| 41 | |
| 42 | if [[ -f "$HOME/google-cloud-sdk/completion.zsh.inc" ]]; then |
| 43 | source "$HOME/google-cloud-sdk/completion.zsh.inc" |
| 44 | fi |
| 45 | |
| 46 | # ============================================================================= |
| 47 | # NVM (Node Version Manager) |
| 48 | # ============================================================================= |
| 49 | export NVM_DIR="$HOME/.nvm" |
| 50 | |
| 51 | [[ -f "$NVM_DIR/nvm.sh" && -r "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh" |
| 52 | [[ -f "$NVM_DIR/bash_completion" && -r "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion" |
starship.toml
· 978 B · TOML
Raw
"$schema" = "https://starship.rs/config-schema.json"
add_newline = true
command_timeout = 1000
format = "$time$username$hostname$directory$git_branch$git_status$nodejs$dotnet$java$kotlin$ruby$xcode$swift$golang$docker_context$python$line_break$character"
[time]
disabled = false
format = "[$time]($style) "
time_format = "%R"
style = "dimmed white"
[username]
show_always = true
format = "[$user]($style) "
style_user = "bold cyan"
style_root = "bold red"
[hostname]
ssh_only = true
format = "on [$hostname]($style) "
style = "bold yellow"
[directory]
truncation_length = 3
truncate_to_repo = false
style = "bold blue"
[git_branch]
symbol = "git:"
format = "on [$symbol$branch]($style) "
style = "bold purple"
[git_status]
format = "([$all_status$ahead_behind]($style) )"
style = "bold red"
[character]
success_symbol = "[❯](bold green)"
error_symbol = "[❯](bold red)"
vimcmd_symbol = "[❮](bold green)"
[docker_context]
disabled = true
[package]
disabled = true
| 1 | "$schema" = "https://starship.rs/config-schema.json" |
| 2 | |
| 3 | add_newline = true |
| 4 | command_timeout = 1000 |
| 5 | format = "$time$username$hostname$directory$git_branch$git_status$nodejs$dotnet$java$kotlin$ruby$xcode$swift$golang$docker_context$python$line_break$character" |
| 6 | |
| 7 | [time] |
| 8 | disabled = false |
| 9 | format = "[$time]($style) " |
| 10 | time_format = "%R" |
| 11 | style = "dimmed white" |
| 12 | |
| 13 | [username] |
| 14 | show_always = true |
| 15 | format = "[$user]($style) " |
| 16 | style_user = "bold cyan" |
| 17 | style_root = "bold red" |
| 18 | |
| 19 | [hostname] |
| 20 | ssh_only = true |
| 21 | format = "on [$hostname]($style) " |
| 22 | style = "bold yellow" |
| 23 | |
| 24 | [directory] |
| 25 | truncation_length = 3 |
| 26 | truncate_to_repo = false |
| 27 | style = "bold blue" |
| 28 | |
| 29 | [git_branch] |
| 30 | symbol = "git:" |
| 31 | format = "on [$symbol$branch]($style) " |
| 32 | style = "bold purple" |
| 33 | |
| 34 | [git_status] |
| 35 | format = "([$all_status$ahead_behind]($style) )" |
| 36 | style = "bold red" |
| 37 | |
| 38 | [character] |
| 39 | success_symbol = "[❯](bold green)" |
| 40 | error_symbol = "[❯](bold red)" |
| 41 | vimcmd_symbol = "[❮](bold green)" |
| 42 | |
| 43 | [docker_context] |
| 44 | disabled = true |
| 45 | |
| 46 | [package] |
| 47 | disabled = true |
| 48 |
vimrc
· 2.9 KiB · VimL
Raw
" Enable line numbers
set number
" Enable relative line numbers
set relativenumber
" Enable syntax highlighting
syntax on
" Set colorscheme
colorscheme slate
" Enable file type detection and plugins
filetype plugin indent on
" Set the tab width to 4 spaces
set tabstop=4
set shiftwidth=4
set expandtab
" Enable auto-indentation
set autoindent
set smartindent
" Highlight current line
set cursorline
" Show matching parentheses
set showmatch
" Enable line wrapping
set wrap
" Enable mouse support
set mouse=a
" Enable clipboard access
set clipboard=unnamedplus
" Disable swap file
set noswapfile
" Enable incremental search
set incsearch
" Ignore case in search
set ignorecase
" Override ignorecase if search contains capital letters
set smartcase
" Display line and column number of the cursor position
set ruler
" Set the status line at the bottom
set laststatus=2
" Show command in bottom bar
set showcmd
" Set command height
set cmdheight=2
" Set history lines
set history=1000
" Disable backup file
set nobackup
" Enable persistent undo
set undofile
" Set maximum number of undo levels
set undolevels=1000
" Set undo directory
if has("persistent_undo")
silent !mkdir ~/.vim/undodir > /dev/null 2>&1
set undodir=~/.vim/undodir
endif
" Set search highlighting
set hlsearch
" Enable visual bell
set visualbell
" Set default file encoding
set encoding=utf-8
" Set the leader key to space
let mapleader = " "
" Map <Leader>w to save the file
nnoremap <Leader>w :w<CR>
" Map <Leader>q to quit
nnoremap <Leader>q :q<CR>
" Map <Leader>x to save and quit
nnoremap <Leader>x :wq<CR>
" Enable folding
set foldmethod=syntax
set foldlevelstart=99
" Enable line wrapping at 80 characters
set textwidth=80
set colorcolumn=80
" Add some basic key mappings
" Map jj to escape insert mode
inoremap jj <Esc>
" Map <Leader>n to toggle line numbers
nnoremap <Leader>n :set number!<CR>
" Map <Leader>r to toggle relative line numbers
nnoremap <Leader>r :set relativenumber!<CR>
" Configure plugins (if you use a plugin manager like vim-plug)
" Example with vim-plug:
" call plug#begin('~/.vim/plugged')
" Plug 'tpope/vim-sensible'
" Plug 'preservim/nerdtree'
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
" Plug 'airblade/vim-gitgutter'
" call plug#end()
" NERDTree key mappings
" nnoremap <C-n> :NERDTreeToggle<CR>
" Enable automatic hard wrapping at textwidth (80 chars)
set formatoptions+=t " Auto-wrap text using textwidth
set formatoptions+=c " Auto-wrap comments using textwidth
set formatoptions+=r " Continue comments when pressing Enter
set formatoptions+=o " Continue comments when using 'o' or 'O'
set formatoptions+=q " Allow formatting of comments with 'gq'
set formatoptions+=n " Recognize numbered lists
set formatoptions+=l " Don't break lines that were already long
" Enable syntax highlighting
syntax on
" Increase memory limit for complex syntax parsing (Prevents E363)
set maxmempattern=20000
| 1 | " Enable line numbers |
| 2 | set number |
| 3 | |
| 4 | " Enable relative line numbers |
| 5 | set relativenumber |
| 6 | |
| 7 | " Enable syntax highlighting |
| 8 | syntax on |
| 9 | |
| 10 | " Set colorscheme |
| 11 | colorscheme slate |
| 12 | |
| 13 | " Enable file type detection and plugins |
| 14 | filetype plugin indent on |
| 15 | |
| 16 | " Set the tab width to 4 spaces |
| 17 | set tabstop=4 |
| 18 | set shiftwidth=4 |
| 19 | set expandtab |
| 20 | |
| 21 | " Enable auto-indentation |
| 22 | set autoindent |
| 23 | set smartindent |
| 24 | |
| 25 | " Highlight current line |
| 26 | set cursorline |
| 27 | |
| 28 | " Show matching parentheses |
| 29 | set showmatch |
| 30 | |
| 31 | " Enable line wrapping |
| 32 | set wrap |
| 33 | |
| 34 | " Enable mouse support |
| 35 | set mouse=a |
| 36 | |
| 37 | " Enable clipboard access |
| 38 | set clipboard=unnamedplus |
| 39 | |
| 40 | " Disable swap file |
| 41 | set noswapfile |
| 42 | |
| 43 | " Enable incremental search |
| 44 | set incsearch |
| 45 | |
| 46 | " Ignore case in search |
| 47 | set ignorecase |
| 48 | |
| 49 | " Override ignorecase if search contains capital letters |
| 50 | set smartcase |
| 51 | |
| 52 | " Display line and column number of the cursor position |
| 53 | set ruler |
| 54 | |
| 55 | " Set the status line at the bottom |
| 56 | set laststatus=2 |
| 57 | |
| 58 | " Show command in bottom bar |
| 59 | set showcmd |
| 60 | |
| 61 | " Set command height |
| 62 | set cmdheight=2 |
| 63 | |
| 64 | " Set history lines |
| 65 | set history=1000 |
| 66 | |
| 67 | " Disable backup file |
| 68 | set nobackup |
| 69 | |
| 70 | " Enable persistent undo |
| 71 | set undofile |
| 72 | |
| 73 | " Set maximum number of undo levels |
| 74 | set undolevels=1000 |
| 75 | |
| 76 | " Set undo directory |
| 77 | if has("persistent_undo") |
| 78 | silent !mkdir ~/.vim/undodir > /dev/null 2>&1 |
| 79 | set undodir=~/.vim/undodir |
| 80 | endif |
| 81 | |
| 82 | " Set search highlighting |
| 83 | set hlsearch |
| 84 | |
| 85 | " Enable visual bell |
| 86 | set visualbell |
| 87 | |
| 88 | " Set default file encoding |
| 89 | set encoding=utf-8 |
| 90 | |
| 91 | " Set the leader key to space |
| 92 | let mapleader = " " |
| 93 | |
| 94 | " Map <Leader>w to save the file |
| 95 | nnoremap <Leader>w :w<CR> |
| 96 | |
| 97 | " Map <Leader>q to quit |
| 98 | nnoremap <Leader>q :q<CR> |
| 99 | |
| 100 | " Map <Leader>x to save and quit |
| 101 | nnoremap <Leader>x :wq<CR> |
| 102 | |
| 103 | " Enable folding |
| 104 | set foldmethod=syntax |
| 105 | set foldlevelstart=99 |
| 106 | |
| 107 | " Enable line wrapping at 80 characters |
| 108 | set textwidth=80 |
| 109 | set colorcolumn=80 |
| 110 | |
| 111 | " Add some basic key mappings |
| 112 | " Map jj to escape insert mode |
| 113 | inoremap jj <Esc> |
| 114 | |
| 115 | " Map <Leader>n to toggle line numbers |
| 116 | nnoremap <Leader>n :set number!<CR> |
| 117 | |
| 118 | " Map <Leader>r to toggle relative line numbers |
| 119 | nnoremap <Leader>r :set relativenumber!<CR> |
| 120 | |
| 121 | " Configure plugins (if you use a plugin manager like vim-plug) |
| 122 | " Example with vim-plug: |
| 123 | " call plug#begin('~/.vim/plugged') |
| 124 | " Plug 'tpope/vim-sensible' |
| 125 | " Plug 'preservim/nerdtree' |
| 126 | " Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } |
| 127 | " Plug 'airblade/vim-gitgutter' |
| 128 | " call plug#end() |
| 129 | |
| 130 | " NERDTree key mappings |
| 131 | " nnoremap <C-n> :NERDTreeToggle<CR> |
| 132 | |
| 133 | " Enable automatic hard wrapping at textwidth (80 chars) |
| 134 | set formatoptions+=t " Auto-wrap text using textwidth |
| 135 | set formatoptions+=c " Auto-wrap comments using textwidth |
| 136 | set formatoptions+=r " Continue comments when pressing Enter |
| 137 | set formatoptions+=o " Continue comments when using 'o' or 'O' |
| 138 | set formatoptions+=q " Allow formatting of comments with 'gq' |
| 139 | set formatoptions+=n " Recognize numbered lists |
| 140 | set formatoptions+=l " Don't break lines that were already long |
| 141 | |
| 142 | " Enable syntax highlighting |
| 143 | syntax on |
| 144 | |
| 145 | " Increase memory limit for complex syntax parsing (Prevents E363) |
| 146 | set maxmempattern=20000 |
zsh_macos.sh
· 7.4 KiB · Bash
Raw
#!/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://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
".config/starship.toml"
)
# =============================
# 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_spaceship_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 "Spaceship theme installed"
}
install_starship_config() {
local target="$HOME/.config/starship.toml"
local tmp="${target}.tmp.$$"
log "Installing Starship config..."
mkdir -p "$(dirname "$target")"
if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
mv "$tmp" "$target"
ok "Starship config installed at $target"
else
rm -f "$tmp"
warn "Failed to download Starship config"
fi
}
install_starship_theme() {
if command -v starship >/dev/null 2>&1; then
ok "Starship already installed"
elif command -v brew >/dev/null 2>&1; then
log "Installing Starship with Homebrew..."
brew install starship
ok "Starship installed"
else
log "Installing Starship..."
mkdir -p "$HOME/.local/bin"
curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
ok "Starship installed"
fi
install_starship_config
}
install_theme() {
local choice="${1:-}"
local selected_theme
if [[ -z "$choice" ]]; then
echo "Select prompt theme:"
echo " 1) Spaceship"
echo " 2) Starship"
read -r -p "Select theme [1-2]: " choice
fi
case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
1|spaceship) selected_theme="spaceship" ;;
2|starship) selected_theme="starship" ;;
*) warn "Invalid theme selection: $choice"; return 1 ;;
esac
case "$selected_theme" in
spaceship) install_spaceship_theme ;;
starship) install_starship_theme ;;
esac
printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
ok "Theme selected: $selected_theme"
}
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
# Strip the leading dot for the download URL
local remote_file="${f#.}"
[[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
local url="$GIST_RAW_BASE/$remote_file"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
mkdir -p "$(dirname "$target")"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $remote_file -> $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $remote_file"
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/select prompt theme (Spaceship or Starship)"
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://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 22 | |
| 23 | CONFIG_FILES=( |
| 24 | ".alias" |
| 25 | ".func" |
| 26 | ".pathrc" |
| 27 | ".sourcerc" |
| 28 | ".vimrc" |
| 29 | ".zshrc" |
| 30 | ".config/starship.toml" |
| 31 | ) |
| 32 | |
| 33 | # ============================= |
| 34 | # REQUIREMENTS |
| 35 | # ============================= |
| 36 | check_requirements() { |
| 37 | if [[ $EUID -eq 0 ]]; then |
| 38 | err "Do not run as root on macOS" |
| 39 | exit 1 |
| 40 | fi |
| 41 | } |
| 42 | |
| 43 | # ============================= |
| 44 | # INSTALLATION FUNCTIONS |
| 45 | # ============================= |
| 46 | install_oh_my_zsh() { |
| 47 | if [[ -d "$HOME/.oh-my-zsh" ]]; then |
| 48 | ok "Oh My Zsh already installed" |
| 49 | return |
| 50 | fi |
| 51 | |
| 52 | log "Installing Oh My Zsh..." |
| 53 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 54 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 55 | ok "Oh My Zsh installed" |
| 56 | } |
| 57 | |
| 58 | install_plugins() { |
| 59 | log "Installing plugins..." |
| 60 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 61 | mkdir -p "$dir" |
| 62 | |
| 63 | [[ -d "$dir/zsh-autosuggestions" ]] || \ |
| 64 | git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 65 | |
| 66 | [[ -d "$dir/zsh-syntax-highlighting" ]] || \ |
| 67 | git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 68 | |
| 69 | ok "Plugins installed" |
| 70 | } |
| 71 | |
| 72 | install_spaceship_theme() { |
| 73 | log "Installing Spaceship theme..." |
| 74 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 75 | local dir="$themes/spaceship-prompt" |
| 76 | |
| 77 | mkdir -p "$themes" |
| 78 | [[ -d "$dir" ]] || \ |
| 79 | git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 80 | |
| 81 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 82 | ok "Spaceship theme installed" |
| 83 | } |
| 84 | |
| 85 | install_starship_config() { |
| 86 | local target="$HOME/.config/starship.toml" |
| 87 | local tmp="${target}.tmp.$$" |
| 88 | |
| 89 | log "Installing Starship config..." |
| 90 | mkdir -p "$(dirname "$target")" |
| 91 | |
| 92 | if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then |
| 93 | mv "$tmp" "$target" |
| 94 | ok "Starship config installed at $target" |
| 95 | else |
| 96 | rm -f "$tmp" |
| 97 | warn "Failed to download Starship config" |
| 98 | fi |
| 99 | } |
| 100 | |
| 101 | install_starship_theme() { |
| 102 | if command -v starship >/dev/null 2>&1; then |
| 103 | ok "Starship already installed" |
| 104 | elif command -v brew >/dev/null 2>&1; then |
| 105 | log "Installing Starship with Homebrew..." |
| 106 | brew install starship |
| 107 | ok "Starship installed" |
| 108 | else |
| 109 | log "Installing Starship..." |
| 110 | mkdir -p "$HOME/.local/bin" |
| 111 | curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin" |
| 112 | ok "Starship installed" |
| 113 | fi |
| 114 | |
| 115 | install_starship_config |
| 116 | } |
| 117 | |
| 118 | install_theme() { |
| 119 | local choice="${1:-}" |
| 120 | local selected_theme |
| 121 | |
| 122 | if [[ -z "$choice" ]]; then |
| 123 | echo "Select prompt theme:" |
| 124 | echo " 1) Spaceship" |
| 125 | echo " 2) Starship" |
| 126 | read -r -p "Select theme [1-2]: " choice |
| 127 | fi |
| 128 | |
| 129 | case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in |
| 130 | 1|spaceship) selected_theme="spaceship" ;; |
| 131 | 2|starship) selected_theme="starship" ;; |
| 132 | *) warn "Invalid theme selection: $choice"; return 1 ;; |
| 133 | esac |
| 134 | |
| 135 | case "$selected_theme" in |
| 136 | spaceship) install_spaceship_theme ;; |
| 137 | starship) install_starship_theme ;; |
| 138 | esac |
| 139 | |
| 140 | printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme" |
| 141 | ok "Theme selected: $selected_theme" |
| 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 | # Strip the leading dot for the download URL |
| 151 | local remote_file="${f#.}" |
| 152 | [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml" |
| 153 | local url="$GIST_RAW_BASE/$remote_file" |
| 154 | local target="$HOME/$f" |
| 155 | local tmp="${target}.tmp.$$" |
| 156 | |
| 157 | mkdir -p "$(dirname "$target")" |
| 158 | |
| 159 | if [[ -f "$target" ]]; then |
| 160 | cp "$target" "$backup/" |
| 161 | fi |
| 162 | |
| 163 | log "Fetching $remote_file -> $f ..." |
| 164 | if curl -fsSL "$url" -o "$tmp"; then |
| 165 | mv "$tmp" "$target" |
| 166 | else |
| 167 | rm -f "$tmp" |
| 168 | warn "Failed to download $remote_file" |
| 169 | fi |
| 170 | done |
| 171 | |
| 172 | ok "Configs downloaded (Backup at $backup)" |
| 173 | } |
| 174 | |
| 175 | update_zshrc() { |
| 176 | local zshrc="$HOME/.zshrc" |
| 177 | log "Checking .zshrc..." |
| 178 | |
| 179 | if [[ ! -f "$zshrc" ]]; then |
| 180 | warn ".zshrc not found. Run option 5 first." |
| 181 | return 1 |
| 182 | fi |
| 183 | |
| 184 | ok ".zshrc already comes from the managed gist." |
| 185 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 186 | } |
| 187 | |
| 188 | switch_shell() { |
| 189 | log "Starting Zsh session..." |
| 190 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 191 | echo "----------------------------------------" |
| 192 | zsh -l |
| 193 | echo "----------------------------------------" |
| 194 | ok "Returned from Zsh session" |
| 195 | } |
| 196 | |
| 197 | # ============================= |
| 198 | # INTERACTIVE MENU |
| 199 | # ============================= |
| 200 | show_menu() { |
| 201 | echo "===========================================" |
| 202 | echo "macOS Zsh Setup - Choose what to do" |
| 203 | echo "===========================================" |
| 204 | echo " 0) Run ALL steps (1-7)" |
| 205 | echo " 1) Install Oh My Zsh" |
| 206 | echo " 2) Install plugins (autosuggestions, syntax highlighting)" |
| 207 | echo " 3) Install/select prompt theme (Spaceship or Starship)" |
| 208 | echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)" |
| 209 | echo " 5) Check ~/.zshrc load order" |
| 210 | echo " 6) Switch to Zsh (Temporary Sub-shell)" |
| 211 | echo " 7) 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) |
| 228 | else |
| 229 | to_run+=("$item") |
| 230 | fi |
| 231 | done |
| 232 | |
| 233 | if [[ ${#to_run[@]} -gt 0 ]]; then |
| 234 | for choice in "${to_run[@]}"; do |
| 235 | local skip=false |
| 236 | |
| 237 | if [[ ${#to_exclude[@]} -gt 0 ]]; then |
| 238 | for ex in "${to_exclude[@]}"; do |
| 239 | if [[ "$choice" == "$ex" ]]; then |
| 240 | skip=true |
| 241 | break |
| 242 | fi |
| 243 | done |
| 244 | fi |
| 245 | |
| 246 | $skip && continue |
| 247 | |
| 248 | case "$choice" in |
| 249 | 1) install_oh_my_zsh ;; |
| 250 | 2) install_plugins ;; |
| 251 | 3) install_theme ;; |
| 252 | 4) download_configs ;; |
| 253 | 5) update_zshrc ;; |
| 254 | 6) switch_shell ;; |
| 255 | 7) exit 0 ;; |
| 256 | *) warn "Skipping invalid option: $choice" ;; |
| 257 | esac |
| 258 | echo |
| 259 | done |
| 260 | fi |
| 261 | } |
| 262 | |
| 263 | # ============================= |
| 264 | # MAIN |
| 265 | # ============================= |
| 266 | main() { |
| 267 | check_requirements |
| 268 | while true; do |
| 269 | show_menu |
| 270 | run_choices |
| 271 | read -p "Do you want to run more options? (y/n): " again |
| 272 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 273 | done |
| 274 | ok "macOS configuration complete!" |
| 275 | } |
| 276 | |
| 277 | main "$@" |
| 278 |
zsh_ubuntu.sh
· 9.0 KiB · Bash
Raw
#!/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://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
".config/starship.toml"
)
# =============================
# 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_spaceship_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 "Spaceship theme installed"
}
install_starship_config() {
local target="$HOME/.config/starship.toml"
local tmp="${target}.tmp.$$"
log "Installing Starship config..."
mkdir -p "$(dirname "$target")"
if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
mv "$tmp" "$target"
ok "Starship config installed at $target"
else
rm -f "$tmp"
warn "Failed to download Starship config"
fi
}
install_starship_theme() {
if command -v starship >/dev/null 2>&1; then
ok "Starship already installed"
elif command -v brew >/dev/null 2>&1; then
log "Installing Starship with Homebrew..."
brew install starship
ok "Starship installed"
else
log "Installing Starship..."
mkdir -p "$HOME/.local/bin"
curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
ok "Starship installed"
fi
install_starship_config
}
install_theme() {
local choice="${1:-}"
local selected_theme
if [[ -z "$choice" ]]; then
echo "Select prompt theme:"
echo " 1) Spaceship"
echo " 2) Starship"
read -r -p "Select theme [1-2]: " choice
fi
case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
1|spaceship) selected_theme="spaceship" ;;
2|starship) selected_theme="starship" ;;
*) warn "Invalid theme selection: $choice"; return 1 ;;
esac
case "$selected_theme" in
spaceship) install_spaceship_theme ;;
starship) install_starship_theme ;;
esac
printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
ok "Theme selected: $selected_theme"
}
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
# Strip the leading dot for the download URL
local remote_file="${f#.}"
[[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
local url="$GIST_RAW_BASE/$remote_file"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
mkdir -p "$(dirname "$target")"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $remote_file -> $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $remote_file"
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/select prompt theme (Spaceship or Starship)"
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://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 26 | CONFIG_FILES=( |
| 27 | ".alias" |
| 28 | ".func" |
| 29 | ".pathrc" |
| 30 | ".sourcerc" |
| 31 | ".vimrc" |
| 32 | ".zshrc" |
| 33 | ".config/starship.toml" |
| 34 | ) |
| 35 | |
| 36 | # ============================= |
| 37 | # OS DETECTION |
| 38 | # ============================= |
| 39 | detect_os() { |
| 40 | if [ -f /etc/os-release ]; then |
| 41 | . /etc/os-release |
| 42 | echo "$ID" |
| 43 | else |
| 44 | echo "unknown" |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | # ============================= |
| 49 | # REQUIREMENTS |
| 50 | # ============================= |
| 51 | check_requirements() { |
| 52 | if [[ $EUID -eq 0 ]]; then |
| 53 | err "Do not run as root" |
| 54 | exit 1 |
| 55 | fi |
| 56 | if ! command -v sudo >/dev/null 2>&1; then |
| 57 | err "sudo required" |
| 58 | exit 1 |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | # ============================= |
| 63 | # INSTALLATION FUNCTIONS |
| 64 | # ============================= |
| 65 | update_system() { |
| 66 | $SKIP_PACKAGES && return |
| 67 | log "Updating system..." |
| 68 | sudo apt-get update -y |
| 69 | sudo apt-get upgrade -y |
| 70 | ok "System updated" |
| 71 | } |
| 72 | |
| 73 | install_packages() { |
| 74 | $SKIP_PACKAGES && return |
| 75 | log "Installing core packages..." |
| 76 | sudo apt-get install -y \ |
| 77 | zsh git vim curl wget unzip zip build-essential xz-utils |
| 78 | ok "Packages installed" |
| 79 | } |
| 80 | |
| 81 | set_timezone() { |
| 82 | log "Setting timezone to Asia/Singapore..." |
| 83 | sudo timedatectl set-timezone Asia/Singapore |
| 84 | ok "Timezone set to Asia/Singapore" |
| 85 | } |
| 86 | |
| 87 | install_homebrew() { |
| 88 | ! $INSTALL_HOMEBREW && return |
| 89 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 90 | log "Installing Homebrew..." |
| 91 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 92 | ok "Homebrew installed" |
| 93 | } |
| 94 | |
| 95 | configure_shell() { |
| 96 | $SKIP_SHELL_CHANGE && return |
| 97 | log "Changing default shell to zsh..." |
| 98 | local zsh_path |
| 99 | zsh_path="$(command -v zsh)" |
| 100 | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 101 | chsh -s "$zsh_path" |
| 102 | ok "Shell changed (requires logout/login to take effect)" |
| 103 | } |
| 104 | |
| 105 | install_oh_my_zsh() { |
| 106 | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return |
| 107 | log "Installing Oh My Zsh..." |
| 108 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 109 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 110 | ok "Oh My Zsh installed" |
| 111 | } |
| 112 | |
| 113 | install_plugins() { |
| 114 | log "Installing plugins..." |
| 115 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 116 | mkdir -p "$dir" |
| 117 | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 118 | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 119 | ok "Plugins installed" |
| 120 | } |
| 121 | |
| 122 | install_spaceship_theme() { |
| 123 | log "Installing Spaceship theme..." |
| 124 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 125 | local dir="$themes/spaceship-prompt" |
| 126 | mkdir -p "$themes" |
| 127 | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 128 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 129 | ok "Spaceship theme installed" |
| 130 | } |
| 131 | |
| 132 | install_starship_config() { |
| 133 | local target="$HOME/.config/starship.toml" |
| 134 | local tmp="${target}.tmp.$$" |
| 135 | |
| 136 | log "Installing Starship config..." |
| 137 | mkdir -p "$(dirname "$target")" |
| 138 | |
| 139 | if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then |
| 140 | mv "$tmp" "$target" |
| 141 | ok "Starship config installed at $target" |
| 142 | else |
| 143 | rm -f "$tmp" |
| 144 | warn "Failed to download Starship config" |
| 145 | fi |
| 146 | } |
| 147 | |
| 148 | install_starship_theme() { |
| 149 | if command -v starship >/dev/null 2>&1; then |
| 150 | ok "Starship already installed" |
| 151 | elif command -v brew >/dev/null 2>&1; then |
| 152 | log "Installing Starship with Homebrew..." |
| 153 | brew install starship |
| 154 | ok "Starship installed" |
| 155 | else |
| 156 | log "Installing Starship..." |
| 157 | mkdir -p "$HOME/.local/bin" |
| 158 | curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin" |
| 159 | ok "Starship installed" |
| 160 | fi |
| 161 | |
| 162 | install_starship_config |
| 163 | } |
| 164 | |
| 165 | install_theme() { |
| 166 | local choice="${1:-}" |
| 167 | local selected_theme |
| 168 | |
| 169 | if [[ -z "$choice" ]]; then |
| 170 | echo "Select prompt theme:" |
| 171 | echo " 1) Spaceship" |
| 172 | echo " 2) Starship" |
| 173 | read -r -p "Select theme [1-2]: " choice |
| 174 | fi |
| 175 | |
| 176 | case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in |
| 177 | 1|spaceship) selected_theme="spaceship" ;; |
| 178 | 2|starship) selected_theme="starship" ;; |
| 179 | *) warn "Invalid theme selection: $choice"; return 1 ;; |
| 180 | esac |
| 181 | |
| 182 | case "$selected_theme" in |
| 183 | spaceship) install_spaceship_theme ;; |
| 184 | starship) install_starship_theme ;; |
| 185 | esac |
| 186 | |
| 187 | printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme" |
| 188 | ok "Theme selected: $selected_theme" |
| 189 | } |
| 190 | |
| 191 | download_configs() { |
| 192 | log "Downloading custom config files..." |
| 193 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 194 | mkdir -p "$backup" |
| 195 | |
| 196 | for f in "${CONFIG_FILES[@]}"; do |
| 197 | # Strip the leading dot for the download URL |
| 198 | local remote_file="${f#.}" |
| 199 | [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml" |
| 200 | local url="$GIST_RAW_BASE/$remote_file" |
| 201 | local target="$HOME/$f" |
| 202 | local tmp="${target}.tmp.$$" |
| 203 | |
| 204 | mkdir -p "$(dirname "$target")" |
| 205 | |
| 206 | if [[ -f "$target" ]]; then |
| 207 | cp "$target" "$backup/" |
| 208 | fi |
| 209 | |
| 210 | log "Fetching $remote_file -> $f ..." |
| 211 | if curl -fsSL "$url" -o "$tmp"; then |
| 212 | mv "$tmp" "$target" |
| 213 | else |
| 214 | rm -f "$tmp" |
| 215 | warn "Failed to download $remote_file" |
| 216 | fi |
| 217 | done |
| 218 | |
| 219 | ok "Configs downloaded (Backup at $backup)" |
| 220 | } |
| 221 | |
| 222 | update_zshrc() { |
| 223 | local zshrc="$HOME/.zshrc" |
| 224 | log "Checking .zshrc..." |
| 225 | |
| 226 | if [[ ! -f "$zshrc" ]]; then |
| 227 | warn ".zshrc not found. Run option 9 first." |
| 228 | return 1 |
| 229 | fi |
| 230 | |
| 231 | ok ".zshrc already comes from the managed gist." |
| 232 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 233 | } |
| 234 | |
| 235 | switch_shell() { |
| 236 | log "Starting Zsh session..." |
| 237 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 238 | echo "----------------------------------------" |
| 239 | zsh -l |
| 240 | echo "----------------------------------------" |
| 241 | ok "Returned from Zsh session" |
| 242 | } |
| 243 | |
| 244 | # ============================= |
| 245 | # INTERACTIVE MENU |
| 246 | # ============================= |
| 247 | show_menu() { |
| 248 | echo "===========================================" |
| 249 | echo "Zsh Installer - Choose what to do" |
| 250 | echo "===========================================" |
| 251 | echo " 0) Run ALL steps (1-11)" |
| 252 | echo " 1) Update system packages" |
| 253 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 254 | echo " 3) Set Timezone (Asia/Singapore)" |
| 255 | echo " 4) Install Homebrew" |
| 256 | echo " 5) Configure shell (chsh - sets default shell)" |
| 257 | echo " 6) Install Oh My Zsh" |
| 258 | echo " 7) Install plugins (autosuggestions, syntax highlighting)" |
| 259 | echo " 8) Install/select prompt theme (Spaceship or Starship)" |
| 260 | echo " 9) Download custom configs (~/.alias, .vimrc, etc.)" |
| 261 | echo "10) Check ~/.zshrc load order" |
| 262 | echo "11) Switch to Zsh (Temporary Sub-shell)" |
| 263 | echo "12) Quit" |
| 264 | echo "===========================================" |
| 265 | } |
| 266 | |
| 267 | run_choices() { |
| 268 | local input |
| 269 | read -p "Select: " input |
| 270 | input="${input//,/ }" |
| 271 | |
| 272 | local -a to_run=() |
| 273 | local -a to_exclude=() |
| 274 | |
| 275 | for item in $input; do |
| 276 | if [[ "$item" == !* ]]; then |
| 277 | to_exclude+=("${item:1}") |
| 278 | elif [[ "$item" == "0" ]]; then |
| 279 | to_run+=(1 2 3 4 5 6 7 8 9 10 11) |
| 280 | else |
| 281 | to_run+=("$item") |
| 282 | fi |
| 283 | done |
| 284 | |
| 285 | for choice in "${to_run[@]}"; do |
| 286 | local skip=false |
| 287 | |
| 288 | for ex in "${to_exclude[@]}"; do |
| 289 | if [[ "$choice" == "$ex" ]]; then |
| 290 | skip=true |
| 291 | break |
| 292 | fi |
| 293 | done |
| 294 | |
| 295 | $skip && continue |
| 296 | |
| 297 | case "$choice" in |
| 298 | 1) update_system ;; |
| 299 | 2) install_packages ;; |
| 300 | 3) set_timezone ;; |
| 301 | 4) install_homebrew ;; |
| 302 | 5) configure_shell ;; |
| 303 | 6) install_oh_my_zsh ;; |
| 304 | 7) install_plugins ;; |
| 305 | 8) install_theme ;; |
| 306 | 9) download_configs ;; |
| 307 | 10) update_zshrc ;; |
| 308 | 11) switch_shell ;; |
| 309 | 12) log "Exiting..."; exit 0 ;; |
| 310 | *) warn "Skipping invalid option: $choice" ;; |
| 311 | esac |
| 312 | echo |
| 313 | done |
| 314 | } |
| 315 | |
| 316 | # ============================= |
| 317 | # MAIN |
| 318 | # ============================= |
| 319 | main() { |
| 320 | check_requirements |
| 321 | while true; do |
| 322 | show_menu |
| 323 | run_choices |
| 324 | read -p "Do you want to run more options? (y/n): " again |
| 325 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 326 | done |
| 327 | ok "Zsh installation/configuration complete!" |
| 328 | } |
| 329 | |
| 330 | main "$@" |
| 331 |
zsh_wsl.sh
· 9.4 KiB · Bash
Raw
#!/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://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD"
CONFIG_FILES=(
".alias"
".func"
".pathrc"
".sourcerc"
".vimrc"
".zshrc"
".config/starship.toml"
)
# =============================
# 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_spaceship_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 "Spaceship theme installed"
}
install_starship_config() {
local target="$HOME/.config/starship.toml"
local tmp="${target}.tmp.$$"
log "Installing Starship config..."
mkdir -p "$(dirname "$target")"
if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then
mv "$tmp" "$target"
ok "Starship config installed at $target"
else
rm -f "$tmp"
warn "Failed to download Starship config"
fi
}
install_starship_theme() {
if command -v starship >/dev/null 2>&1; then
ok "Starship already installed"
elif command -v brew >/dev/null 2>&1; then
log "Installing Starship with Homebrew..."
brew install starship
ok "Starship installed"
else
log "Installing Starship..."
mkdir -p "$HOME/.local/bin"
curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
ok "Starship installed"
fi
install_starship_config
}
install_theme() {
local choice="${1:-}"
local selected_theme
if [[ -z "$choice" ]]; then
echo "Select prompt theme:"
echo " 1) Spaceship"
echo " 2) Starship"
read -r -p "Select theme [1-2]: " choice
fi
case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in
1|spaceship) selected_theme="spaceship" ;;
2|starship) selected_theme="starship" ;;
*) warn "Invalid theme selection: $choice"; return 1 ;;
esac
case "$selected_theme" in
spaceship) install_spaceship_theme ;;
starship) install_starship_theme ;;
esac
printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme"
ok "Theme selected: $selected_theme"
}
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
# Strip the leading dot for the download URL
local remote_file="${f#.}"
[[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml"
local url="$GIST_RAW_BASE/$remote_file"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
mkdir -p "$(dirname "$target")"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $remote_file -> $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $remote_file"
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/select prompt theme (Spaceship or Starship)"
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://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 26 | CONFIG_FILES=( |
| 27 | ".alias" |
| 28 | ".func" |
| 29 | ".pathrc" |
| 30 | ".sourcerc" |
| 31 | ".vimrc" |
| 32 | ".zshrc" |
| 33 | ".config/starship.toml" |
| 34 | ) |
| 35 | |
| 36 | # ============================= |
| 37 | # PLATFORM DETECTION |
| 38 | # ============================= |
| 39 | detect_os() { |
| 40 | if [ -f /etc/os-release ]; then |
| 41 | . /etc/os-release |
| 42 | echo "$ID" |
| 43 | else |
| 44 | echo "unknown" |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | is_wsl() { |
| 49 | grep -qi "microsoft" /proc/version 2>/dev/null |
| 50 | } |
| 51 | |
| 52 | # ============================= |
| 53 | # REQUIREMENTS |
| 54 | # ============================= |
| 55 | check_requirements() { |
| 56 | if [[ $EUID -eq 0 ]]; then |
| 57 | err "Do not run as root" |
| 58 | exit 1 |
| 59 | fi |
| 60 | if ! command -v sudo >/dev/null 2>&1; then |
| 61 | err "sudo required" |
| 62 | exit 1 |
| 63 | fi |
| 64 | if ! is_wsl; then |
| 65 | err "This installer is intended for WSL" |
| 66 | exit 1 |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | # ============================= |
| 71 | # INSTALLATION FUNCTIONS |
| 72 | # ============================= |
| 73 | update_system() { |
| 74 | $SKIP_PACKAGES && return |
| 75 | log "Updating system..." |
| 76 | sudo apt-get update -y |
| 77 | sudo apt-get upgrade -y |
| 78 | ok "System updated" |
| 79 | } |
| 80 | |
| 81 | install_packages() { |
| 82 | $SKIP_PACKAGES && return |
| 83 | log "Installing core packages..." |
| 84 | sudo apt-get install -y \ |
| 85 | zsh git vim curl wget unzip zip build-essential xz-utils |
| 86 | ok "Packages installed" |
| 87 | } |
| 88 | |
| 89 | set_timezone() { |
| 90 | log "Checking timezone configuration..." |
| 91 | if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then |
| 92 | sudo timedatectl set-timezone Asia/Singapore |
| 93 | ok "Timezone set to Asia/Singapore" |
| 94 | return |
| 95 | fi |
| 96 | |
| 97 | warn "Skipping timezone change: timedatectl is not available in this WSL environment" |
| 98 | } |
| 99 | |
| 100 | install_homebrew() { |
| 101 | ! $INSTALL_HOMEBREW && return |
| 102 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 103 | log "Installing Homebrew..." |
| 104 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 105 | ok "Homebrew installed" |
| 106 | } |
| 107 | |
| 108 | configure_shell() { |
| 109 | $SKIP_SHELL_CHANGE && return |
| 110 | log "Changing default shell to zsh..." |
| 111 | local zsh_path |
| 112 | zsh_path="$(command -v zsh)" |
| 113 | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 114 | chsh -s "$zsh_path" |
| 115 | ok "Shell changed (open a new WSL session for it to take effect)" |
| 116 | } |
| 117 | |
| 118 | install_oh_my_zsh() { |
| 119 | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return |
| 120 | log "Installing Oh My Zsh..." |
| 121 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 122 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 123 | ok "Oh My Zsh installed" |
| 124 | } |
| 125 | |
| 126 | install_plugins() { |
| 127 | log "Installing plugins..." |
| 128 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 129 | mkdir -p "$dir" |
| 130 | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 131 | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 132 | ok "Plugins installed" |
| 133 | } |
| 134 | |
| 135 | install_spaceship_theme() { |
| 136 | log "Installing Spaceship theme..." |
| 137 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 138 | local dir="$themes/spaceship-prompt" |
| 139 | mkdir -p "$themes" |
| 140 | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 141 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 142 | ok "Spaceship theme installed" |
| 143 | } |
| 144 | |
| 145 | install_starship_config() { |
| 146 | local target="$HOME/.config/starship.toml" |
| 147 | local tmp="${target}.tmp.$$" |
| 148 | |
| 149 | log "Installing Starship config..." |
| 150 | mkdir -p "$(dirname "$target")" |
| 151 | |
| 152 | if curl -fsSL "$GIST_RAW_BASE/starship.toml" -o "$tmp"; then |
| 153 | mv "$tmp" "$target" |
| 154 | ok "Starship config installed at $target" |
| 155 | else |
| 156 | rm -f "$tmp" |
| 157 | warn "Failed to download Starship config" |
| 158 | fi |
| 159 | } |
| 160 | |
| 161 | install_starship_theme() { |
| 162 | if command -v starship >/dev/null 2>&1; then |
| 163 | ok "Starship already installed" |
| 164 | elif command -v brew >/dev/null 2>&1; then |
| 165 | log "Installing Starship with Homebrew..." |
| 166 | brew install starship |
| 167 | ok "Starship installed" |
| 168 | else |
| 169 | log "Installing Starship..." |
| 170 | mkdir -p "$HOME/.local/bin" |
| 171 | curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin" |
| 172 | ok "Starship installed" |
| 173 | fi |
| 174 | |
| 175 | install_starship_config |
| 176 | } |
| 177 | |
| 178 | install_theme() { |
| 179 | local choice="${1:-}" |
| 180 | local selected_theme |
| 181 | |
| 182 | if [[ -z "$choice" ]]; then |
| 183 | echo "Select prompt theme:" |
| 184 | echo " 1) Spaceship" |
| 185 | echo " 2) Starship" |
| 186 | read -r -p "Select theme [1-2]: " choice |
| 187 | fi |
| 188 | |
| 189 | case "$(printf '%s' "$choice" | tr '[:upper:]' '[:lower:]')" in |
| 190 | 1|spaceship) selected_theme="spaceship" ;; |
| 191 | 2|starship) selected_theme="starship" ;; |
| 192 | *) warn "Invalid theme selection: $choice"; return 1 ;; |
| 193 | esac |
| 194 | |
| 195 | case "$selected_theme" in |
| 196 | spaceship) install_spaceship_theme ;; |
| 197 | starship) install_starship_theme ;; |
| 198 | esac |
| 199 | |
| 200 | printf "%s\n" "$selected_theme" > "$HOME/.zsh_theme" |
| 201 | ok "Theme selected: $selected_theme" |
| 202 | } |
| 203 | |
| 204 | download_configs() { |
| 205 | log "Downloading custom config files..." |
| 206 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 207 | mkdir -p "$backup" |
| 208 | |
| 209 | for f in "${CONFIG_FILES[@]}"; do |
| 210 | # Strip the leading dot for the download URL |
| 211 | local remote_file="${f#.}" |
| 212 | [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml" |
| 213 | local url="$GIST_RAW_BASE/$remote_file" |
| 214 | local target="$HOME/$f" |
| 215 | local tmp="${target}.tmp.$$" |
| 216 | |
| 217 | mkdir -p "$(dirname "$target")" |
| 218 | |
| 219 | if [[ -f "$target" ]]; then |
| 220 | cp "$target" "$backup/" |
| 221 | fi |
| 222 | |
| 223 | log "Fetching $remote_file -> $f ..." |
| 224 | if curl -fsSL "$url" -o "$tmp"; then |
| 225 | mv "$tmp" "$target" |
| 226 | else |
| 227 | rm -f "$tmp" |
| 228 | warn "Failed to download $remote_file" |
| 229 | fi |
| 230 | done |
| 231 | |
| 232 | ok "Configs downloaded (Backup at $backup)" |
| 233 | } |
| 234 | |
| 235 | update_zshrc() { |
| 236 | local zshrc="$HOME/.zshrc" |
| 237 | log "Checking .zshrc..." |
| 238 | |
| 239 | if [[ ! -f "$zshrc" ]]; then |
| 240 | warn ".zshrc not found. Run option 9 first." |
| 241 | return 1 |
| 242 | fi |
| 243 | |
| 244 | ok ".zshrc already comes from the managed gist." |
| 245 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 246 | } |
| 247 | |
| 248 | switch_shell() { |
| 249 | log "Starting Zsh session..." |
| 250 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 251 | echo "----------------------------------------" |
| 252 | zsh -l |
| 253 | echo "----------------------------------------" |
| 254 | ok "Returned from Zsh session" |
| 255 | } |
| 256 | |
| 257 | # ============================= |
| 258 | # INTERACTIVE MENU |
| 259 | # ============================= |
| 260 | show_menu() { |
| 261 | echo "===========================================" |
| 262 | echo "WSL Zsh Installer - Choose what to do" |
| 263 | echo "===========================================" |
| 264 | echo " 0) Run ALL steps (1-11)" |
| 265 | echo " 1) Update system packages" |
| 266 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 267 | echo " 3) Set Timezone (best effort)" |
| 268 | echo " 4) Install Homebrew" |
| 269 | echo " 5) Configure shell (chsh - sets default shell)" |
| 270 | echo " 6) Install Oh My Zsh" |
| 271 | echo " 7) Install plugins (autosuggestions, syntax highlighting)" |
| 272 | echo " 8) Install/select prompt theme (Spaceship or Starship)" |
| 273 | echo " 9) Download custom configs (~/.alias, .vimrc, etc.)" |
| 274 | echo "10) Check ~/.zshrc load order" |
| 275 | echo "11) Switch to Zsh (Temporary Sub-shell)" |
| 276 | echo "12) Quit" |
| 277 | echo "===========================================" |
| 278 | } |
| 279 | |
| 280 | run_choices() { |
| 281 | local input |
| 282 | read -p "Select: " input |
| 283 | input="${input//,/ }" |
| 284 | |
| 285 | local -a to_run=() |
| 286 | local -a to_exclude=() |
| 287 | |
| 288 | for item in $input; do |
| 289 | if [[ "$item" == !* ]]; then |
| 290 | to_exclude+=("${item:1}") |
| 291 | elif [[ "$item" == "0" ]]; then |
| 292 | to_run+=(1 2 3 4 5 6 7 8 9 10 11) |
| 293 | else |
| 294 | to_run+=("$item") |
| 295 | fi |
| 296 | done |
| 297 | |
| 298 | for choice in "${to_run[@]}"; do |
| 299 | local skip=false |
| 300 | |
| 301 | for ex in "${to_exclude[@]}"; do |
| 302 | if [[ "$choice" == "$ex" ]]; then |
| 303 | skip=true |
| 304 | break |
| 305 | fi |
| 306 | done |
| 307 | |
| 308 | $skip && continue |
| 309 | |
| 310 | case "$choice" in |
| 311 | 1) update_system ;; |
| 312 | 2) install_packages ;; |
| 313 | 3) set_timezone ;; |
| 314 | 4) install_homebrew ;; |
| 315 | 5) configure_shell ;; |
| 316 | 6) install_oh_my_zsh ;; |
| 317 | 7) install_plugins ;; |
| 318 | 8) install_theme ;; |
| 319 | 9) download_configs ;; |
| 320 | 10) update_zshrc ;; |
| 321 | 11) switch_shell ;; |
| 322 | 12) log "Exiting..."; exit 0 ;; |
| 323 | *) warn "Skipping invalid option: $choice" ;; |
| 324 | esac |
| 325 | echo |
| 326 | done |
| 327 | } |
| 328 | |
| 329 | # ============================= |
| 330 | # MAIN |
| 331 | # ============================= |
| 332 | main() { |
| 333 | check_requirements |
| 334 | while true; do |
| 335 | show_menu |
| 336 | run_choices |
| 337 | read -p "Do you want to run more options? (y/n): " again |
| 338 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 339 | done |
| 340 | ok "WSL Zsh installation/configuration complete!" |
| 341 | } |
| 342 | |
| 343 | main "$@" |
| 344 |
zshrc
· 3.5 KiB · Bash
Raw
# =============================================================================
# 1. ZSH THEME & PLUGINS (Must be defined before Oh My Zsh loads)
# =============================================================================
export ZSH="$HOME/.oh-my-zsh"
source_if_readable() {
local file="$1"
if [[ -f "$file" && -r "$file" ]]; then
source "$file"
fi
}
ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-}"
if [[ -z "$ZSH_THEME_CHOICE" && -f "$HOME/.zsh_theme" ]]; then
ZSH_THEME_CHOICE="$(<"$HOME/.zsh_theme")"
fi
ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-spaceship}"
case "$ZSH_THEME_CHOICE" in
starship)
ZSH_THEME=""
;;
spaceship|*)
ZSH_THEME="spaceship"
SPACESHIP_PROMPT_ORDER=(
time # Time stamps section
user # Username section
dir # Current directory section
git # Git section (git_branch + git_status)
node # Node.js section
dotnet # .NET section
java # Java section
kotlin # Kotlin section
ruby # Ruby section
xcode # Xcode section
swift # Swift section
golang # Go section
docker # Docker section
venv # virtualenv section
line_sep # Line break
char # Prompt character
)
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_SEPARATE_LINE=true
SPACESHIP_PROMPT_ADD_NEWLINE=true
SPACESHIP_CHAR_SYMBOL="❯"
SPACESHIP_CHAR_SUFFIX=" "
SPACESHIP_DOCKER_CONTEXT_SHOW=false
if [[ $(uname) == "Darwin" ]]; then
# is the Apple logo in Nerd Fonts
SPACESHIP_USER_SUFFIX="%F{cyan} [ ]%f "
elif [[ $(uname) == "Linux" ]]; then
# is the Ubuntu logo in Nerd Fonts
SPACESHIP_USER_SUFFIX="%F{yellow} [ ]%f "
else
SPACESHIP_USER_SUFFIX=" "
fi
;;
esac
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
# Initialize Oh My Zsh (Crucial for themes and plugins to work)
source_if_readable "$ZSH/oh-my-zsh.sh"
# =============================================================================
# 2. THIRD-PARTY INITIALIZATION (SDKMAN, NVM, Oh My Zsh)
# =============================================================================
source_if_readable "$HOME/.sourcerc"
# =============================================================================
# 3. CUSTOM OVERRIDES (Functions must load before Path Management)
# =============================================================================
source_if_readable "$HOME/.func"
# =============================================================================
# 4. PATH MANAGEMENT (Relies on append_path from .func)
# =============================================================================
source_if_readable "$HOME/.pathrc"
# =============================================================================
# 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh)
# =============================================================================
source_if_readable "$HOME/.alias"
if [[ "$ZSH_THEME_CHOICE" == "starship" ]]; then
if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
export STARSHIP_CONFIG="$HOME/.config/starship.toml"
fi
if command -v starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
else
echo "Warning: Starship selected but starship is not installed."
fi
fi
| 1 | # ============================================================================= |
| 2 | # 1. ZSH THEME & PLUGINS (Must be defined before Oh My Zsh loads) |
| 3 | # ============================================================================= |
| 4 | export ZSH="$HOME/.oh-my-zsh" |
| 5 | |
| 6 | source_if_readable() { |
| 7 | local file="$1" |
| 8 | if [[ -f "$file" && -r "$file" ]]; then |
| 9 | source "$file" |
| 10 | fi |
| 11 | } |
| 12 | |
| 13 | ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-}" |
| 14 | if [[ -z "$ZSH_THEME_CHOICE" && -f "$HOME/.zsh_theme" ]]; then |
| 15 | ZSH_THEME_CHOICE="$(<"$HOME/.zsh_theme")" |
| 16 | fi |
| 17 | ZSH_THEME_CHOICE="${ZSH_THEME_CHOICE:-spaceship}" |
| 18 | |
| 19 | case "$ZSH_THEME_CHOICE" in |
| 20 | starship) |
| 21 | ZSH_THEME="" |
| 22 | ;; |
| 23 | spaceship|*) |
| 24 | ZSH_THEME="spaceship" |
| 25 | |
| 26 | SPACESHIP_PROMPT_ORDER=( |
| 27 | time # Time stamps section |
| 28 | user # Username section |
| 29 | dir # Current directory section |
| 30 | git # Git section (git_branch + git_status) |
| 31 | node # Node.js section |
| 32 | dotnet # .NET section |
| 33 | java # Java section |
| 34 | kotlin # Kotlin section |
| 35 | ruby # Ruby section |
| 36 | xcode # Xcode section |
| 37 | swift # Swift section |
| 38 | golang # Go section |
| 39 | docker # Docker section |
| 40 | venv # virtualenv section |
| 41 | line_sep # Line break |
| 42 | char # Prompt character |
| 43 | ) |
| 44 | |
| 45 | SPACESHIP_USER_SHOW=always |
| 46 | SPACESHIP_PROMPT_SEPARATE_LINE=true |
| 47 | SPACESHIP_PROMPT_ADD_NEWLINE=true |
| 48 | SPACESHIP_CHAR_SYMBOL="❯" |
| 49 | SPACESHIP_CHAR_SUFFIX=" " |
| 50 | SPACESHIP_DOCKER_CONTEXT_SHOW=false |
| 51 | |
| 52 | if [[ $(uname) == "Darwin" ]]; then |
| 53 | # is the Apple logo in Nerd Fonts |
| 54 | SPACESHIP_USER_SUFFIX="%F{cyan} [ ]%f " |
| 55 | elif [[ $(uname) == "Linux" ]]; then |
| 56 | # is the Ubuntu logo in Nerd Fonts |
| 57 | SPACESHIP_USER_SUFFIX="%F{yellow} [ ]%f " |
| 58 | else |
| 59 | SPACESHIP_USER_SUFFIX=" " |
| 60 | fi |
| 61 | ;; |
| 62 | esac |
| 63 | |
| 64 | plugins=(git zsh-syntax-highlighting zsh-autosuggestions) |
| 65 | |
| 66 | # Initialize Oh My Zsh (Crucial for themes and plugins to work) |
| 67 | source_if_readable "$ZSH/oh-my-zsh.sh" |
| 68 | |
| 69 | # ============================================================================= |
| 70 | # 2. THIRD-PARTY INITIALIZATION (SDKMAN, NVM, Oh My Zsh) |
| 71 | # ============================================================================= |
| 72 | source_if_readable "$HOME/.sourcerc" |
| 73 | |
| 74 | # ============================================================================= |
| 75 | # 3. CUSTOM OVERRIDES (Functions must load before Path Management) |
| 76 | # ============================================================================= |
| 77 | source_if_readable "$HOME/.func" |
| 78 | |
| 79 | # ============================================================================= |
| 80 | # 4. PATH MANAGEMENT (Relies on append_path from .func) |
| 81 | # ============================================================================= |
| 82 | source_if_readable "$HOME/.pathrc" |
| 83 | |
| 84 | # ============================================================================= |
| 85 | # 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh) |
| 86 | # ============================================================================= |
| 87 | source_if_readable "$HOME/.alias" |
| 88 | |
| 89 | if [[ "$ZSH_THEME_CHOICE" == "starship" ]]; then |
| 90 | if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then |
| 91 | export STARSHIP_CONFIG="$HOME/.config/starship.toml" |
| 92 | fi |
| 93 | |
| 94 | if command -v starship >/dev/null 2>&1; then |
| 95 | eval "$(starship init zsh)" |
| 96 | else |
| 97 | echo "Warning: Starship selected but starship is not installed." |
| 98 | fi |
| 99 | fi |
| 100 |