README.md
· 1.0 KiB · Markdown
Sin formato
# 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)"
```
### Shell framework and prompt
The installers use Oh My Zsh for framework features and plugins, with the OMZ theme disabled:
```zsh
ZSH_THEME=""
source "$ZSH/oh-my-zsh.sh"
eval "$(starship init zsh)"
```
Starship owns the prompt and loads after Oh My Zsh. The managed Starship config is installed at `~/.config/starship.toml`. A Nerd Font is required for the Powerline symbols.
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)"
Shell framework and prompt
The installers use Oh My Zsh for framework features and plugins, with the OMZ theme disabled:
ZSH_THEME=""
source "$ZSH/oh-my-zsh.sh"
eval "$(starship init zsh)"
Starship owns the prompt and loads after Oh My Zsh. The managed Starship config is installed at ~/.config/starship.toml. A Nerd Font is required for the Powerline symbols.
alias
· 1.1 KiB · Text
Sin formato
# =============================================================================
# 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
Sin formato
#!/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
Sin formato
# =============================================================================
# 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
Sin formato
# =============================================================================
# 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.0 KiB · Text
Sin formato
# =============================================================================
# FILE: ~/.sourcerc
# Description: Initializes third-party package managers and external tools.
# =============================================================================
# =============================================================================
# GENERAL ENV
# =============================================================================
if [[ -f "$HOME/.local/bin/env" && -r "$HOME/.local/bin/env" ]]; then
source "$HOME/.local/bin/env"
fi
# =============================================================================
# CLAUDE CODE / AI GATEWAY
# =============================================================================
export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic"
# =============================================================================
# SDKMAN (Java/Kotlin/Scala Version Manager)
# =============================================================================
export SDKMAN_DIR="$HOME/.sdkman"
if [[ -f "$SDKMAN_DIR/bin/sdkman-init.sh" && -r "$SDKMAN_DIR/bin/sdkman-init.sh" ]]; then
source "$SDKMAN_DIR/bin/sdkman-init.sh"
fi
# =============================================================================
# NVM (Node Version Manager)
# =============================================================================
export NVM_DIR="$HOME/.nvm"
if [[ -f "$NVM_DIR/nvm.sh" && -r "$NVM_DIR/nvm.sh" ]]; then
source "$NVM_DIR/nvm.sh"
fi
if [[ -f "$NVM_DIR/bash_completion" && -r "$NVM_DIR/bash_completion" ]]; then
source "$NVM_DIR/bash_completion"
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
| 1 | # ============================================================================= |
| 2 | # FILE: ~/.sourcerc |
| 3 | # Description: Initializes third-party package managers and external tools. |
| 4 | # ============================================================================= |
| 5 | |
| 6 | # ============================================================================= |
| 7 | # GENERAL ENV |
| 8 | # ============================================================================= |
| 9 | if [[ -f "$HOME/.local/bin/env" && -r "$HOME/.local/bin/env" ]]; then |
| 10 | source "$HOME/.local/bin/env" |
| 11 | fi |
| 12 | |
| 13 | # ============================================================================= |
| 14 | # CLAUDE CODE / AI GATEWAY |
| 15 | # ============================================================================= |
| 16 | export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic" |
| 17 | |
| 18 | # ============================================================================= |
| 19 | # SDKMAN (Java/Kotlin/Scala Version Manager) |
| 20 | # ============================================================================= |
| 21 | export SDKMAN_DIR="$HOME/.sdkman" |
| 22 | if [[ -f "$SDKMAN_DIR/bin/sdkman-init.sh" && -r "$SDKMAN_DIR/bin/sdkman-init.sh" ]]; then |
| 23 | source "$SDKMAN_DIR/bin/sdkman-init.sh" |
| 24 | fi |
| 25 | |
| 26 | # ============================================================================= |
| 27 | # NVM (Node Version Manager) |
| 28 | # ============================================================================= |
| 29 | export NVM_DIR="$HOME/.nvm" |
| 30 | if [[ -f "$NVM_DIR/nvm.sh" && -r "$NVM_DIR/nvm.sh" ]]; then |
| 31 | source "$NVM_DIR/nvm.sh" |
| 32 | fi |
| 33 | if [[ -f "$NVM_DIR/bash_completion" && -r "$NVM_DIR/bash_completion" ]]; then |
| 34 | source "$NVM_DIR/bash_completion" |
| 35 | fi |
| 36 | |
| 37 | # ============================================================================= |
| 38 | # GOOGLE CLOUD SDK |
| 39 | # ============================================================================= |
| 40 | if [[ -f "$HOME/google-cloud-sdk/path.zsh.inc" ]]; then |
| 41 | source "$HOME/google-cloud-sdk/path.zsh.inc" |
| 42 | fi |
| 43 | |
| 44 | if [[ -f "$HOME/google-cloud-sdk/completion.zsh.inc" ]]; then |
| 45 | source "$HOME/google-cloud-sdk/completion.zsh.inc" |
| 46 | fi |
starship.toml
· 5.3 KiB · TOML
Sin formato
"$schema" = 'https://starship.rs/config-schema.json'
format = """
[](red)\
$os\
$username\
[](bg:peach fg:red)\
$directory\
[](bg:yellow fg:peach)\
$git_branch\
$git_status\
[](fg:yellow bg:green)\
$c\
$rust\
$golang\
$nodejs\
$bun\
$php\
$java\
$kotlin\
$haskell\
$python\
[](fg:green bg:sapphire)\
$conda\
[](fg:sapphire bg:lavender)\
$time\
[ ](fg:lavender)\
$cmd_duration\
$line_break\
$character"""
palette = 'catppuccin_mocha'
[os]
disabled = false
style = "bg:red fg:crust"
[os.symbols]
Windows = ""
Ubuntu = ""
SUSE = ""
Raspbian = ""
Mint = ""
Macos = ""
Manjaro = ""
Linux = ""
Gentoo = ""
Fedora = ""
Alpine = ""
Amazon = ""
Android = ""
AOSC = ""
Arch = ""
Artix = ""
CentOS = ""
Debian = ""
Redhat = ""
RedHatEnterprise = ""
[username]
show_always = true
style_user = "bg:red fg:crust"
style_root = "bg:red fg:crust"
format = '[ $user]($style)'
[directory]
style = "bg:peach fg:crust"
format = "[ $path ]($style)"
truncation_length = 3
truncation_symbol = "…/"
[directory.substitutions]
"Documents" = " "
"Downloads" = " "
"Music" = " "
"Pictures" = " "
"Developer" = " "
[git_branch]
symbol = ""
style = "bg:yellow"
format = '[[ $symbol $branch ](fg:crust bg:yellow)]($style)'
[git_status]
style = "bg:yellow"
format = '[[($all_status$ahead_behind )](fg:crust bg:yellow)]($style)'
[nodejs]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[bun]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[c]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[rust]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[golang]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[php]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[java]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[kotlin]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[haskell]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[python]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version)(\(#$virtualenv\)) ](fg:crust bg:green)]($style)'
[docker_context]
symbol = ""
style = "bg:sapphire"
format = '[[ $symbol( $context) ](fg:crust bg:sapphire)]($style)'
[conda]
symbol = " "
style = "fg:crust bg:sapphire"
format = '[$symbol$environment ]($style)'
ignore_base = false
[time]
disabled = false
time_format = "%R"
style = "bg:lavender"
format = '[[ $time ](fg:crust bg:lavender)]($style)'
[line_break]
disabled = false
[character]
disabled = false
success_symbol = '[❯](bold fg:green)'
error_symbol = '[❯](bold fg:red)'
vimcmd_symbol = '[❮](bold fg:green)'
vimcmd_replace_one_symbol = '[❮](bold fg:lavender)'
vimcmd_replace_symbol = '[❮](bold fg:lavender)'
vimcmd_visual_symbol = '[❮](bold fg:yellow)'
[cmd_duration]
show_milliseconds = true
format = " in $duration "
style = "bg:lavender"
disabled = false
show_notifications = true
min_time_to_notify = 45000
[palettes.catppuccin_mocha]
rosewater = "#f5e0dc"
flamingo = "#f2cdcd"
pink = "#f5c2e7"
mauve = "#cba6f7"
red = "#f38ba8"
maroon = "#eba0ac"
peach = "#fab387"
yellow = "#f9e2af"
green = "#a6e3a1"
teal = "#94e2d5"
sky = "#89dceb"
sapphire = "#74c7ec"
blue = "#89b4fa"
lavender = "#b4befe"
text = "#cdd6f4"
subtext1 = "#bac2de"
subtext0 = "#a6adc8"
overlay2 = "#9399b2"
overlay1 = "#7f849c"
overlay0 = "#6c7086"
surface2 = "#585b70"
surface1 = "#45475a"
surface0 = "#313244"
base = "#1e1e2e"
mantle = "#181825"
crust = "#11111b"
[palettes.catppuccin_frappe]
rosewater = "#f2d5cf"
flamingo = "#eebebe"
pink = "#f4b8e4"
mauve = "#ca9ee6"
red = "#e78284"
maroon = "#ea999c"
peach = "#ef9f76"
yellow = "#e5c890"
green = "#a6d189"
teal = "#81c8be"
sky = "#99d1db"
sapphire = "#85c1dc"
blue = "#8caaee"
lavender = "#babbf1"
text = "#c6d0f5"
subtext1 = "#b5bfe2"
subtext0 = "#a5adce"
overlay2 = "#949cbb"
overlay1 = "#838ba7"
overlay0 = "#737994"
surface2 = "#626880"
surface1 = "#51576d"
surface0 = "#414559"
base = "#303446"
mantle = "#292c3c"
crust = "#232634"
[palettes.catppuccin_latte]
rosewater = "#dc8a78"
flamingo = "#dd7878"
pink = "#ea76cb"
mauve = "#8839ef"
red = "#d20f39"
maroon = "#e64553"
peach = "#fe640b"
yellow = "#df8e1d"
green = "#40a02b"
teal = "#179299"
sky = "#04a5e5"
sapphire = "#209fb5"
blue = "#1e66f5"
lavender = "#7287fd"
text = "#4c4f69"
subtext1 = "#5c5f77"
subtext0 = "#6c6f85"
overlay2 = "#7c7f93"
overlay1 = "#8c8fa1"
overlay0 = "#9ca0b0"
surface2 = "#acb0be"
surface1 = "#bcc0cc"
surface0 = "#ccd0da"
base = "#eff1f5"
mantle = "#e6e9ef"
crust = "#dce0e8"
[palettes.catppuccin_macchiato]
rosewater = "#f4dbd6"
flamingo = "#f0c6c6"
pink = "#f5bde6"
mauve = "#c6a0f6"
red = "#ed8796"
maroon = "#ee99a0"
peach = "#f5a97f"
yellow = "#eed49f"
green = "#a6da95"
teal = "#8bd5ca"
sky = "#91d7e3"
sapphire = "#7dc4e4"
blue = "#8aadf4"
lavender = "#b7bdf8"
text = "#cad3f5"
subtext1 = "#b8c0e0"
subtext0 = "#a5adcb"
overlay2 = "#939ab7"
overlay1 = "#8087a2"
overlay0 = "#6e738d"
surface2 = "#5b6078"
surface1 = "#494d64"
surface0 = "#363a4f"
base = "#24273a"
mantle = "#1e2030"
crust = "#181926"
| 1 | "$schema" = 'https://starship.rs/config-schema.json' |
| 2 | |
| 3 | format = """ |
| 4 | [](red)\ |
| 5 | $os\ |
| 6 | $username\ |
| 7 | [](bg:peach fg:red)\ |
| 8 | $directory\ |
| 9 | [](bg:yellow fg:peach)\ |
| 10 | $git_branch\ |
| 11 | $git_status\ |
| 12 | [](fg:yellow bg:green)\ |
| 13 | $c\ |
| 14 | $rust\ |
| 15 | $golang\ |
| 16 | $nodejs\ |
| 17 | $bun\ |
| 18 | $php\ |
| 19 | $java\ |
| 20 | $kotlin\ |
| 21 | $haskell\ |
| 22 | $python\ |
| 23 | [](fg:green bg:sapphire)\ |
| 24 | $conda\ |
| 25 | [](fg:sapphire bg:lavender)\ |
| 26 | $time\ |
| 27 | [ ](fg:lavender)\ |
| 28 | $cmd_duration\ |
| 29 | $line_break\ |
| 30 | $character""" |
| 31 | |
| 32 | palette = 'catppuccin_mocha' |
| 33 | |
| 34 | [os] |
| 35 | disabled = false |
| 36 | style = "bg:red fg:crust" |
| 37 | |
| 38 | [os.symbols] |
| 39 | Windows = "" |
| 40 | Ubuntu = "" |
| 41 | SUSE = "" |
| 42 | Raspbian = "" |
| 43 | Mint = "" |
| 44 | Macos = "" |
| 45 | Manjaro = "" |
| 46 | Linux = "" |
| 47 | Gentoo = "" |
| 48 | Fedora = "" |
| 49 | Alpine = "" |
| 50 | Amazon = "" |
| 51 | Android = "" |
| 52 | AOSC = "" |
| 53 | Arch = "" |
| 54 | Artix = "" |
| 55 | CentOS = "" |
| 56 | Debian = "" |
| 57 | Redhat = "" |
| 58 | RedHatEnterprise = "" |
| 59 | |
| 60 | [username] |
| 61 | show_always = true |
| 62 | style_user = "bg:red fg:crust" |
| 63 | style_root = "bg:red fg:crust" |
| 64 | format = '[ $user]($style)' |
| 65 | |
| 66 | [directory] |
| 67 | style = "bg:peach fg:crust" |
| 68 | format = "[ $path ]($style)" |
| 69 | truncation_length = 3 |
| 70 | truncation_symbol = "…/" |
| 71 | |
| 72 | [directory.substitutions] |
| 73 | "Documents" = " " |
| 74 | "Downloads" = " " |
| 75 | "Music" = " " |
| 76 | "Pictures" = " " |
| 77 | "Developer" = " " |
| 78 | |
| 79 | [git_branch] |
| 80 | symbol = "" |
| 81 | style = "bg:yellow" |
| 82 | format = '[[ $symbol $branch ](fg:crust bg:yellow)]($style)' |
| 83 | |
| 84 | [git_status] |
| 85 | style = "bg:yellow" |
| 86 | format = '[[($all_status$ahead_behind )](fg:crust bg:yellow)]($style)' |
| 87 | |
| 88 | [nodejs] |
| 89 | symbol = "" |
| 90 | style = "bg:green" |
| 91 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 92 | |
| 93 | [bun] |
| 94 | symbol = "" |
| 95 | style = "bg:green" |
| 96 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 97 | |
| 98 | [c] |
| 99 | symbol = " " |
| 100 | style = "bg:green" |
| 101 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 102 | |
| 103 | [rust] |
| 104 | symbol = "" |
| 105 | style = "bg:green" |
| 106 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 107 | |
| 108 | [golang] |
| 109 | symbol = "" |
| 110 | style = "bg:green" |
| 111 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 112 | |
| 113 | [php] |
| 114 | symbol = "" |
| 115 | style = "bg:green" |
| 116 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 117 | |
| 118 | [java] |
| 119 | symbol = " " |
| 120 | style = "bg:green" |
| 121 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 122 | |
| 123 | [kotlin] |
| 124 | symbol = "" |
| 125 | style = "bg:green" |
| 126 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 127 | |
| 128 | [haskell] |
| 129 | symbol = "" |
| 130 | style = "bg:green" |
| 131 | format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)' |
| 132 | |
| 133 | [python] |
| 134 | symbol = "" |
| 135 | style = "bg:green" |
| 136 | format = '[[ $symbol( $version)(\(#$virtualenv\)) ](fg:crust bg:green)]($style)' |
| 137 | |
| 138 | [docker_context] |
| 139 | symbol = "" |
| 140 | style = "bg:sapphire" |
| 141 | format = '[[ $symbol( $context) ](fg:crust bg:sapphire)]($style)' |
| 142 | |
| 143 | [conda] |
| 144 | symbol = " " |
| 145 | style = "fg:crust bg:sapphire" |
| 146 | format = '[$symbol$environment ]($style)' |
| 147 | ignore_base = false |
| 148 | |
| 149 | [time] |
| 150 | disabled = false |
| 151 | time_format = "%R" |
| 152 | style = "bg:lavender" |
| 153 | format = '[[ $time ](fg:crust bg:lavender)]($style)' |
| 154 | |
| 155 | [line_break] |
| 156 | disabled = false |
| 157 | |
| 158 | [character] |
| 159 | disabled = false |
| 160 | success_symbol = '[❯](bold fg:green)' |
| 161 | error_symbol = '[❯](bold fg:red)' |
| 162 | vimcmd_symbol = '[❮](bold fg:green)' |
| 163 | vimcmd_replace_one_symbol = '[❮](bold fg:lavender)' |
| 164 | vimcmd_replace_symbol = '[❮](bold fg:lavender)' |
| 165 | vimcmd_visual_symbol = '[❮](bold fg:yellow)' |
| 166 | |
| 167 | [cmd_duration] |
| 168 | show_milliseconds = true |
| 169 | format = " in $duration " |
| 170 | style = "bg:lavender" |
| 171 | disabled = false |
| 172 | show_notifications = true |
| 173 | min_time_to_notify = 45000 |
| 174 | |
| 175 | [palettes.catppuccin_mocha] |
| 176 | rosewater = "#f5e0dc" |
| 177 | flamingo = "#f2cdcd" |
| 178 | pink = "#f5c2e7" |
| 179 | mauve = "#cba6f7" |
| 180 | red = "#f38ba8" |
| 181 | maroon = "#eba0ac" |
| 182 | peach = "#fab387" |
| 183 | yellow = "#f9e2af" |
| 184 | green = "#a6e3a1" |
| 185 | teal = "#94e2d5" |
| 186 | sky = "#89dceb" |
| 187 | sapphire = "#74c7ec" |
| 188 | blue = "#89b4fa" |
| 189 | lavender = "#b4befe" |
| 190 | text = "#cdd6f4" |
| 191 | subtext1 = "#bac2de" |
| 192 | subtext0 = "#a6adc8" |
| 193 | overlay2 = "#9399b2" |
| 194 | overlay1 = "#7f849c" |
| 195 | overlay0 = "#6c7086" |
| 196 | surface2 = "#585b70" |
| 197 | surface1 = "#45475a" |
| 198 | surface0 = "#313244" |
| 199 | base = "#1e1e2e" |
| 200 | mantle = "#181825" |
| 201 | crust = "#11111b" |
| 202 | |
| 203 | [palettes.catppuccin_frappe] |
| 204 | rosewater = "#f2d5cf" |
| 205 | flamingo = "#eebebe" |
| 206 | pink = "#f4b8e4" |
| 207 | mauve = "#ca9ee6" |
| 208 | red = "#e78284" |
| 209 | maroon = "#ea999c" |
| 210 | peach = "#ef9f76" |
| 211 | yellow = "#e5c890" |
| 212 | green = "#a6d189" |
| 213 | teal = "#81c8be" |
| 214 | sky = "#99d1db" |
| 215 | sapphire = "#85c1dc" |
| 216 | blue = "#8caaee" |
| 217 | lavender = "#babbf1" |
| 218 | text = "#c6d0f5" |
| 219 | subtext1 = "#b5bfe2" |
| 220 | subtext0 = "#a5adce" |
| 221 | overlay2 = "#949cbb" |
| 222 | overlay1 = "#838ba7" |
| 223 | overlay0 = "#737994" |
| 224 | surface2 = "#626880" |
| 225 | surface1 = "#51576d" |
| 226 | surface0 = "#414559" |
| 227 | base = "#303446" |
| 228 | mantle = "#292c3c" |
| 229 | crust = "#232634" |
| 230 | |
| 231 | [palettes.catppuccin_latte] |
| 232 | rosewater = "#dc8a78" |
| 233 | flamingo = "#dd7878" |
| 234 | pink = "#ea76cb" |
| 235 | mauve = "#8839ef" |
| 236 | red = "#d20f39" |
| 237 | maroon = "#e64553" |
| 238 | peach = "#fe640b" |
| 239 | yellow = "#df8e1d" |
| 240 | green = "#40a02b" |
| 241 | teal = "#179299" |
| 242 | sky = "#04a5e5" |
| 243 | sapphire = "#209fb5" |
| 244 | blue = "#1e66f5" |
| 245 | lavender = "#7287fd" |
| 246 | text = "#4c4f69" |
| 247 | subtext1 = "#5c5f77" |
| 248 | subtext0 = "#6c6f85" |
| 249 | overlay2 = "#7c7f93" |
| 250 | overlay1 = "#8c8fa1" |
| 251 | overlay0 = "#9ca0b0" |
| 252 | surface2 = "#acb0be" |
| 253 | surface1 = "#bcc0cc" |
| 254 | surface0 = "#ccd0da" |
| 255 | base = "#eff1f5" |
| 256 | mantle = "#e6e9ef" |
| 257 | crust = "#dce0e8" |
| 258 | |
| 259 | [palettes.catppuccin_macchiato] |
| 260 | rosewater = "#f4dbd6" |
| 261 | flamingo = "#f0c6c6" |
| 262 | pink = "#f5bde6" |
| 263 | mauve = "#c6a0f6" |
| 264 | red = "#ed8796" |
| 265 | maroon = "#ee99a0" |
| 266 | peach = "#f5a97f" |
| 267 | yellow = "#eed49f" |
| 268 | green = "#a6da95" |
| 269 | teal = "#8bd5ca" |
| 270 | sky = "#91d7e3" |
| 271 | sapphire = "#7dc4e4" |
| 272 | blue = "#8aadf4" |
| 273 | lavender = "#b7bdf8" |
| 274 | text = "#cad3f5" |
| 275 | subtext1 = "#b8c0e0" |
| 276 | subtext0 = "#a5adcb" |
| 277 | overlay2 = "#939ab7" |
| 278 | overlay1 = "#8087a2" |
| 279 | overlay0 = "#6e738d" |
| 280 | surface2 = "#5b6078" |
| 281 | surface1 = "#494d64" |
| 282 | surface0 = "#363a4f" |
| 283 | base = "#24273a" |
| 284 | mantle = "#1e2030" |
| 285 | crust = "#181926" |
| 286 |
vimrc
· 2.9 KiB · VimL
Sin formato
" 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.3 KiB · Bash
Sin formato
#!/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() {
log "Installing Oh My Zsh and plugins..."
export RUNZSH=no
export CHSH=no
export KEEP_ZSHRC=yes
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
else
ok "Oh My Zsh already installed"
fi
local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
local plugin_dir="$custom/plugins"
mkdir -p "$plugin_dir"
[[ -d "$plugin_dir/zsh-autosuggestions" ]] || \
git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions"
[[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || \
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting"
ok "Oh My Zsh plugins installed to $plugin_dir"
}
install_starship() {
if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; 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
}
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)"
}
configure_zshrc() {
local zshrc="$HOME/.zshrc"
log "Configuring .zshrc for Oh My Zsh and Starship..."
touch "$zshrc"
cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)"
cat > "$zshrc" <<'EOF'
# =============================================================================
# 1. HELPER FUNCTIONS & PATH
# =============================================================================
source_if_readable() {
local file="$1"
if [[ -f "$file" && -r "$file" ]]; then
source "$file"
fi
}
export PATH="$HOME/.local/bin:$PATH"
# =============================================================================
# 2. OH MY ZSH FRAMEWORK
# =============================================================================
export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
ZSH_THEME=""
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
source_if_readable "$ZSH/oh-my-zsh.sh"
# =============================================================================
# 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
# =============================================================================
source_if_readable "$HOME/.sourcerc"
source_if_readable "$HOME/.func"
source_if_readable "$HOME/.pathrc"
source_if_readable "$HOME/.alias"
# =============================================================================
# 4. STARSHIP PROMPT
# =============================================================================
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)"
elif [[ -x "$HOME/.local/bin/starship" ]]; then
eval "$("$HOME/.local/bin/starship" init zsh)"
fi
EOF
ok ".zshrc configured for Oh My Zsh framework with Starship prompt"
}
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 Minimal Zsh Setup - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-5)"
echo " 1) Install Oh My Zsh + plugins"
echo " 2) Install Starship prompt"
echo " 3) Download custom configs (~/.alias, .func, .vimrc, etc.)"
echo " 4) Configure ~/.zshrc (Oh My Zsh + Starship)"
echo " 5) Switch to Zsh (Temporary Sub-shell)"
echo " 6) 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)
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_starship ;;
3) download_configs ;;
4) configure_zshrc ;;
5) switch_shell ;;
6) 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 minimal Zsh 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 | log "Installing Oh My Zsh and plugins..." |
| 48 | export RUNZSH=no |
| 49 | export CHSH=no |
| 50 | export KEEP_ZSHRC=yes |
| 51 | |
| 52 | if [[ ! -d "$HOME/.oh-my-zsh" ]]; then |
| 53 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended |
| 54 | else |
| 55 | ok "Oh My Zsh already installed" |
| 56 | fi |
| 57 | |
| 58 | local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" |
| 59 | local plugin_dir="$custom/plugins" |
| 60 | mkdir -p "$plugin_dir" |
| 61 | |
| 62 | [[ -d "$plugin_dir/zsh-autosuggestions" ]] || \ |
| 63 | git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions" |
| 64 | |
| 65 | [[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || \ |
| 66 | git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting" |
| 67 | |
| 68 | ok "Oh My Zsh plugins installed to $plugin_dir" |
| 69 | } |
| 70 | |
| 71 | install_starship() { |
| 72 | if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then |
| 73 | ok "Starship already installed" |
| 74 | elif command -v brew >/dev/null 2>&1; then |
| 75 | log "Installing Starship with Homebrew..." |
| 76 | brew install starship |
| 77 | ok "Starship installed" |
| 78 | else |
| 79 | log "Installing Starship..." |
| 80 | mkdir -p "$HOME/.local/bin" |
| 81 | curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin" |
| 82 | ok "Starship installed" |
| 83 | fi |
| 84 | } |
| 85 | |
| 86 | download_configs() { |
| 87 | log "Downloading custom config files..." |
| 88 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 89 | mkdir -p "$backup" |
| 90 | |
| 91 | for f in "${CONFIG_FILES[@]}"; do |
| 92 | # Strip the leading dot for the download URL |
| 93 | local remote_file="${f#.}" |
| 94 | [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml" |
| 95 | local url="$GIST_RAW_BASE/$remote_file" |
| 96 | local target="$HOME/$f" |
| 97 | local tmp="${target}.tmp.$$" |
| 98 | |
| 99 | mkdir -p "$(dirname "$target")" |
| 100 | |
| 101 | if [[ -f "$target" ]]; then |
| 102 | cp "$target" "$backup/" |
| 103 | fi |
| 104 | |
| 105 | log "Fetching $remote_file -> $f ..." |
| 106 | if curl -fsSL "$url" -o "$tmp"; then |
| 107 | mv "$tmp" "$target" |
| 108 | else |
| 109 | rm -f "$tmp" |
| 110 | warn "Failed to download $remote_file" |
| 111 | fi |
| 112 | done |
| 113 | |
| 114 | ok "Configs downloaded (Backup at $backup)" |
| 115 | } |
| 116 | |
| 117 | configure_zshrc() { |
| 118 | local zshrc="$HOME/.zshrc" |
| 119 | log "Configuring .zshrc for Oh My Zsh and Starship..." |
| 120 | |
| 121 | touch "$zshrc" |
| 122 | cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)" |
| 123 | |
| 124 | cat > "$zshrc" <<'EOF' |
| 125 | # ============================================================================= |
| 126 | # 1. HELPER FUNCTIONS & PATH |
| 127 | # ============================================================================= |
| 128 | source_if_readable() { |
| 129 | local file="$1" |
| 130 | if [[ -f "$file" && -r "$file" ]]; then |
| 131 | source "$file" |
| 132 | fi |
| 133 | } |
| 134 | |
| 135 | export PATH="$HOME/.local/bin:$PATH" |
| 136 | |
| 137 | # ============================================================================= |
| 138 | # 2. OH MY ZSH FRAMEWORK |
| 139 | # ============================================================================= |
| 140 | export ZSH="${ZSH:-$HOME/.oh-my-zsh}" |
| 141 | ZSH_THEME="" |
| 142 | |
| 143 | plugins=( |
| 144 | git |
| 145 | zsh-autosuggestions |
| 146 | zsh-syntax-highlighting |
| 147 | ) |
| 148 | |
| 149 | source_if_readable "$ZSH/oh-my-zsh.sh" |
| 150 | |
| 151 | # ============================================================================= |
| 152 | # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS |
| 153 | # ============================================================================= |
| 154 | source_if_readable "$HOME/.sourcerc" |
| 155 | source_if_readable "$HOME/.func" |
| 156 | source_if_readable "$HOME/.pathrc" |
| 157 | source_if_readable "$HOME/.alias" |
| 158 | |
| 159 | # ============================================================================= |
| 160 | # 4. STARSHIP PROMPT |
| 161 | # ============================================================================= |
| 162 | if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then |
| 163 | export STARSHIP_CONFIG="$HOME/.config/starship.toml" |
| 164 | fi |
| 165 | |
| 166 | if command -v starship >/dev/null 2>&1; then |
| 167 | eval "$(starship init zsh)" |
| 168 | elif [[ -x "$HOME/.local/bin/starship" ]]; then |
| 169 | eval "$("$HOME/.local/bin/starship" init zsh)" |
| 170 | fi |
| 171 | EOF |
| 172 | |
| 173 | ok ".zshrc configured for Oh My Zsh framework with Starship prompt" |
| 174 | } |
| 175 | |
| 176 | switch_shell() { |
| 177 | log "Starting Zsh session..." |
| 178 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 179 | echo "----------------------------------------" |
| 180 | zsh -l |
| 181 | echo "----------------------------------------" |
| 182 | ok "Returned from Zsh session" |
| 183 | } |
| 184 | |
| 185 | # ============================= |
| 186 | # INTERACTIVE MENU |
| 187 | # ============================= |
| 188 | show_menu() { |
| 189 | echo "===========================================" |
| 190 | echo "macOS Minimal Zsh Setup - Choose what to do" |
| 191 | echo "===========================================" |
| 192 | echo " 0) Run ALL steps (1-5)" |
| 193 | echo " 1) Install Oh My Zsh + plugins" |
| 194 | echo " 2) Install Starship prompt" |
| 195 | echo " 3) Download custom configs (~/.alias, .func, .vimrc, etc.)" |
| 196 | echo " 4) Configure ~/.zshrc (Oh My Zsh + Starship)" |
| 197 | echo " 5) Switch to Zsh (Temporary Sub-shell)" |
| 198 | echo " 6) Quit" |
| 199 | echo "===========================================" |
| 200 | } |
| 201 | |
| 202 | run_choices() { |
| 203 | local input |
| 204 | read -p "Select: " input |
| 205 | input="${input//,/ }" |
| 206 | |
| 207 | local -a to_run=() |
| 208 | local -a to_exclude=() |
| 209 | |
| 210 | for item in $input; do |
| 211 | if [[ "$item" == !* ]]; then |
| 212 | to_exclude+=("${item:1}") |
| 213 | elif [[ "$item" == "0" ]]; then |
| 214 | to_run+=(1 2 3 4 5) |
| 215 | else |
| 216 | to_run+=("$item") |
| 217 | fi |
| 218 | done |
| 219 | |
| 220 | if [[ ${#to_run[@]} -gt 0 ]]; then |
| 221 | for choice in "${to_run[@]}"; do |
| 222 | local skip=false |
| 223 | |
| 224 | if [[ ${#to_exclude[@]} -gt 0 ]]; then |
| 225 | for ex in "${to_exclude[@]}"; do |
| 226 | if [[ "$choice" == "$ex" ]]; then |
| 227 | skip=true |
| 228 | break |
| 229 | fi |
| 230 | done |
| 231 | fi |
| 232 | |
| 233 | $skip && continue |
| 234 | |
| 235 | case "$choice" in |
| 236 | 1) install_oh_my_zsh ;; |
| 237 | 2) install_starship ;; |
| 238 | 3) download_configs ;; |
| 239 | 4) configure_zshrc ;; |
| 240 | 5) switch_shell ;; |
| 241 | 6) exit 0 ;; |
| 242 | *) warn "Skipping invalid option: $choice" ;; |
| 243 | esac |
| 244 | echo |
| 245 | done |
| 246 | fi |
| 247 | } |
| 248 | |
| 249 | # ============================= |
| 250 | # MAIN |
| 251 | # ============================= |
| 252 | main() { |
| 253 | check_requirements |
| 254 | while true; do |
| 255 | show_menu |
| 256 | run_choices |
| 257 | read -p "Do you want to run more options? (y/n): " again |
| 258 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 259 | done |
| 260 | ok "macOS minimal Zsh configuration complete!" |
| 261 | } |
| 262 | |
| 263 | main "$@" |
| 264 |
zsh_ubuntu.sh
· 10 KiB · Bash
Sin formato
#!/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 [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [ -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. The script will request sudo when necessary."
exit 1
fi
if [[ "$(detect_os)" != "macos" ]] && ! command -v sudo >/dev/null 2>&1; then
err "sudo required on Linux"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
update_system() {
$SKIP_PACKAGES && return
log "Updating system..."
local os=$(detect_os)
case "$os" in
macos)
brew update || warn "Homebrew update failed; continuing installer"
;;
ubuntu|debian)
sudo apt-get update -y
if ! sudo apt-get upgrade -y; then
warn "System upgrade did not complete. This can happen when apt wants to downgrade a package."
warn "Continuing because the Zsh setup does not require OS package upgrades to finish."
fi
;;
fedora)
sudo dnf upgrade -y || warn "System upgrade failed; continuing installer"
;;
arch)
sudo pacman -Syu --noconfirm || warn "System upgrade failed; continuing installer"
;;
*) warn "Auto-update not supported for OS: $os" ;;
esac
ok "System update step finished"
}
install_packages() {
$SKIP_PACKAGES && return
log "Installing core packages..."
local os=$(detect_os)
case "$os" in
macos) brew install zsh git vim curl wget unzip xz ;;
ubuntu|debian) sudo apt-get install -y zsh git vim curl wget unzip zip build-essential xz-utils ;;
fedora) sudo dnf install -y zsh git vim curl wget unzip zip @development-tools xz ;;
arch) sudo pacman -S --noconfirm zsh git vim curl wget unzip zip base-devel xz ;;
*) warn "Auto-install not supported for OS: $os. Please install zsh, git, vim, curl manually." ;;
esac
ok "Packages installed"
}
set_timezone() {
log "Setting timezone to Asia/Singapore..."
local os=$(detect_os)
if [[ "$os" == "macos" ]]; then
sudo systemsetup -settimezone Asia/Singapore >/dev/null
else
sudo timedatectl set-timezone Asia/Singapore
fi
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)"
if ! grep -qx "$zsh_path" /etc/shells; then
echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
fi
chsh -s "$zsh_path"
ok "Shell changed (requires logout/login to take effect)"
}
install_oh_my_zsh() {
log "Installing Oh My Zsh and plugins..."
export RUNZSH=no
export CHSH=no
export KEEP_ZSHRC=yes
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
else
ok "Oh My Zsh already installed"
fi
local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
local plugin_dir="$custom/plugins"
mkdir -p "$plugin_dir"
[[ -d "$plugin_dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions"
[[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting"
ok "Oh My Zsh plugins installed to $plugin_dir"
}
install_starship() {
if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then
ok "Starship already installed"
else
log "Installing Starship prompt..."
if command -v brew >/dev/null 2>&1; then
brew install starship
else
mkdir -p "$HOME/.local/bin"
curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
fi
ok "Starship installed"
fi
}
download_configs() {
log "Downloading custom config files from OpenGist..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
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)"
}
configure_zshrc() {
local zshrc="$HOME/.zshrc"
log "Configuring .zshrc for Oh My Zsh and Starship..."
touch "$zshrc"
cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)"
cat > "$zshrc" <<'EOF'
# =============================================================================
# 1. HELPER FUNCTIONS & PATH
# =============================================================================
source_if_readable() {
local file="$1"
if [[ -f "$file" && -r "$file" ]]; then
source "$file"
fi
}
export PATH="$HOME/.local/bin:$PATH"
# =============================================================================
# 2. OH MY ZSH FRAMEWORK
# =============================================================================
export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
ZSH_THEME=""
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
source_if_readable "$ZSH/oh-my-zsh.sh"
# =============================================================================
# 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
# =============================================================================
source_if_readable "$HOME/.sourcerc"
source_if_readable "$HOME/.func"
source_if_readable "$HOME/.pathrc"
source_if_readable "$HOME/.alias"
# =============================================================================
# 4. STARSHIP PROMPT
# =============================================================================
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)"
elif [[ -x "$HOME/.local/bin/starship" ]]; then
eval "$("$HOME/.local/bin/starship" init zsh)"
fi
EOF
ok ".zshrc configured for Oh My Zsh framework with Starship prompt"
}
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 "Minimal Zsh Installer - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-10)"
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 + plugins"
echo " 7) Install Starship prompt"
echo " 8) Download custom configs (from OpenGist)"
echo " 9) Configure ~/.zshrc (Oh My Zsh + Starship)"
echo "10) Switch to Zsh (Temporary Sub-shell)"
echo "11) 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)
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_starship ;;
8) download_configs ;;
9) configure_zshrc ;;
10) switch_shell ;;
11) 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 [[ "$OSTYPE" == "darwin"* ]]; then |
| 41 | echo "macos" |
| 42 | elif [ -f /etc/os-release ]; then |
| 43 | . /etc/os-release |
| 44 | echo "$ID" |
| 45 | else |
| 46 | echo "unknown" |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | # ============================= |
| 51 | # REQUIREMENTS |
| 52 | # ============================= |
| 53 | check_requirements() { |
| 54 | if [[ $EUID -eq 0 ]]; then |
| 55 | err "Do not run as root. The script will request sudo when necessary." |
| 56 | exit 1 |
| 57 | fi |
| 58 | if [[ "$(detect_os)" != "macos" ]] && ! command -v sudo >/dev/null 2>&1; then |
| 59 | err "sudo required on Linux" |
| 60 | exit 1 |
| 61 | fi |
| 62 | } |
| 63 | |
| 64 | # ============================= |
| 65 | # INSTALLATION FUNCTIONS |
| 66 | # ============================= |
| 67 | update_system() { |
| 68 | $SKIP_PACKAGES && return |
| 69 | log "Updating system..." |
| 70 | local os=$(detect_os) |
| 71 | |
| 72 | case "$os" in |
| 73 | macos) |
| 74 | brew update || warn "Homebrew update failed; continuing installer" |
| 75 | ;; |
| 76 | ubuntu|debian) |
| 77 | sudo apt-get update -y |
| 78 | if ! sudo apt-get upgrade -y; then |
| 79 | warn "System upgrade did not complete. This can happen when apt wants to downgrade a package." |
| 80 | warn "Continuing because the Zsh setup does not require OS package upgrades to finish." |
| 81 | fi |
| 82 | ;; |
| 83 | fedora) |
| 84 | sudo dnf upgrade -y || warn "System upgrade failed; continuing installer" |
| 85 | ;; |
| 86 | arch) |
| 87 | sudo pacman -Syu --noconfirm || warn "System upgrade failed; continuing installer" |
| 88 | ;; |
| 89 | *) warn "Auto-update not supported for OS: $os" ;; |
| 90 | esac |
| 91 | ok "System update step finished" |
| 92 | } |
| 93 | |
| 94 | install_packages() { |
| 95 | $SKIP_PACKAGES && return |
| 96 | log "Installing core packages..." |
| 97 | local os=$(detect_os) |
| 98 | |
| 99 | case "$os" in |
| 100 | macos) brew install zsh git vim curl wget unzip xz ;; |
| 101 | ubuntu|debian) sudo apt-get install -y zsh git vim curl wget unzip zip build-essential xz-utils ;; |
| 102 | fedora) sudo dnf install -y zsh git vim curl wget unzip zip @development-tools xz ;; |
| 103 | arch) sudo pacman -S --noconfirm zsh git vim curl wget unzip zip base-devel xz ;; |
| 104 | *) warn "Auto-install not supported for OS: $os. Please install zsh, git, vim, curl manually." ;; |
| 105 | esac |
| 106 | ok "Packages installed" |
| 107 | } |
| 108 | |
| 109 | set_timezone() { |
| 110 | log "Setting timezone to Asia/Singapore..." |
| 111 | local os=$(detect_os) |
| 112 | if [[ "$os" == "macos" ]]; then |
| 113 | sudo systemsetup -settimezone Asia/Singapore >/dev/null |
| 114 | else |
| 115 | sudo timedatectl set-timezone Asia/Singapore |
| 116 | fi |
| 117 | ok "Timezone set to Asia/Singapore" |
| 118 | } |
| 119 | |
| 120 | install_homebrew() { |
| 121 | ! $INSTALL_HOMEBREW && return |
| 122 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 123 | log "Installing Homebrew..." |
| 124 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 125 | ok "Homebrew installed" |
| 126 | } |
| 127 | |
| 128 | configure_shell() { |
| 129 | $SKIP_SHELL_CHANGE && return |
| 130 | log "Changing default shell to zsh..." |
| 131 | local zsh_path |
| 132 | zsh_path="$(command -v zsh)" |
| 133 | |
| 134 | if ! grep -qx "$zsh_path" /etc/shells; then |
| 135 | echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 136 | fi |
| 137 | chsh -s "$zsh_path" |
| 138 | ok "Shell changed (requires logout/login to take effect)" |
| 139 | } |
| 140 | |
| 141 | install_oh_my_zsh() { |
| 142 | log "Installing Oh My Zsh and plugins..." |
| 143 | export RUNZSH=no |
| 144 | export CHSH=no |
| 145 | export KEEP_ZSHRC=yes |
| 146 | |
| 147 | if [[ ! -d "$HOME/.oh-my-zsh" ]]; then |
| 148 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended |
| 149 | else |
| 150 | ok "Oh My Zsh already installed" |
| 151 | fi |
| 152 | |
| 153 | local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" |
| 154 | local plugin_dir="$custom/plugins" |
| 155 | mkdir -p "$plugin_dir" |
| 156 | |
| 157 | [[ -d "$plugin_dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions" |
| 158 | [[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting" |
| 159 | |
| 160 | ok "Oh My Zsh plugins installed to $plugin_dir" |
| 161 | } |
| 162 | |
| 163 | install_starship() { |
| 164 | if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then |
| 165 | ok "Starship already installed" |
| 166 | else |
| 167 | log "Installing Starship prompt..." |
| 168 | if command -v brew >/dev/null 2>&1; then |
| 169 | brew install starship |
| 170 | else |
| 171 | mkdir -p "$HOME/.local/bin" |
| 172 | curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin" |
| 173 | fi |
| 174 | ok "Starship installed" |
| 175 | fi |
| 176 | } |
| 177 | |
| 178 | download_configs() { |
| 179 | log "Downloading custom config files from OpenGist..." |
| 180 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 181 | mkdir -p "$backup" |
| 182 | |
| 183 | for f in "${CONFIG_FILES[@]}"; do |
| 184 | local remote_file="${f#.}" |
| 185 | [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml" |
| 186 | local url="$GIST_RAW_BASE/$remote_file" |
| 187 | local target="$HOME/$f" |
| 188 | local tmp="${target}.tmp.$$" |
| 189 | |
| 190 | mkdir -p "$(dirname "$target")" |
| 191 | |
| 192 | if [[ -f "$target" ]]; then |
| 193 | cp "$target" "$backup/" |
| 194 | fi |
| 195 | |
| 196 | log "Fetching $remote_file -> $f ..." |
| 197 | if curl -fsSL "$url" -o "$tmp"; then |
| 198 | mv "$tmp" "$target" |
| 199 | else |
| 200 | rm -f "$tmp" |
| 201 | warn "Failed to download $remote_file" |
| 202 | fi |
| 203 | done |
| 204 | |
| 205 | ok "Configs downloaded (Backup at $backup)" |
| 206 | } |
| 207 | |
| 208 | configure_zshrc() { |
| 209 | local zshrc="$HOME/.zshrc" |
| 210 | log "Configuring .zshrc for Oh My Zsh and Starship..." |
| 211 | |
| 212 | touch "$zshrc" |
| 213 | cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)" |
| 214 | |
| 215 | cat > "$zshrc" <<'EOF' |
| 216 | # ============================================================================= |
| 217 | # 1. HELPER FUNCTIONS & PATH |
| 218 | # ============================================================================= |
| 219 | source_if_readable() { |
| 220 | local file="$1" |
| 221 | if [[ -f "$file" && -r "$file" ]]; then |
| 222 | source "$file" |
| 223 | fi |
| 224 | } |
| 225 | |
| 226 | export PATH="$HOME/.local/bin:$PATH" |
| 227 | |
| 228 | # ============================================================================= |
| 229 | # 2. OH MY ZSH FRAMEWORK |
| 230 | # ============================================================================= |
| 231 | export ZSH="${ZSH:-$HOME/.oh-my-zsh}" |
| 232 | ZSH_THEME="" |
| 233 | |
| 234 | plugins=( |
| 235 | git |
| 236 | zsh-autosuggestions |
| 237 | zsh-syntax-highlighting |
| 238 | ) |
| 239 | |
| 240 | source_if_readable "$ZSH/oh-my-zsh.sh" |
| 241 | |
| 242 | # ============================================================================= |
| 243 | # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS |
| 244 | # ============================================================================= |
| 245 | source_if_readable "$HOME/.sourcerc" |
| 246 | source_if_readable "$HOME/.func" |
| 247 | source_if_readable "$HOME/.pathrc" |
| 248 | source_if_readable "$HOME/.alias" |
| 249 | |
| 250 | # ============================================================================= |
| 251 | # 4. STARSHIP PROMPT |
| 252 | # ============================================================================= |
| 253 | if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then |
| 254 | export STARSHIP_CONFIG="$HOME/.config/starship.toml" |
| 255 | fi |
| 256 | |
| 257 | if command -v starship >/dev/null 2>&1; then |
| 258 | eval "$(starship init zsh)" |
| 259 | elif [[ -x "$HOME/.local/bin/starship" ]]; then |
| 260 | eval "$("$HOME/.local/bin/starship" init zsh)" |
| 261 | fi |
| 262 | EOF |
| 263 | |
| 264 | ok ".zshrc configured for Oh My Zsh framework with Starship prompt" |
| 265 | } |
| 266 | |
| 267 | switch_shell() { |
| 268 | log "Starting Zsh session..." |
| 269 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 270 | echo "----------------------------------------" |
| 271 | zsh -l |
| 272 | echo "----------------------------------------" |
| 273 | ok "Returned from Zsh session" |
| 274 | } |
| 275 | |
| 276 | # ============================= |
| 277 | # INTERACTIVE MENU |
| 278 | # ============================= |
| 279 | show_menu() { |
| 280 | echo "===========================================" |
| 281 | echo "Minimal Zsh Installer - Choose what to do" |
| 282 | echo "===========================================" |
| 283 | echo " 0) Run ALL steps (1-10)" |
| 284 | echo " 1) Update system packages" |
| 285 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 286 | echo " 3) Set Timezone (Asia/Singapore)" |
| 287 | echo " 4) Install Homebrew" |
| 288 | echo " 5) Configure shell (chsh - sets default shell)" |
| 289 | echo " 6) Install Oh My Zsh + plugins" |
| 290 | echo " 7) Install Starship prompt" |
| 291 | echo " 8) Download custom configs (from OpenGist)" |
| 292 | echo " 9) Configure ~/.zshrc (Oh My Zsh + Starship)" |
| 293 | echo "10) Switch to Zsh (Temporary Sub-shell)" |
| 294 | echo "11) Quit" |
| 295 | echo "===========================================" |
| 296 | } |
| 297 | |
| 298 | run_choices() { |
| 299 | local input |
| 300 | read -p "Select: " input |
| 301 | input="${input//,/ }" |
| 302 | |
| 303 | local -a to_run=() |
| 304 | local -a to_exclude=() |
| 305 | |
| 306 | for item in $input; do |
| 307 | if [[ "$item" == !* ]]; then |
| 308 | to_exclude+=("${item:1}") |
| 309 | elif [[ "$item" == "0" ]]; then |
| 310 | to_run+=(1 2 3 4 5 6 7 8 9 10) |
| 311 | else |
| 312 | to_run+=("$item") |
| 313 | fi |
| 314 | done |
| 315 | |
| 316 | for choice in "${to_run[@]}"; do |
| 317 | local skip=false |
| 318 | |
| 319 | for ex in "${to_exclude[@]}"; do |
| 320 | if [[ "$choice" == "$ex" ]]; then |
| 321 | skip=true |
| 322 | break |
| 323 | fi |
| 324 | done |
| 325 | |
| 326 | $skip && continue |
| 327 | |
| 328 | case "$choice" in |
| 329 | 1) update_system ;; |
| 330 | 2) install_packages ;; |
| 331 | 3) set_timezone ;; |
| 332 | 4) install_homebrew ;; |
| 333 | 5) configure_shell ;; |
| 334 | 6) install_oh_my_zsh ;; |
| 335 | 7) install_starship ;; |
| 336 | 8) download_configs ;; |
| 337 | 9) configure_zshrc ;; |
| 338 | 10) switch_shell ;; |
| 339 | 11) log "Exiting..."; exit 0 ;; |
| 340 | *) warn "Skipping invalid option: $choice" ;; |
| 341 | esac |
| 342 | echo |
| 343 | done |
| 344 | } |
| 345 | |
| 346 | # ============================= |
| 347 | # MAIN |
| 348 | # ============================= |
| 349 | main() { |
| 350 | check_requirements |
| 351 | while true; do |
| 352 | show_menu |
| 353 | run_choices |
| 354 | read -p "Do you want to run more options? (y/n): " again |
| 355 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 356 | done |
| 357 | ok "Zsh installation/configuration complete!" |
| 358 | } |
| 359 | |
| 360 | main "$@" |
| 361 |
zsh_wsl.sh
· 10 KiB · Bash
Sin formato
#!/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. The script will request sudo when necessary."
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..."
local os=$(detect_os)
case "$os" in
ubuntu|debian)
sudo apt-get update -y
if ! sudo apt-get upgrade -y; then
warn "System upgrade did not complete. This can happen when apt wants to downgrade a package."
warn "Continuing because the Zsh setup does not require OS package upgrades to finish."
fi
;;
fedora)
sudo dnf upgrade -y || warn "System upgrade failed; continuing installer"
;;
arch)
sudo pacman -Syu --noconfirm || warn "System upgrade failed; continuing installer"
;;
*) warn "Auto-update not supported for OS: $os" ;;
esac
ok "System update step finished"
}
install_packages() {
$SKIP_PACKAGES && return
log "Installing core packages..."
local os=$(detect_os)
case "$os" in
ubuntu|debian) sudo apt-get install -y zsh git vim curl wget unzip zip build-essential xz-utils ;;
fedora) sudo dnf install -y zsh git vim curl wget unzip zip @development-tools xz ;;
arch) sudo pacman -S --noconfirm zsh git vim curl wget unzip zip base-devel xz ;;
*) warn "Auto-install not supported for OS: $os. Please install zsh, git, vim, curl manually." ;;
esac
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)"
if ! grep -qx "$zsh_path" /etc/shells; then
echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
fi
chsh -s "$zsh_path"
ok "Shell changed (open a new WSL session for it to take effect)"
}
install_oh_my_zsh() {
log "Installing Oh My Zsh and plugins..."
export RUNZSH=no
export CHSH=no
export KEEP_ZSHRC=yes
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended
else
ok "Oh My Zsh already installed"
fi
local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
local plugin_dir="$custom/plugins"
mkdir -p "$plugin_dir"
[[ -d "$plugin_dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions"
[[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting"
ok "Oh My Zsh plugins installed to $plugin_dir"
}
install_starship() {
if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then
ok "Starship already installed"
else
log "Installing Starship prompt..."
if command -v brew >/dev/null 2>&1; then
brew install starship
else
mkdir -p "$HOME/.local/bin"
curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin"
fi
ok "Starship installed"
fi
}
download_configs() {
log "Downloading custom config files from OpenGist..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
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)"
}
configure_zshrc() {
local zshrc="$HOME/.zshrc"
log "Configuring .zshrc for Oh My Zsh and Starship..."
touch "$zshrc"
cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)"
cat > "$zshrc" <<'EOF'
# =============================================================================
# 1. HELPER FUNCTIONS & PATH
# =============================================================================
source_if_readable() {
local file="$1"
if [[ -f "$file" && -r "$file" ]]; then
source "$file"
fi
}
export PATH="$HOME/.local/bin:$PATH"
# =============================================================================
# 2. OH MY ZSH FRAMEWORK
# =============================================================================
export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
ZSH_THEME=""
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
source_if_readable "$ZSH/oh-my-zsh.sh"
# =============================================================================
# 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
# =============================================================================
source_if_readable "$HOME/.sourcerc"
source_if_readable "$HOME/.func"
source_if_readable "$HOME/.pathrc"
source_if_readable "$HOME/.alias"
# =============================================================================
# 4. STARSHIP PROMPT
# =============================================================================
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)"
elif [[ -x "$HOME/.local/bin/starship" ]]; then
eval "$("$HOME/.local/bin/starship" init zsh)"
fi
EOF
ok ".zshrc configured for Oh My Zsh framework with Starship prompt"
}
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 Minimal Zsh Installer - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-10)"
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 + plugins"
echo " 7) Install Starship prompt"
echo " 8) Download custom configs (from OpenGist)"
echo " 9) Configure ~/.zshrc (Oh My Zsh + Starship)"
echo "10) Switch to Zsh (Temporary Sub-shell)"
echo "11) 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)
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_starship ;;
8) download_configs ;;
9) configure_zshrc ;;
10) switch_shell ;;
11) 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. The script will request sudo when necessary." |
| 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 | local os=$(detect_os) |
| 77 | |
| 78 | case "$os" in |
| 79 | ubuntu|debian) |
| 80 | sudo apt-get update -y |
| 81 | if ! sudo apt-get upgrade -y; then |
| 82 | warn "System upgrade did not complete. This can happen when apt wants to downgrade a package." |
| 83 | warn "Continuing because the Zsh setup does not require OS package upgrades to finish." |
| 84 | fi |
| 85 | ;; |
| 86 | fedora) |
| 87 | sudo dnf upgrade -y || warn "System upgrade failed; continuing installer" |
| 88 | ;; |
| 89 | arch) |
| 90 | sudo pacman -Syu --noconfirm || warn "System upgrade failed; continuing installer" |
| 91 | ;; |
| 92 | *) warn "Auto-update not supported for OS: $os" ;; |
| 93 | esac |
| 94 | ok "System update step finished" |
| 95 | } |
| 96 | |
| 97 | install_packages() { |
| 98 | $SKIP_PACKAGES && return |
| 99 | log "Installing core packages..." |
| 100 | local os=$(detect_os) |
| 101 | |
| 102 | case "$os" in |
| 103 | ubuntu|debian) sudo apt-get install -y zsh git vim curl wget unzip zip build-essential xz-utils ;; |
| 104 | fedora) sudo dnf install -y zsh git vim curl wget unzip zip @development-tools xz ;; |
| 105 | arch) sudo pacman -S --noconfirm zsh git vim curl wget unzip zip base-devel xz ;; |
| 106 | *) warn "Auto-install not supported for OS: $os. Please install zsh, git, vim, curl manually." ;; |
| 107 | esac |
| 108 | ok "Packages installed" |
| 109 | } |
| 110 | |
| 111 | set_timezone() { |
| 112 | log "Checking timezone configuration..." |
| 113 | if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then |
| 114 | sudo timedatectl set-timezone Asia/Singapore |
| 115 | ok "Timezone set to Asia/Singapore" |
| 116 | return |
| 117 | fi |
| 118 | |
| 119 | warn "Skipping timezone change: timedatectl is not available in this WSL environment" |
| 120 | } |
| 121 | |
| 122 | install_homebrew() { |
| 123 | ! $INSTALL_HOMEBREW && return |
| 124 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 125 | log "Installing Homebrew..." |
| 126 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 127 | ok "Homebrew installed" |
| 128 | } |
| 129 | |
| 130 | configure_shell() { |
| 131 | $SKIP_SHELL_CHANGE && return |
| 132 | log "Changing default shell to zsh..." |
| 133 | local zsh_path |
| 134 | zsh_path="$(command -v zsh)" |
| 135 | |
| 136 | if ! grep -qx "$zsh_path" /etc/shells; then |
| 137 | echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 138 | fi |
| 139 | chsh -s "$zsh_path" |
| 140 | ok "Shell changed (open a new WSL session for it to take effect)" |
| 141 | } |
| 142 | |
| 143 | install_oh_my_zsh() { |
| 144 | log "Installing Oh My Zsh and plugins..." |
| 145 | export RUNZSH=no |
| 146 | export CHSH=no |
| 147 | export KEEP_ZSHRC=yes |
| 148 | |
| 149 | if [[ ! -d "$HOME/.oh-my-zsh" ]]; then |
| 150 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended |
| 151 | else |
| 152 | ok "Oh My Zsh already installed" |
| 153 | fi |
| 154 | |
| 155 | local custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" |
| 156 | local plugin_dir="$custom/plugins" |
| 157 | mkdir -p "$plugin_dir" |
| 158 | |
| 159 | [[ -d "$plugin_dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$plugin_dir/zsh-autosuggestions" |
| 160 | [[ -d "$plugin_dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$plugin_dir/zsh-syntax-highlighting" |
| 161 | |
| 162 | ok "Oh My Zsh plugins installed to $plugin_dir" |
| 163 | } |
| 164 | |
| 165 | install_starship() { |
| 166 | if command -v starship >/dev/null 2>&1 || [[ -f "$HOME/.local/bin/starship" ]]; then |
| 167 | ok "Starship already installed" |
| 168 | else |
| 169 | log "Installing Starship prompt..." |
| 170 | if command -v brew >/dev/null 2>&1; then |
| 171 | brew install starship |
| 172 | else |
| 173 | mkdir -p "$HOME/.local/bin" |
| 174 | curl -fsSL https://starship.rs/install.sh | sh -s -- -y -b "$HOME/.local/bin" |
| 175 | fi |
| 176 | ok "Starship installed" |
| 177 | fi |
| 178 | } |
| 179 | |
| 180 | download_configs() { |
| 181 | log "Downloading custom config files from OpenGist..." |
| 182 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 183 | mkdir -p "$backup" |
| 184 | |
| 185 | for f in "${CONFIG_FILES[@]}"; do |
| 186 | local remote_file="${f#.}" |
| 187 | [[ "$f" == ".config/starship.toml" ]] && remote_file="starship.toml" |
| 188 | local url="$GIST_RAW_BASE/$remote_file" |
| 189 | local target="$HOME/$f" |
| 190 | local tmp="${target}.tmp.$$" |
| 191 | |
| 192 | mkdir -p "$(dirname "$target")" |
| 193 | |
| 194 | if [[ -f "$target" ]]; then |
| 195 | cp "$target" "$backup/" |
| 196 | fi |
| 197 | |
| 198 | log "Fetching $remote_file -> $f ..." |
| 199 | if curl -fsSL "$url" -o "$tmp"; then |
| 200 | mv "$tmp" "$target" |
| 201 | else |
| 202 | rm -f "$tmp" |
| 203 | warn "Failed to download $remote_file" |
| 204 | fi |
| 205 | done |
| 206 | |
| 207 | ok "Configs downloaded (Backup at $backup)" |
| 208 | } |
| 209 | |
| 210 | configure_zshrc() { |
| 211 | local zshrc="$HOME/.zshrc" |
| 212 | log "Configuring .zshrc for Oh My Zsh and Starship..." |
| 213 | |
| 214 | touch "$zshrc" |
| 215 | cp "$zshrc" "$HOME/.zshrc.backup_$(date +%Y%m%d_%H%M%S)" |
| 216 | |
| 217 | cat > "$zshrc" <<'EOF' |
| 218 | # ============================================================================= |
| 219 | # 1. HELPER FUNCTIONS & PATH |
| 220 | # ============================================================================= |
| 221 | source_if_readable() { |
| 222 | local file="$1" |
| 223 | if [[ -f "$file" && -r "$file" ]]; then |
| 224 | source "$file" |
| 225 | fi |
| 226 | } |
| 227 | |
| 228 | export PATH="$HOME/.local/bin:$PATH" |
| 229 | |
| 230 | # ============================================================================= |
| 231 | # 2. OH MY ZSH FRAMEWORK |
| 232 | # ============================================================================= |
| 233 | export ZSH="${ZSH:-$HOME/.oh-my-zsh}" |
| 234 | ZSH_THEME="" |
| 235 | |
| 236 | plugins=( |
| 237 | git |
| 238 | zsh-autosuggestions |
| 239 | zsh-syntax-highlighting |
| 240 | ) |
| 241 | |
| 242 | source_if_readable "$ZSH/oh-my-zsh.sh" |
| 243 | |
| 244 | # ============================================================================= |
| 245 | # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS |
| 246 | # ============================================================================= |
| 247 | source_if_readable "$HOME/.sourcerc" |
| 248 | source_if_readable "$HOME/.func" |
| 249 | source_if_readable "$HOME/.pathrc" |
| 250 | source_if_readable "$HOME/.alias" |
| 251 | |
| 252 | # ============================================================================= |
| 253 | # 4. STARSHIP PROMPT |
| 254 | # ============================================================================= |
| 255 | if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then |
| 256 | export STARSHIP_CONFIG="$HOME/.config/starship.toml" |
| 257 | fi |
| 258 | |
| 259 | if command -v starship >/dev/null 2>&1; then |
| 260 | eval "$(starship init zsh)" |
| 261 | elif [[ -x "$HOME/.local/bin/starship" ]]; then |
| 262 | eval "$("$HOME/.local/bin/starship" init zsh)" |
| 263 | fi |
| 264 | EOF |
| 265 | |
| 266 | ok ".zshrc configured for Oh My Zsh framework with Starship prompt" |
| 267 | } |
| 268 | |
| 269 | switch_shell() { |
| 270 | log "Starting Zsh session..." |
| 271 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 272 | echo "----------------------------------------" |
| 273 | zsh -l |
| 274 | echo "----------------------------------------" |
| 275 | ok "Returned from Zsh session" |
| 276 | } |
| 277 | |
| 278 | # ============================= |
| 279 | # INTERACTIVE MENU |
| 280 | # ============================= |
| 281 | show_menu() { |
| 282 | echo "===========================================" |
| 283 | echo "WSL Minimal Zsh Installer - Choose what to do" |
| 284 | echo "===========================================" |
| 285 | echo " 0) Run ALL steps (1-10)" |
| 286 | echo " 1) Update system packages" |
| 287 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 288 | echo " 3) Set Timezone (best effort)" |
| 289 | echo " 4) Install Homebrew" |
| 290 | echo " 5) Configure shell (chsh - sets default shell)" |
| 291 | echo " 6) Install Oh My Zsh + plugins" |
| 292 | echo " 7) Install Starship prompt" |
| 293 | echo " 8) Download custom configs (from OpenGist)" |
| 294 | echo " 9) Configure ~/.zshrc (Oh My Zsh + Starship)" |
| 295 | echo "10) Switch to Zsh (Temporary Sub-shell)" |
| 296 | echo "11) Quit" |
| 297 | echo "===========================================" |
| 298 | } |
| 299 | |
| 300 | run_choices() { |
| 301 | local input |
| 302 | read -p "Select: " input |
| 303 | input="${input//,/ }" |
| 304 | |
| 305 | local -a to_run=() |
| 306 | local -a to_exclude=() |
| 307 | |
| 308 | for item in $input; do |
| 309 | if [[ "$item" == !* ]]; then |
| 310 | to_exclude+=("${item:1}") |
| 311 | elif [[ "$item" == "0" ]]; then |
| 312 | to_run+=(1 2 3 4 5 6 7 8 9 10) |
| 313 | else |
| 314 | to_run+=("$item") |
| 315 | fi |
| 316 | done |
| 317 | |
| 318 | for choice in "${to_run[@]}"; do |
| 319 | local skip=false |
| 320 | |
| 321 | for ex in "${to_exclude[@]}"; do |
| 322 | if [[ "$choice" == "$ex" ]]; then |
| 323 | skip=true |
| 324 | break |
| 325 | fi |
| 326 | done |
| 327 | |
| 328 | $skip && continue |
| 329 | |
| 330 | case "$choice" in |
| 331 | 1) update_system ;; |
| 332 | 2) install_packages ;; |
| 333 | 3) set_timezone ;; |
| 334 | 4) install_homebrew ;; |
| 335 | 5) configure_shell ;; |
| 336 | 6) install_oh_my_zsh ;; |
| 337 | 7) install_starship ;; |
| 338 | 8) download_configs ;; |
| 339 | 9) configure_zshrc ;; |
| 340 | 10) switch_shell ;; |
| 341 | 11) log "Exiting..."; exit 0 ;; |
| 342 | *) warn "Skipping invalid option: $choice" ;; |
| 343 | esac |
| 344 | echo |
| 345 | done |
| 346 | } |
| 347 | |
| 348 | # ============================= |
| 349 | # MAIN |
| 350 | # ============================= |
| 351 | main() { |
| 352 | check_requirements |
| 353 | while true; do |
| 354 | show_menu |
| 355 | run_choices |
| 356 | read -p "Do you want to run more options? (y/n): " again |
| 357 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 358 | done |
| 359 | ok "WSL Zsh installation/configuration complete!" |
| 360 | } |
| 361 | |
| 362 | main "$@" |
| 363 |
zshrc
· 1.9 KiB · Bash
Sin formato
# =============================================================================
# 1. HELPER FUNCTIONS & PATH
# =============================================================================
source_if_readable() {
local file="$1"
if [[ -f "$file" && -r "$file" ]]; then
source "$file"
fi
}
# Ensure local bin is in PATH early (catches manual Starship installations)
export PATH="$HOME/.local/bin:$PATH"
# =============================================================================
# 2. OH MY ZSH FRAMEWORK
# =============================================================================
export ZSH="${ZSH:-$HOME/.oh-my-zsh}"
ZSH_THEME=""
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
source_if_readable "$ZSH/oh-my-zsh.sh"
# =============================================================================
# 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS
# =============================================================================
# Load external initializers (SDKMAN, NVM, etc.)
source_if_readable "$HOME/.sourcerc"
# Custom Functions (must load before Path Management)
source_if_readable "$HOME/.func"
# Path Management (Relies on append_path from .func)
source_if_readable "$HOME/.pathrc"
# Aliases (Loaded late so they override framework/system defaults)
source_if_readable "$HOME/.alias"
# =============================================================================
# 4. STARSHIP PROMPT
# =============================================================================
if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then
export STARSHIP_CONFIG="$HOME/.config/starship.toml"
fi
# Starship owns the prompt. It must initialize after Oh My Zsh.
if command -v starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
elif [[ -x "$HOME/.local/bin/starship" ]]; then
eval "$("$HOME/.local/bin/starship" init zsh)"
fi
| 1 | # ============================================================================= |
| 2 | # 1. HELPER FUNCTIONS & PATH |
| 3 | # ============================================================================= |
| 4 | source_if_readable() { |
| 5 | local file="$1" |
| 6 | if [[ -f "$file" && -r "$file" ]]; then |
| 7 | source "$file" |
| 8 | fi |
| 9 | } |
| 10 | |
| 11 | # Ensure local bin is in PATH early (catches manual Starship installations) |
| 12 | export PATH="$HOME/.local/bin:$PATH" |
| 13 | |
| 14 | # ============================================================================= |
| 15 | # 2. OH MY ZSH FRAMEWORK |
| 16 | # ============================================================================= |
| 17 | export ZSH="${ZSH:-$HOME/.oh-my-zsh}" |
| 18 | ZSH_THEME="" |
| 19 | |
| 20 | plugins=( |
| 21 | git |
| 22 | zsh-autosuggestions |
| 23 | zsh-syntax-highlighting |
| 24 | ) |
| 25 | |
| 26 | source_if_readable "$ZSH/oh-my-zsh.sh" |
| 27 | |
| 28 | # ============================================================================= |
| 29 | # 3. THIRD-PARTY INITIALIZATION & CUSTOM CONFIGS |
| 30 | # ============================================================================= |
| 31 | # Load external initializers (SDKMAN, NVM, etc.) |
| 32 | source_if_readable "$HOME/.sourcerc" |
| 33 | |
| 34 | # Custom Functions (must load before Path Management) |
| 35 | source_if_readable "$HOME/.func" |
| 36 | |
| 37 | # Path Management (Relies on append_path from .func) |
| 38 | source_if_readable "$HOME/.pathrc" |
| 39 | |
| 40 | # Aliases (Loaded late so they override framework/system defaults) |
| 41 | source_if_readable "$HOME/.alias" |
| 42 | |
| 43 | # ============================================================================= |
| 44 | # 4. STARSHIP PROMPT |
| 45 | # ============================================================================= |
| 46 | if [[ -z "${STARSHIP_CONFIG:-}" && -f "$HOME/.config/starship.toml" ]]; then |
| 47 | export STARSHIP_CONFIG="$HOME/.config/starship.toml" |
| 48 | fi |
| 49 | |
| 50 | # Starship owns the prompt. It must initialize after Oh My Zsh. |
| 51 | if command -v starship >/dev/null 2>&1; then |
| 52 | eval "$(starship init zsh)" |
| 53 | elif [[ -x "$HOME/.local/bin/starship" ]]; then |
| 54 | eval "$("$HOME/.local/bin/starship" init zsh)" |
| 55 | fi |
| 56 |