README.md
· 505 B · Markdown
Неформатований
# Bash Script Installer for Zsh
The "Bash Script Installer" simplifies the setup of Zsh.
## Zsh
### Ubuntu
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
```
### WSL
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
```
### MacOS
```zsh
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
```
Bash Script Installer for Zsh
The "Bash Script Installer" simplifies the setup of Zsh.
Zsh
Ubuntu
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_ubuntu.sh)"
WSL
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_wsl.sh)"
MacOS
bash -c "$(curl -fsSL https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD/zsh_macos.sh)"
alias
· 1.1 KiB · Text
Неформатований
# =============================================================================
# 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' |
func
· 6.8 KiB · Text
Неформатований
# =============================================================================
# CUSTOM FUNCTIONS
# =============================================================================
# -----------------------------------------------------------------------------
# Function: clip
# -----------------------------------------------------------------------------
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
# Use native macOS open
command open "$target"
elif grep -qi "microsoft" /proc/version 2>/dev/null; then
# Use WSL Explorer
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. Windows interop might be disabled.\n" >&2
return 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Use Linux xdg-open
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
# -----------------------------------------------------------------------------
clear_history() {
# Clears the history file and reloads the current session's history for Zsh
>| "$HISTFILE" && fc -R
echo "History cleared."
}
# -----------------------------------------------------------------------------
# Function: claude
# -----------------------------------------------------------------------------
claude() {
# Run the check in a subshell, unsetting the function first so it only finds the binary
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
if [[ "$1" == "--yolo" ]]; then
shift
command claude --dangerously-skip-permissions "$@"
return $?
fi
command claude "$@"
}
# -----------------------------------------------------------------------------
# Function: create
# -----------------------------------------------------------------------------
create() {
if ! command -v install >/dev/null 2>&1; then
printf "Error: 'install' coreutil is not available on this system.\n" >&2
return 1
fi
if [ $# -eq 0 ]; then
printf "Usage: create <file> [file ...]\n" >&2
return 2
fi
for p in "$@"; do
if [ "${p#\~}" != "$p" ]; then
p="${HOME}${p#\~}"
fi
if [ -z "$p" ] || [ "$p" = "/" ]; then
printf "create: refusing to operate on '%s'\n" "$p" >&2
return 1
fi
if [ -e "$p" ]; then
printf "create: '%s' already exists. Skipping.\n" "$p" >&2
continue
fi
if ! install -D /dev/null "$p"; then
printf "create: failed to create '%s'\n" "$p" >&2
return 1
fi
done
return 0
}
# -----------------------------------------------------------------------------
# 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
if lsof -i :"$PORT" >/dev/null 2>&1; then
echo "Port $PORT is IN USE"
lsof -i :"$PORT"
else
echo "Port $PORT is FREE"
fi
else
if ! command -v ss >/dev/null 2>&1; then
printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2
return 1
fi
if sudo ss -tulnp | grep -q ":$PORT "; then
echo "Port $PORT is IN USE"
sudo ss -tulnp | grep ":$PORT "
else
echo "Port $PORT is FREE"
fi
fi
}
# -----------------------------------------------------------------------------
# Function: append_path
# -----------------------------------------------------------------------------
append_path() {
local dir="$1"
if [ -d "$dir" ]; then
case ":$PATH:" in
*":$dir:"*) ;; # Already in PATH
*) PATH="$PATH:$dir" ;;
esac
elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then
echo "Warning: $dir does not exist." >&2
fi
}
# -----------------------------------------------------------------------------
# Function: add_path_to_config
# -----------------------------------------------------------------------------
add_path_to_config() {
local new_path="$1"
local config_file="$HOME/.bashrc"
if [[ "$SHELL" == *"zsh"* ]]; then
config_file="$HOME/.zshrc"
fi
if [ -z "$new_path" ]; then
printf "Usage: addpath <directory>\n" >&2
return 1
fi
new_path="${new_path/#\~/$HOME}"
if [ ! -d "$new_path" ]; then
printf "Warning: '%s' does not exist.\n" "$new_path" >&2
printf "Do you still want to add it to your config? (y/N) "
read -r -k 1 REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return 1
fi
fi
if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then
printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file"
return 0
fi
if grep -q "^export PATH" "$config_file"; then
awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
else
echo "append_path \"$new_path\"" >> "$config_file"
echo "export PATH" >> "$config_file"
fi
printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file"
if type append_path >/dev/null 2>&1; then
append_path "$new_path"
export PATH
printf "🚀 Path is now active in your current session!\n"
fi
}
| 1 | # ============================================================================= |
| 2 | # CUSTOM FUNCTIONS |
| 3 | # ============================================================================= |
| 4 | |
| 5 | # ----------------------------------------------------------------------------- |
| 6 | # Function: clip |
| 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 | # Use native macOS open |
| 50 | command open "$target" |
| 51 | elif grep -qi "microsoft" /proc/version 2>/dev/null; then |
| 52 | # Use WSL Explorer |
| 53 | if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then |
| 54 | explorer.exe "$(wslpath -w "$target")" |
| 55 | else |
| 56 | printf "Error: 'wslpath' or 'explorer.exe' not found. Windows interop might be disabled.\n" >&2 |
| 57 | return 1 |
| 58 | fi |
| 59 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 60 | # Use Linux xdg-open |
| 61 | if command -v xdg-open >/dev/null 2>&1; then |
| 62 | xdg-open "$target" |
| 63 | else |
| 64 | printf "Error: 'xdg-open' not found.\n" >&2 |
| 65 | return 1 |
| 66 | fi |
| 67 | fi |
| 68 | } |
| 69 | alias open='open_file' |
| 70 | |
| 71 | # ----------------------------------------------------------------------------- |
| 72 | # Function: clear_history |
| 73 | # ----------------------------------------------------------------------------- |
| 74 | clear_history() { |
| 75 | # Clears the history file and reloads the current session's history for Zsh |
| 76 | >| "$HISTFILE" && fc -R |
| 77 | echo "History cleared." |
| 78 | } |
| 79 | |
| 80 | # ----------------------------------------------------------------------------- |
| 81 | # Function: claude |
| 82 | # ----------------------------------------------------------------------------- |
| 83 | claude() { |
| 84 | # Run the check in a subshell, unsetting the function first so it only finds the binary |
| 85 | if ! whence -p claude >/dev/null 2>&1; then |
| 86 | printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2 |
| 87 | return 1 |
| 88 | fi |
| 89 | |
| 90 | if [[ "$1" == "--yolo" ]]; then |
| 91 | shift |
| 92 | command claude --dangerously-skip-permissions "$@" |
| 93 | return $? |
| 94 | fi |
| 95 | |
| 96 | command claude "$@" |
| 97 | } |
| 98 | |
| 99 | # ----------------------------------------------------------------------------- |
| 100 | # Function: create |
| 101 | # ----------------------------------------------------------------------------- |
| 102 | create() { |
| 103 | if ! command -v install >/dev/null 2>&1; then |
| 104 | printf "Error: 'install' coreutil is not available on this system.\n" >&2 |
| 105 | return 1 |
| 106 | fi |
| 107 | |
| 108 | if [ $# -eq 0 ]; then |
| 109 | printf "Usage: create <file> [file ...]\n" >&2 |
| 110 | return 2 |
| 111 | fi |
| 112 | |
| 113 | for p in "$@"; do |
| 114 | if [ "${p#\~}" != "$p" ]; then |
| 115 | p="${HOME}${p#\~}" |
| 116 | fi |
| 117 | |
| 118 | if [ -z "$p" ] || [ "$p" = "/" ]; then |
| 119 | printf "create: refusing to operate on '%s'\n" "$p" >&2 |
| 120 | return 1 |
| 121 | fi |
| 122 | |
| 123 | if [ -e "$p" ]; then |
| 124 | printf "create: '%s' already exists. Skipping.\n" "$p" >&2 |
| 125 | continue |
| 126 | fi |
| 127 | |
| 128 | if ! install -D /dev/null "$p"; then |
| 129 | printf "create: failed to create '%s'\n" "$p" >&2 |
| 130 | return 1 |
| 131 | fi |
| 132 | done |
| 133 | return 0 |
| 134 | } |
| 135 | |
| 136 | # ----------------------------------------------------------------------------- |
| 137 | # Function: check_port |
| 138 | # ----------------------------------------------------------------------------- |
| 139 | check_port() { |
| 140 | local PORT=$1 |
| 141 | |
| 142 | if [ -z "$PORT" ]; then |
| 143 | printf "Usage: check_port <port_number>\n" >&2 |
| 144 | return 1 |
| 145 | fi |
| 146 | |
| 147 | if [[ "$OSTYPE" == "darwin"* ]]; then |
| 148 | if lsof -i :"$PORT" >/dev/null 2>&1; then |
| 149 | echo "Port $PORT is IN USE" |
| 150 | lsof -i :"$PORT" |
| 151 | else |
| 152 | echo "Port $PORT is FREE" |
| 153 | fi |
| 154 | else |
| 155 | if ! command -v ss >/dev/null 2>&1; then |
| 156 | printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2 |
| 157 | return 1 |
| 158 | fi |
| 159 | |
| 160 | if sudo ss -tulnp | grep -q ":$PORT "; then |
| 161 | echo "Port $PORT is IN USE" |
| 162 | sudo ss -tulnp | grep ":$PORT " |
| 163 | else |
| 164 | echo "Port $PORT is FREE" |
| 165 | fi |
| 166 | fi |
| 167 | } |
| 168 | |
| 169 | # ----------------------------------------------------------------------------- |
| 170 | # Function: append_path |
| 171 | # ----------------------------------------------------------------------------- |
| 172 | append_path() { |
| 173 | local dir="$1" |
| 174 | if [ -d "$dir" ]; then |
| 175 | case ":$PATH:" in |
| 176 | *":$dir:"*) ;; # Already in PATH |
| 177 | *) PATH="$PATH:$dir" ;; |
| 178 | esac |
| 179 | elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then |
| 180 | echo "Warning: $dir does not exist." >&2 |
| 181 | fi |
| 182 | } |
| 183 | |
| 184 | # ----------------------------------------------------------------------------- |
| 185 | # Function: add_path_to_config |
| 186 | # ----------------------------------------------------------------------------- |
| 187 | add_path_to_config() { |
| 188 | local new_path="$1" |
| 189 | local config_file="$HOME/.bashrc" |
| 190 | |
| 191 | if [[ "$SHELL" == *"zsh"* ]]; then |
| 192 | config_file="$HOME/.zshrc" |
| 193 | fi |
| 194 | |
| 195 | if [ -z "$new_path" ]; then |
| 196 | printf "Usage: addpath <directory>\n" >&2 |
| 197 | return 1 |
| 198 | fi |
| 199 | |
| 200 | new_path="${new_path/#\~/$HOME}" |
| 201 | |
| 202 | if [ ! -d "$new_path" ]; then |
| 203 | printf "Warning: '%s' does not exist.\n" "$new_path" >&2 |
| 204 | printf "Do you still want to add it to your config? (y/N) " |
| 205 | read -r -k 1 REPLY |
| 206 | echo |
| 207 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 208 | return 1 |
| 209 | fi |
| 210 | fi |
| 211 | |
| 212 | if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then |
| 213 | printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file" |
| 214 | return 0 |
| 215 | fi |
| 216 | |
| 217 | if grep -q "^export PATH" "$config_file"; then |
| 218 | awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file" |
| 219 | else |
| 220 | echo "append_path \"$new_path\"" >> "$config_file" |
| 221 | echo "export PATH" >> "$config_file" |
| 222 | fi |
| 223 | |
| 224 | printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file" |
| 225 | |
| 226 | if type append_path >/dev/null 2>&1; then |
| 227 | append_path "$new_path" |
| 228 | export PATH |
| 229 | printf "🚀 Path is now active in your current session!\n" |
| 230 | fi |
| 231 | } |
| 232 |
pathrc
· 6.6 KiB · Text
Неформатований
# =============================================================================
# CUSTOM FUNCTIONS
# =============================================================================
# -----------------------------------------------------------------------------
# Function: clip
# -----------------------------------------------------------------------------
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 (Cross-platform file/directory opener)
# -----------------------------------------------------------------------------
open_file() {
local target="${1:-.}"
if [[ "$OSTYPE" == "darwin"* ]]; then
# Use native macOS open
command open "$target"
elif grep -qi "microsoft" /proc/version 2>/dev/null; then
# Use WSL Explorer
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. Windows interop might be disabled.\n" >&2
return 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Use Linux xdg-open
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
# -----------------------------------------------------------------------------
clear_history() {
history -p
}
# -----------------------------------------------------------------------------
# Function: claude
# -----------------------------------------------------------------------------
claude() {
if ! command -v claude >/dev/null 2>&1; then
printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2
return 1
fi
if [[ "$1" == "--yolo" ]]; then
shift
command claude --dangerously-skip-permissions "$@"
return $?
fi
command claude "$@"
}
# -----------------------------------------------------------------------------
# Function: create
# -----------------------------------------------------------------------------
create() {
if ! command -v install >/dev/null 2>&1; then
printf "Error: 'install' coreutil is not available on this system.\n" >&2
return 1
fi
if [ $# -eq 0 ]; then
printf "Usage: create <file> [file ...]\n" >&2
return 2
fi
for p in "$@"; do
if [ "${p#\~}" != "$p" ]; then
p="${HOME}${p#\~}"
fi
if [ -z "$p" ] || [ "$p" = "/" ]; then
printf "create: refusing to operate on '%s'\n" "$p" >&2
return 1
fi
if [ -e "$p" ]; then
printf "create: '%s' already exists. Skipping.\n" "$p" >&2
continue
fi
if ! install -D /dev/null "$p"; then
printf "create: failed to create '%s'\n" "$p" >&2
return 1
fi
done
return 0
}
# -----------------------------------------------------------------------------
# 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
if lsof -i :"$PORT" >/dev/null 2>&1; then
echo "Port $PORT is IN USE"
lsof -i :"$PORT"
else
echo "Port $PORT is FREE"
fi
else
if ! command -v ss >/dev/null 2>&1; then
printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2
return 1
fi
if sudo ss -tulnp | grep -q ":$PORT "; then
echo "Port $PORT is IN USE"
sudo ss -tulnp | grep ":$PORT "
else
echo "Port $PORT is FREE"
fi
fi
}
# -----------------------------------------------------------------------------
# Function: append_path
# -----------------------------------------------------------------------------
append_path() {
local dir="$1"
if [ -d "$dir" ]; then
case ":$PATH:" in
*":$dir:"*) ;; # Already in PATH
*) PATH="$PATH:$dir" ;;
esac
elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then
echo "Warning: $dir does not exist." >&2
fi
}
# -----------------------------------------------------------------------------
# Function: add_path_to_config
# -----------------------------------------------------------------------------
add_path_to_config() {
local new_path="$1"
local config_file="$HOME/.bashrc"
if [[ "$SHELL" == *"zsh"* ]]; then
config_file="$HOME/.zshrc"
fi
if [ -z "$new_path" ]; then
printf "Usage: addpath <directory>\n" >&2
return 1
fi
new_path="${new_path/#\~/$HOME}"
if [ ! -d "$new_path" ]; then
printf "Warning: '%s' does not exist.\n" "$new_path" >&2
read -p "Do you still want to add it to your config? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return 1
fi
fi
if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then
printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file"
return 0
fi
if grep -q "^export PATH" "$config_file"; then
awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file"
else
echo "append_path \"$new_path\"" >> "$config_file"
echo "export PATH" >> "$config_file"
fi
printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file"
if type append_path >/dev/null 2>&1; then
append_path "$new_path"
export PATH
printf "🚀 Path is now active in your current session!\n"
fi
}
append_path "$HOME/.local/bin"
export PATH
| 1 | # ============================================================================= |
| 2 | # CUSTOM FUNCTIONS |
| 3 | # ============================================================================= |
| 4 | |
| 5 | # ----------------------------------------------------------------------------- |
| 6 | # Function: clip |
| 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 (Cross-platform file/directory opener) |
| 44 | # ----------------------------------------------------------------------------- |
| 45 | open_file() { |
| 46 | local target="${1:-.}" |
| 47 | |
| 48 | if [[ "$OSTYPE" == "darwin"* ]]; then |
| 49 | # Use native macOS open |
| 50 | command open "$target" |
| 51 | elif grep -qi "microsoft" /proc/version 2>/dev/null; then |
| 52 | # Use WSL Explorer |
| 53 | if command -v wslpath >/dev/null 2>&1 && command -v explorer.exe >/dev/null 2>&1; then |
| 54 | explorer.exe "$(wslpath -w "$target")" |
| 55 | else |
| 56 | printf "Error: 'wslpath' or 'explorer.exe' not found. Windows interop might be disabled.\n" >&2 |
| 57 | return 1 |
| 58 | fi |
| 59 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then |
| 60 | # Use Linux xdg-open |
| 61 | if command -v xdg-open >/dev/null 2>&1; then |
| 62 | xdg-open "$target" |
| 63 | else |
| 64 | printf "Error: 'xdg-open' not found.\n" >&2 |
| 65 | return 1 |
| 66 | fi |
| 67 | fi |
| 68 | } |
| 69 | alias open='open_file' |
| 70 | |
| 71 | # ----------------------------------------------------------------------------- |
| 72 | # Function: clear_history |
| 73 | # ----------------------------------------------------------------------------- |
| 74 | clear_history() { |
| 75 | history -p |
| 76 | } |
| 77 | |
| 78 | # ----------------------------------------------------------------------------- |
| 79 | # Function: claude |
| 80 | # ----------------------------------------------------------------------------- |
| 81 | claude() { |
| 82 | if ! command -v claude >/dev/null 2>&1; then |
| 83 | printf "Error: 'claude' CLI is not installed or not in your PATH.\n" >&2 |
| 84 | return 1 |
| 85 | fi |
| 86 | |
| 87 | if [[ "$1" == "--yolo" ]]; then |
| 88 | shift |
| 89 | command claude --dangerously-skip-permissions "$@" |
| 90 | return $? |
| 91 | fi |
| 92 | |
| 93 | command claude "$@" |
| 94 | } |
| 95 | |
| 96 | # ----------------------------------------------------------------------------- |
| 97 | # Function: create |
| 98 | # ----------------------------------------------------------------------------- |
| 99 | create() { |
| 100 | if ! command -v install >/dev/null 2>&1; then |
| 101 | printf "Error: 'install' coreutil is not available on this system.\n" >&2 |
| 102 | return 1 |
| 103 | fi |
| 104 | |
| 105 | if [ $# -eq 0 ]; then |
| 106 | printf "Usage: create <file> [file ...]\n" >&2 |
| 107 | return 2 |
| 108 | fi |
| 109 | |
| 110 | for p in "$@"; do |
| 111 | if [ "${p#\~}" != "$p" ]; then |
| 112 | p="${HOME}${p#\~}" |
| 113 | fi |
| 114 | |
| 115 | if [ -z "$p" ] || [ "$p" = "/" ]; then |
| 116 | printf "create: refusing to operate on '%s'\n" "$p" >&2 |
| 117 | return 1 |
| 118 | fi |
| 119 | |
| 120 | if [ -e "$p" ]; then |
| 121 | printf "create: '%s' already exists. Skipping.\n" "$p" >&2 |
| 122 | continue |
| 123 | fi |
| 124 | |
| 125 | if ! install -D /dev/null "$p"; then |
| 126 | printf "create: failed to create '%s'\n" "$p" >&2 |
| 127 | return 1 |
| 128 | fi |
| 129 | done |
| 130 | return 0 |
| 131 | } |
| 132 | |
| 133 | # ----------------------------------------------------------------------------- |
| 134 | # Function: check_port |
| 135 | # ----------------------------------------------------------------------------- |
| 136 | check_port() { |
| 137 | local PORT=$1 |
| 138 | |
| 139 | if [ -z "$PORT" ]; then |
| 140 | printf "Usage: check_port <port_number>\n" >&2 |
| 141 | return 1 |
| 142 | fi |
| 143 | |
| 144 | if [[ "$OSTYPE" == "darwin"* ]]; then |
| 145 | if lsof -i :"$PORT" >/dev/null 2>&1; then |
| 146 | echo "Port $PORT is IN USE" |
| 147 | lsof -i :"$PORT" |
| 148 | else |
| 149 | echo "Port $PORT is FREE" |
| 150 | fi |
| 151 | else |
| 152 | if ! command -v ss >/dev/null 2>&1; then |
| 153 | printf "Error: 'ss' command not found. This function requires Linux iproute2 utilities.\n" >&2 |
| 154 | return 1 |
| 155 | fi |
| 156 | |
| 157 | if sudo ss -tulnp | grep -q ":$PORT "; then |
| 158 | echo "Port $PORT is IN USE" |
| 159 | sudo ss -tulnp | grep ":$PORT " |
| 160 | else |
| 161 | echo "Port $PORT is FREE" |
| 162 | fi |
| 163 | fi |
| 164 | } |
| 165 | |
| 166 | # ----------------------------------------------------------------------------- |
| 167 | # Function: append_path |
| 168 | # ----------------------------------------------------------------------------- |
| 169 | append_path() { |
| 170 | local dir="$1" |
| 171 | if [ -d "$dir" ]; then |
| 172 | case ":$PATH:" in |
| 173 | *":$dir:"*) ;; # Already in PATH |
| 174 | *) PATH="$PATH:$dir" ;; |
| 175 | esac |
| 176 | elif [ "${SUPPRESS_WARNINGS:-0}" -ne 1 ]; then |
| 177 | echo "Warning: $dir does not exist." >&2 |
| 178 | fi |
| 179 | } |
| 180 | |
| 181 | # ----------------------------------------------------------------------------- |
| 182 | # Function: add_path_to_config |
| 183 | # ----------------------------------------------------------------------------- |
| 184 | add_path_to_config() { |
| 185 | local new_path="$1" |
| 186 | local config_file="$HOME/.bashrc" |
| 187 | |
| 188 | if [[ "$SHELL" == *"zsh"* ]]; then |
| 189 | config_file="$HOME/.zshrc" |
| 190 | fi |
| 191 | |
| 192 | if [ -z "$new_path" ]; then |
| 193 | printf "Usage: addpath <directory>\n" >&2 |
| 194 | return 1 |
| 195 | fi |
| 196 | |
| 197 | new_path="${new_path/#\~/$HOME}" |
| 198 | |
| 199 | if [ ! -d "$new_path" ]; then |
| 200 | printf "Warning: '%s' does not exist.\n" "$new_path" >&2 |
| 201 | read -p "Do you still want to add it to your config? (y/N) " -n 1 -r |
| 202 | echo |
| 203 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 204 | return 1 |
| 205 | fi |
| 206 | fi |
| 207 | |
| 208 | if grep -Fq "append_path \"$new_path\"" "$config_file" || grep -Fq "append_path '$new_path'" "$config_file"; then |
| 209 | printf "Notice: '%s' is already in your %s.\n" "$new_path" "$config_file" |
| 210 | return 0 |
| 211 | fi |
| 212 | |
| 213 | if grep -q "^export PATH" "$config_file"; then |
| 214 | awk -v new_cmd="append_path \"$new_path\"" '/^export PATH/{print new_cmd}1' "$config_file" > "${config_file}.tmp" && mv "${config_file}.tmp" "$config_file" |
| 215 | else |
| 216 | echo "append_path \"$new_path\"" >> "$config_file" |
| 217 | echo "export PATH" >> "$config_file" |
| 218 | fi |
| 219 | |
| 220 | printf "✅ Success: Added '%s' to %s\n" "$new_path" "$config_file" |
| 221 | |
| 222 | if type append_path >/dev/null 2>&1; then |
| 223 | append_path "$new_path" |
| 224 | export PATH |
| 225 | printf "🚀 Path is now active in your current session!\n" |
| 226 | fi |
| 227 | } |
| 228 | |
| 229 | append_path "$HOME/.local/bin" |
| 230 | export PATH |
| 231 |
sourcerc
· 5.6 KiB · Text
Неформатований
# =============================================================================
# FILE: ~/.sourcerc
# Description: Initializes third-party package managers and Oh My Zsh.
# =============================================================================
# Source the custom environment setup file if it exists and is not empty
if [[ -s "$HOME/.local/bin/env" ]]; then
source "$HOME/.local/bin/env"
fi
# Source the SDKMAN initialization script if it exists and is not empty
if [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
source "$HOME/.sdkman/bin/sdkman-init.sh"
fi
# Source the NVM initialization script if it exists and is not empty
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
source "$HOME/.nvm/nvm.sh"
fi
# ==========================================
# CLAUDE CODE / AI GATEWAY
# ==========================================
export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic"
export OPENAI_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/codex-gateway/openai"
# ==========================================
# OH MY ZSH
# ==========================================
if [[ -s "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then
source "$HOME/.oh-my-zsh/oh-my-zsh.sh"
else
echo "Warning: Oh My Zsh not found or is empty."
fi
# ==========================================
# NVM (Node Version Manager)
# ==========================================
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
| 1 | # ============================================================================= |
| 2 | # FILE: ~/.sourcerc |
| 3 | # Description: Initializes third-party package managers and Oh My Zsh. |
| 4 | # ============================================================================= |
| 5 | |
| 6 | # Source the custom environment setup file if it exists and is not empty |
| 7 | if [[ -s "$HOME/.local/bin/env" ]]; then |
| 8 | source "$HOME/.local/bin/env" |
| 9 | fi |
| 10 | |
| 11 | # Source the SDKMAN initialization script if it exists and is not empty |
| 12 | if [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then |
| 13 | source "$HOME/.sdkman/bin/sdkman-init.sh" |
| 14 | fi |
| 15 | |
| 16 | # Source the NVM initialization script if it exists and is not empty |
| 17 | if [[ -s "$HOME/.nvm/nvm.sh" ]]; then |
| 18 | source "$HOME/.nvm/nvm.sh" |
| 19 | fi |
| 20 | |
| 21 | # ========================================== |
| 22 | # CLAUDE CODE / AI GATEWAY |
| 23 | # ========================================== |
| 24 | export ANTHROPIC_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/claude-code-gateway/anthropic" |
| 25 | export OPENAI_BASE_URL="https://gateway.ai.cloudflare.com/v1/9a71825e3842e918e0dff9ad84f50484/codex-gateway/openai" |
| 26 | |
| 27 | # ========================================== |
| 28 | # OH MY ZSH |
| 29 | # ========================================== |
| 30 | if [[ -s "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then |
| 31 | source "$HOME/.oh-my-zsh/oh-my-zsh.sh" |
| 32 | else |
| 33 | echo "Warning: Oh My Zsh not found or is empty." |
| 34 | fi |
| 35 | |
| 36 | # ========================================== |
| 37 | # NVM (Node Version Manager) |
| 38 | # ========================================== |
| 39 | export NVM_DIR="$HOME/.nvm" |
| 40 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" |
| 41 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" |
vimrc
· 2.9 KiB · VimL
Неформатований
" 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
· 5.6 KiB · Bash
Неформатований
#!/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"
)
# =============================
# REQUIREMENTS
# =============================
check_requirements() {
if [[ $EUID -eq 0 ]]; then
err "Do not run as root on macOS"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
install_oh_my_zsh() {
if [[ -d "$HOME/.oh-my-zsh" ]]; then
ok "Oh My Zsh already installed"
return
fi
log "Installing Oh My Zsh..."
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok "Oh My Zsh installed"
}
install_plugins() {
log "Installing plugins..."
local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
mkdir -p "$dir"
[[ -d "$dir/zsh-autosuggestions" ]] || \
git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
[[ -d "$dir/zsh-syntax-highlighting" ]] || \
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
ok "Plugins installed"
}
install_theme() {
log "Installing Spaceship theme..."
local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
local dir="$themes/spaceship-prompt"
mkdir -p "$themes"
[[ -d "$dir" ]] || \
git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
ok "Theme installed"
}
download_configs() {
log "Downloading custom config files..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
# Strip the leading dot for the download URL
local remote_file="${f#.}"
local url="$GIST_RAW_BASE/$remote_file"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $remote_file -> $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $remote_file"
fi
done
ok "Configs downloaded (Backup at $backup)"
}
update_zshrc() {
local zshrc="$HOME/.zshrc"
log "Checking .zshrc..."
if [[ ! -f "$zshrc" ]]; then
warn ".zshrc not found. Run option 5 first."
return 1
fi
ok ".zshrc already comes from the managed gist."
ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
}
switch_shell() {
log "Starting Zsh session..."
echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
echo "----------------------------------------"
zsh -l
echo "----------------------------------------"
ok "Returned from Zsh session"
}
# =============================
# INTERACTIVE MENU
# =============================
show_menu() {
echo "==========================================="
echo "macOS Zsh Setup - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-7)"
echo " 1) Install Oh My Zsh"
echo " 2) Install plugins (autosuggestions, syntax highlighting)"
echo " 3) Install Spaceship theme"
echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)"
echo " 5) Check ~/.zshrc load order"
echo " 6) Switch to Zsh (Temporary Sub-shell)"
echo " 7) Quit"
echo "==========================================="
}
run_choices() {
local input
read -p "Select: " input
input="${input//,/ }"
local -a to_run=()
local -a to_exclude=()
for item in $input; do
if [[ "$item" == !* ]]; then
to_exclude+=("${item:1}")
elif [[ "$item" == "0" ]]; then
to_run+=(1 2 3 4 5 6)
else
to_run+=("$item")
fi
done
if [[ ${#to_run[@]} -gt 0 ]]; then
for choice in "${to_run[@]}"; do
local skip=false
if [[ ${#to_exclude[@]} -gt 0 ]]; then
for ex in "${to_exclude[@]}"; do
if [[ "$choice" == "$ex" ]]; then
skip=true
break
fi
done
fi
$skip && continue
case "$choice" in
1) install_oh_my_zsh ;;
2) install_plugins ;;
3) install_theme ;;
4) download_configs ;;
5) update_zshrc ;;
6) switch_shell ;;
7) exit 0 ;;
*) warn "Skipping invalid option: $choice" ;;
esac
echo
done
fi
}
# =============================
# MAIN
# =============================
main() {
check_requirements
while true; do
show_menu
run_choices
read -p "Do you want to run more options? (y/n): " again
[[ "$again" =~ ^[Yy]$ ]] || break
done
ok "macOS configuration complete!"
}
main "$@"
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # ============================= |
| 5 | # COLORS & LOGGING |
| 6 | # ============================= |
| 7 | RED='\033[0;31m' |
| 8 | GREEN='\033[0;32m' |
| 9 | YELLOW='\033[1;33m' |
| 10 | BLUE='\033[0;34m' |
| 11 | NC='\033[0m' |
| 12 | |
| 13 | log() { echo -e "${BLUE}[INFO]${NC} $*"; } |
| 14 | ok() { echo -e "${GREEN}[OK]${NC} $*"; } |
| 15 | warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } |
| 16 | err() { echo -e "${RED}[ERROR]${NC} $*" >&2; } |
| 17 | |
| 18 | # ============================= |
| 19 | # CONFIG |
| 20 | # ============================= |
| 21 | GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 22 | |
| 23 | CONFIG_FILES=( |
| 24 | ".alias" |
| 25 | ".func" |
| 26 | ".pathrc" |
| 27 | ".sourcerc" |
| 28 | ".vimrc" |
| 29 | ".zshrc" |
| 30 | ) |
| 31 | |
| 32 | # ============================= |
| 33 | # REQUIREMENTS |
| 34 | # ============================= |
| 35 | check_requirements() { |
| 36 | if [[ $EUID -eq 0 ]]; then |
| 37 | err "Do not run as root on macOS" |
| 38 | exit 1 |
| 39 | fi |
| 40 | } |
| 41 | |
| 42 | # ============================= |
| 43 | # INSTALLATION FUNCTIONS |
| 44 | # ============================= |
| 45 | install_oh_my_zsh() { |
| 46 | if [[ -d "$HOME/.oh-my-zsh" ]]; then |
| 47 | ok "Oh My Zsh already installed" |
| 48 | return |
| 49 | fi |
| 50 | |
| 51 | log "Installing Oh My Zsh..." |
| 52 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 53 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 54 | ok "Oh My Zsh installed" |
| 55 | } |
| 56 | |
| 57 | install_plugins() { |
| 58 | log "Installing plugins..." |
| 59 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 60 | mkdir -p "$dir" |
| 61 | |
| 62 | [[ -d "$dir/zsh-autosuggestions" ]] || \ |
| 63 | git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 64 | |
| 65 | [[ -d "$dir/zsh-syntax-highlighting" ]] || \ |
| 66 | git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 67 | |
| 68 | ok "Plugins installed" |
| 69 | } |
| 70 | |
| 71 | install_theme() { |
| 72 | log "Installing Spaceship theme..." |
| 73 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 74 | local dir="$themes/spaceship-prompt" |
| 75 | |
| 76 | mkdir -p "$themes" |
| 77 | [[ -d "$dir" ]] || \ |
| 78 | git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 79 | |
| 80 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 81 | ok "Theme installed" |
| 82 | } |
| 83 | |
| 84 | download_configs() { |
| 85 | log "Downloading custom config files..." |
| 86 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 87 | mkdir -p "$backup" |
| 88 | |
| 89 | for f in "${CONFIG_FILES[@]}"; do |
| 90 | # Strip the leading dot for the download URL |
| 91 | local remote_file="${f#.}" |
| 92 | local url="$GIST_RAW_BASE/$remote_file" |
| 93 | local target="$HOME/$f" |
| 94 | local tmp="${target}.tmp.$$" |
| 95 | |
| 96 | if [[ -f "$target" ]]; then |
| 97 | cp "$target" "$backup/" |
| 98 | fi |
| 99 | |
| 100 | log "Fetching $remote_file -> $f ..." |
| 101 | if curl -fsSL "$url" -o "$tmp"; then |
| 102 | mv "$tmp" "$target" |
| 103 | else |
| 104 | rm -f "$tmp" |
| 105 | warn "Failed to download $remote_file" |
| 106 | fi |
| 107 | done |
| 108 | |
| 109 | ok "Configs downloaded (Backup at $backup)" |
| 110 | } |
| 111 | |
| 112 | update_zshrc() { |
| 113 | local zshrc="$HOME/.zshrc" |
| 114 | log "Checking .zshrc..." |
| 115 | |
| 116 | if [[ ! -f "$zshrc" ]]; then |
| 117 | warn ".zshrc not found. Run option 5 first." |
| 118 | return 1 |
| 119 | fi |
| 120 | |
| 121 | ok ".zshrc already comes from the managed gist." |
| 122 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 123 | } |
| 124 | |
| 125 | switch_shell() { |
| 126 | log "Starting Zsh session..." |
| 127 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 128 | echo "----------------------------------------" |
| 129 | zsh -l |
| 130 | echo "----------------------------------------" |
| 131 | ok "Returned from Zsh session" |
| 132 | } |
| 133 | |
| 134 | # ============================= |
| 135 | # INTERACTIVE MENU |
| 136 | # ============================= |
| 137 | show_menu() { |
| 138 | echo "===========================================" |
| 139 | echo "macOS Zsh Setup - Choose what to do" |
| 140 | echo "===========================================" |
| 141 | echo " 0) Run ALL steps (1-7)" |
| 142 | echo " 1) Install Oh My Zsh" |
| 143 | echo " 2) Install plugins (autosuggestions, syntax highlighting)" |
| 144 | echo " 3) Install Spaceship theme" |
| 145 | echo " 4) Download custom configs (~/.alias, .func, .vimrc, etc.)" |
| 146 | echo " 5) Check ~/.zshrc load order" |
| 147 | echo " 6) Switch to Zsh (Temporary Sub-shell)" |
| 148 | echo " 7) Quit" |
| 149 | echo "===========================================" |
| 150 | } |
| 151 | |
| 152 | run_choices() { |
| 153 | local input |
| 154 | read -p "Select: " input |
| 155 | input="${input//,/ }" |
| 156 | |
| 157 | local -a to_run=() |
| 158 | local -a to_exclude=() |
| 159 | |
| 160 | for item in $input; do |
| 161 | if [[ "$item" == !* ]]; then |
| 162 | to_exclude+=("${item:1}") |
| 163 | elif [[ "$item" == "0" ]]; then |
| 164 | to_run+=(1 2 3 4 5 6) |
| 165 | else |
| 166 | to_run+=("$item") |
| 167 | fi |
| 168 | done |
| 169 | |
| 170 | if [[ ${#to_run[@]} -gt 0 ]]; then |
| 171 | for choice in "${to_run[@]}"; do |
| 172 | local skip=false |
| 173 | |
| 174 | if [[ ${#to_exclude[@]} -gt 0 ]]; then |
| 175 | for ex in "${to_exclude[@]}"; do |
| 176 | if [[ "$choice" == "$ex" ]]; then |
| 177 | skip=true |
| 178 | break |
| 179 | fi |
| 180 | done |
| 181 | fi |
| 182 | |
| 183 | $skip && continue |
| 184 | |
| 185 | case "$choice" in |
| 186 | 1) install_oh_my_zsh ;; |
| 187 | 2) install_plugins ;; |
| 188 | 3) install_theme ;; |
| 189 | 4) download_configs ;; |
| 190 | 5) update_zshrc ;; |
| 191 | 6) switch_shell ;; |
| 192 | 7) exit 0 ;; |
| 193 | *) warn "Skipping invalid option: $choice" ;; |
| 194 | esac |
| 195 | echo |
| 196 | done |
| 197 | fi |
| 198 | } |
| 199 | |
| 200 | # ============================= |
| 201 | # MAIN |
| 202 | # ============================= |
| 203 | main() { |
| 204 | check_requirements |
| 205 | while true; do |
| 206 | show_menu |
| 207 | run_choices |
| 208 | read -p "Do you want to run more options? (y/n): " again |
| 209 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 210 | done |
| 211 | ok "macOS configuration complete!" |
| 212 | } |
| 213 | |
| 214 | main "$@" |
zsh_ubuntu.sh
· 7.2 KiB · Bash
Неформатований
#!/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"
)
# =============================
# OS DETECTION
# =============================
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
else
echo "unknown"
fi
}
# =============================
# REQUIREMENTS
# =============================
check_requirements() {
if [[ $EUID -eq 0 ]]; then
err "Do not run as root"
exit 1
fi
if ! command -v sudo >/dev/null 2>&1; then
err "sudo required"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
update_system() {
$SKIP_PACKAGES && return
log "Updating system..."
sudo apt-get update -y
sudo apt-get upgrade -y
ok "System updated"
}
install_packages() {
$SKIP_PACKAGES && return
log "Installing core packages..."
sudo apt-get install -y \
zsh git vim curl wget unzip zip build-essential xz-utils
ok "Packages installed"
}
set_timezone() {
log "Setting timezone to Asia/Singapore..."
sudo timedatectl set-timezone Asia/Singapore
ok "Timezone set to Asia/Singapore"
}
install_homebrew() {
! $INSTALL_HOMEBREW && return
command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
log "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ok "Homebrew installed"
}
configure_shell() {
$SKIP_SHELL_CHANGE && return
log "Changing default shell to zsh..."
local zsh_path
zsh_path="$(command -v zsh)"
grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
chsh -s "$zsh_path"
ok "Shell changed (requires logout/login to take effect)"
}
install_oh_my_zsh() {
[[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
log "Installing Oh My Zsh..."
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok "Oh My Zsh installed"
}
install_plugins() {
log "Installing plugins..."
local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
mkdir -p "$dir"
[[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
[[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
ok "Plugins installed"
}
install_theme() {
log "Installing Spaceship theme..."
local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
local dir="$themes/spaceship-prompt"
mkdir -p "$themes"
[[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
ok "Theme installed"
}
download_configs() {
log "Downloading custom config files..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
# Strip the leading dot for the download URL
local remote_file="${f#.}"
local url="$GIST_RAW_BASE/$remote_file"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $remote_file -> $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $remote_file"
fi
done
ok "Configs downloaded (Backup at $backup)"
}
update_zshrc() {
local zshrc="$HOME/.zshrc"
log "Checking .zshrc..."
if [[ ! -f "$zshrc" ]]; then
warn ".zshrc not found. Run option 9 first."
return 1
fi
ok ".zshrc already comes from the managed gist."
ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
}
switch_shell() {
log "Starting Zsh session..."
echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
echo "----------------------------------------"
zsh -l
echo "----------------------------------------"
ok "Returned from Zsh session"
}
# =============================
# INTERACTIVE MENU
# =============================
show_menu() {
echo "==========================================="
echo "Zsh Installer - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-11)"
echo " 1) Update system packages"
echo " 2) Install core packages (zsh, git, vim, etc.)"
echo " 3) Set Timezone (Asia/Singapore)"
echo " 4) Install Homebrew"
echo " 5) Configure shell (chsh - sets default shell)"
echo " 6) Install Oh My Zsh"
echo " 7) Install plugins (autosuggestions, syntax highlighting)"
echo " 8) Install Spaceship theme"
echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
echo "10) Check ~/.zshrc load order"
echo "11) Switch to Zsh (Temporary Sub-shell)"
echo "12) Quit"
echo "==========================================="
}
run_choices() {
local input
read -p "Select: " input
input="${input//,/ }"
local -a to_run=()
local -a to_exclude=()
for item in $input; do
if [[ "$item" == !* ]]; then
to_exclude+=("${item:1}")
elif [[ "$item" == "0" ]]; then
to_run+=(1 2 3 4 5 6 7 8 9 10 11)
else
to_run+=("$item")
fi
done
for choice in "${to_run[@]}"; do
local skip=false
for ex in "${to_exclude[@]}"; do
if [[ "$choice" == "$ex" ]]; then
skip=true
break
fi
done
$skip && continue
case "$choice" in
1) update_system ;;
2) install_packages ;;
3) set_timezone ;;
4) install_homebrew ;;
5) configure_shell ;;
6) install_oh_my_zsh ;;
7) install_plugins ;;
8) install_theme ;;
9) download_configs ;;
10) update_zshrc ;;
11) switch_shell ;;
12) log "Exiting..."; exit 0 ;;
*) warn "Skipping invalid option: $choice" ;;
esac
echo
done
}
# =============================
# MAIN
# =============================
main() {
check_requirements
while true; do
show_menu
run_choices
read -p "Do you want to run more options? (y/n): " again
[[ "$again" =~ ^[Yy]$ ]] || break
done
ok "Zsh installation/configuration complete!"
}
main "$@"
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # ============================= |
| 5 | # COLORS & LOGGING |
| 6 | # ============================= |
| 7 | RED='\033[0;31m' |
| 8 | GREEN='\033[0;32m' |
| 9 | YELLOW='\033[1;33m' |
| 10 | BLUE='\033[0;34m' |
| 11 | NC='\033[0m' |
| 12 | |
| 13 | log() { echo -e "${BLUE}[INFO]${NC} $*"; } |
| 14 | ok() { echo -e "${GREEN}[OK]${NC} $*"; } |
| 15 | warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } |
| 16 | err() { echo -e "${RED}[ERROR]${NC} $*" >&2; } |
| 17 | |
| 18 | # ============================= |
| 19 | # FLAGS & CONFIG |
| 20 | # ============================= |
| 21 | SKIP_PACKAGES=false |
| 22 | SKIP_SHELL_CHANGE=false |
| 23 | INSTALL_HOMEBREW=false |
| 24 | |
| 25 | GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 26 | CONFIG_FILES=( |
| 27 | ".alias" |
| 28 | ".func" |
| 29 | ".pathrc" |
| 30 | ".sourcerc" |
| 31 | ".vimrc" |
| 32 | ".zshrc" |
| 33 | ) |
| 34 | |
| 35 | # ============================= |
| 36 | # OS DETECTION |
| 37 | # ============================= |
| 38 | detect_os() { |
| 39 | if [ -f /etc/os-release ]; then |
| 40 | . /etc/os-release |
| 41 | echo "$ID" |
| 42 | else |
| 43 | echo "unknown" |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | # ============================= |
| 48 | # REQUIREMENTS |
| 49 | # ============================= |
| 50 | check_requirements() { |
| 51 | if [[ $EUID -eq 0 ]]; then |
| 52 | err "Do not run as root" |
| 53 | exit 1 |
| 54 | fi |
| 55 | if ! command -v sudo >/dev/null 2>&1; then |
| 56 | err "sudo required" |
| 57 | exit 1 |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | # ============================= |
| 62 | # INSTALLATION FUNCTIONS |
| 63 | # ============================= |
| 64 | update_system() { |
| 65 | $SKIP_PACKAGES && return |
| 66 | log "Updating system..." |
| 67 | sudo apt-get update -y |
| 68 | sudo apt-get upgrade -y |
| 69 | ok "System updated" |
| 70 | } |
| 71 | |
| 72 | install_packages() { |
| 73 | $SKIP_PACKAGES && return |
| 74 | log "Installing core packages..." |
| 75 | sudo apt-get install -y \ |
| 76 | zsh git vim curl wget unzip zip build-essential xz-utils |
| 77 | ok "Packages installed" |
| 78 | } |
| 79 | |
| 80 | set_timezone() { |
| 81 | log "Setting timezone to Asia/Singapore..." |
| 82 | sudo timedatectl set-timezone Asia/Singapore |
| 83 | ok "Timezone set to Asia/Singapore" |
| 84 | } |
| 85 | |
| 86 | install_homebrew() { |
| 87 | ! $INSTALL_HOMEBREW && return |
| 88 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 89 | log "Installing Homebrew..." |
| 90 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 91 | ok "Homebrew installed" |
| 92 | } |
| 93 | |
| 94 | configure_shell() { |
| 95 | $SKIP_SHELL_CHANGE && return |
| 96 | log "Changing default shell to zsh..." |
| 97 | local zsh_path |
| 98 | zsh_path="$(command -v zsh)" |
| 99 | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 100 | chsh -s "$zsh_path" |
| 101 | ok "Shell changed (requires logout/login to take effect)" |
| 102 | } |
| 103 | |
| 104 | install_oh_my_zsh() { |
| 105 | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return |
| 106 | log "Installing Oh My Zsh..." |
| 107 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 108 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 109 | ok "Oh My Zsh installed" |
| 110 | } |
| 111 | |
| 112 | install_plugins() { |
| 113 | log "Installing plugins..." |
| 114 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 115 | mkdir -p "$dir" |
| 116 | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 117 | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 118 | ok "Plugins installed" |
| 119 | } |
| 120 | |
| 121 | install_theme() { |
| 122 | log "Installing Spaceship theme..." |
| 123 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 124 | local dir="$themes/spaceship-prompt" |
| 125 | mkdir -p "$themes" |
| 126 | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 127 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 128 | ok "Theme installed" |
| 129 | } |
| 130 | |
| 131 | download_configs() { |
| 132 | log "Downloading custom config files..." |
| 133 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 134 | mkdir -p "$backup" |
| 135 | |
| 136 | for f in "${CONFIG_FILES[@]}"; do |
| 137 | # Strip the leading dot for the download URL |
| 138 | local remote_file="${f#.}" |
| 139 | local url="$GIST_RAW_BASE/$remote_file" |
| 140 | local target="$HOME/$f" |
| 141 | local tmp="${target}.tmp.$$" |
| 142 | |
| 143 | if [[ -f "$target" ]]; then |
| 144 | cp "$target" "$backup/" |
| 145 | fi |
| 146 | |
| 147 | log "Fetching $remote_file -> $f ..." |
| 148 | if curl -fsSL "$url" -o "$tmp"; then |
| 149 | mv "$tmp" "$target" |
| 150 | else |
| 151 | rm -f "$tmp" |
| 152 | warn "Failed to download $remote_file" |
| 153 | fi |
| 154 | done |
| 155 | |
| 156 | ok "Configs downloaded (Backup at $backup)" |
| 157 | } |
| 158 | |
| 159 | update_zshrc() { |
| 160 | local zshrc="$HOME/.zshrc" |
| 161 | log "Checking .zshrc..." |
| 162 | |
| 163 | if [[ ! -f "$zshrc" ]]; then |
| 164 | warn ".zshrc not found. Run option 9 first." |
| 165 | return 1 |
| 166 | fi |
| 167 | |
| 168 | ok ".zshrc already comes from the managed gist." |
| 169 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 170 | } |
| 171 | |
| 172 | switch_shell() { |
| 173 | log "Starting Zsh session..." |
| 174 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 175 | echo "----------------------------------------" |
| 176 | zsh -l |
| 177 | echo "----------------------------------------" |
| 178 | ok "Returned from Zsh session" |
| 179 | } |
| 180 | |
| 181 | # ============================= |
| 182 | # INTERACTIVE MENU |
| 183 | # ============================= |
| 184 | show_menu() { |
| 185 | echo "===========================================" |
| 186 | echo "Zsh Installer - Choose what to do" |
| 187 | echo "===========================================" |
| 188 | echo " 0) Run ALL steps (1-11)" |
| 189 | echo " 1) Update system packages" |
| 190 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 191 | echo " 3) Set Timezone (Asia/Singapore)" |
| 192 | echo " 4) Install Homebrew" |
| 193 | echo " 5) Configure shell (chsh - sets default shell)" |
| 194 | echo " 6) Install Oh My Zsh" |
| 195 | echo " 7) Install plugins (autosuggestions, syntax highlighting)" |
| 196 | echo " 8) Install Spaceship theme" |
| 197 | echo " 9) Download custom configs (~/.alias, .vimrc, etc.)" |
| 198 | echo "10) Check ~/.zshrc load order" |
| 199 | echo "11) Switch to Zsh (Temporary Sub-shell)" |
| 200 | echo "12) Quit" |
| 201 | echo "===========================================" |
| 202 | } |
| 203 | |
| 204 | run_choices() { |
| 205 | local input |
| 206 | read -p "Select: " input |
| 207 | input="${input//,/ }" |
| 208 | |
| 209 | local -a to_run=() |
| 210 | local -a to_exclude=() |
| 211 | |
| 212 | for item in $input; do |
| 213 | if [[ "$item" == !* ]]; then |
| 214 | to_exclude+=("${item:1}") |
| 215 | elif [[ "$item" == "0" ]]; then |
| 216 | to_run+=(1 2 3 4 5 6 7 8 9 10 11) |
| 217 | else |
| 218 | to_run+=("$item") |
| 219 | fi |
| 220 | done |
| 221 | |
| 222 | for choice in "${to_run[@]}"; do |
| 223 | local skip=false |
| 224 | |
| 225 | for ex in "${to_exclude[@]}"; do |
| 226 | if [[ "$choice" == "$ex" ]]; then |
| 227 | skip=true |
| 228 | break |
| 229 | fi |
| 230 | done |
| 231 | |
| 232 | $skip && continue |
| 233 | |
| 234 | case "$choice" in |
| 235 | 1) update_system ;; |
| 236 | 2) install_packages ;; |
| 237 | 3) set_timezone ;; |
| 238 | 4) install_homebrew ;; |
| 239 | 5) configure_shell ;; |
| 240 | 6) install_oh_my_zsh ;; |
| 241 | 7) install_plugins ;; |
| 242 | 8) install_theme ;; |
| 243 | 9) download_configs ;; |
| 244 | 10) update_zshrc ;; |
| 245 | 11) switch_shell ;; |
| 246 | 12) log "Exiting..."; exit 0 ;; |
| 247 | *) warn "Skipping invalid option: $choice" ;; |
| 248 | esac |
| 249 | echo |
| 250 | done |
| 251 | } |
| 252 | |
| 253 | # ============================= |
| 254 | # MAIN |
| 255 | # ============================= |
| 256 | main() { |
| 257 | check_requirements |
| 258 | while true; do |
| 259 | show_menu |
| 260 | run_choices |
| 261 | read -p "Do you want to run more options? (y/n): " again |
| 262 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 263 | done |
| 264 | ok "Zsh installation/configuration complete!" |
| 265 | } |
| 266 | |
| 267 | main "$@" |
zsh_wsl.sh
· 7.6 KiB · Bash
Неформатований
#!/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"
)
# =============================
# PLATFORM DETECTION
# =============================
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
else
echo "unknown"
fi
}
is_wsl() {
grep -qi "microsoft" /proc/version 2>/dev/null
}
# =============================
# REQUIREMENTS
# =============================
check_requirements() {
if [[ $EUID -eq 0 ]]; then
err "Do not run as root"
exit 1
fi
if ! command -v sudo >/dev/null 2>&1; then
err "sudo required"
exit 1
fi
if ! is_wsl; then
err "This installer is intended for WSL"
exit 1
fi
}
# =============================
# INSTALLATION FUNCTIONS
# =============================
update_system() {
$SKIP_PACKAGES && return
log "Updating system..."
sudo apt-get update -y
sudo apt-get upgrade -y
ok "System updated"
}
install_packages() {
$SKIP_PACKAGES && return
log "Installing core packages..."
sudo apt-get install -y \
zsh git vim curl wget unzip zip build-essential xz-utils
ok "Packages installed"
}
set_timezone() {
log "Checking timezone configuration..."
if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then
sudo timedatectl set-timezone Asia/Singapore
ok "Timezone set to Asia/Singapore"
return
fi
warn "Skipping timezone change: timedatectl is not available in this WSL environment"
}
install_homebrew() {
! $INSTALL_HOMEBREW && return
command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return
log "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ok "Homebrew installed"
}
configure_shell() {
$SKIP_SHELL_CHANGE && return
log "Changing default shell to zsh..."
local zsh_path
zsh_path="$(command -v zsh)"
grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null
chsh -s "$zsh_path"
ok "Shell changed (open a new WSL session for it to take effect)"
}
install_oh_my_zsh() {
[[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return
log "Installing Oh My Zsh..."
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ok "Oh My Zsh installed"
}
install_plugins() {
log "Installing plugins..."
local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
mkdir -p "$dir"
[[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions"
[[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting"
ok "Plugins installed"
}
install_theme() {
log "Installing Spaceship theme..."
local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes"
local dir="$themes/spaceship-prompt"
mkdir -p "$themes"
[[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1
ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme"
ok "Theme installed"
}
download_configs() {
log "Downloading custom config files..."
local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup"
for f in "${CONFIG_FILES[@]}"; do
# Strip the leading dot for the download URL
local remote_file="${f#.}"
local url="$GIST_RAW_BASE/$remote_file"
local target="$HOME/$f"
local tmp="${target}.tmp.$$"
if [[ -f "$target" ]]; then
cp "$target" "$backup/"
fi
log "Fetching $remote_file -> $f ..."
if curl -fsSL "$url" -o "$tmp"; then
mv "$tmp" "$target"
else
rm -f "$tmp"
warn "Failed to download $remote_file"
fi
done
ok "Configs downloaded (Backup at $backup)"
}
update_zshrc() {
local zshrc="$HOME/.zshrc"
log "Checking .zshrc..."
if [[ ! -f "$zshrc" ]]; then
warn ".zshrc not found. Run option 9 first."
return 1
fi
ok ".zshrc already comes from the managed gist."
ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias"
}
switch_shell() {
log "Starting Zsh session..."
echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}"
echo "----------------------------------------"
zsh -l
echo "----------------------------------------"
ok "Returned from Zsh session"
}
# =============================
# INTERACTIVE MENU
# =============================
show_menu() {
echo "==========================================="
echo "WSL Zsh Installer - Choose what to do"
echo "==========================================="
echo " 0) Run ALL steps (1-11)"
echo " 1) Update system packages"
echo " 2) Install core packages (zsh, git, vim, etc.)"
echo " 3) Set Timezone (best effort)"
echo " 4) Install Homebrew"
echo " 5) Configure shell (chsh - sets default shell)"
echo " 6) Install Oh My Zsh"
echo " 7) Install plugins (autosuggestions, syntax highlighting)"
echo " 8) Install Spaceship theme"
echo " 9) Download custom configs (~/.alias, .vimrc, etc.)"
echo "10) Check ~/.zshrc load order"
echo "11) Switch to Zsh (Temporary Sub-shell)"
echo "12) Quit"
echo "==========================================="
}
run_choices() {
local input
read -p "Select: " input
input="${input//,/ }"
local -a to_run=()
local -a to_exclude=()
for item in $input; do
if [[ "$item" == !* ]]; then
to_exclude+=("${item:1}")
elif [[ "$item" == "0" ]]; then
to_run+=(1 2 3 4 5 6 7 8 9 10 11)
else
to_run+=("$item")
fi
done
for choice in "${to_run[@]}"; do
local skip=false
for ex in "${to_exclude[@]}"; do
if [[ "$choice" == "$ex" ]]; then
skip=true
break
fi
done
$skip && continue
case "$choice" in
1) update_system ;;
2) install_packages ;;
3) set_timezone ;;
4) install_homebrew ;;
5) configure_shell ;;
6) install_oh_my_zsh ;;
7) install_plugins ;;
8) install_theme ;;
9) download_configs ;;
10) update_zshrc ;;
11) switch_shell ;;
12) log "Exiting..."; exit 0 ;;
*) warn "Skipping invalid option: $choice" ;;
esac
echo
done
}
# =============================
# MAIN
# =============================
main() {
check_requirements
while true; do
show_menu
run_choices
read -p "Do you want to run more options? (y/n): " again
[[ "$again" =~ ^[Yy]$ ]] || break
done
ok "WSL Zsh installation/configuration complete!"
}
main "$@"
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # ============================= |
| 5 | # COLORS & LOGGING |
| 6 | # ============================= |
| 7 | RED='\033[0;31m' |
| 8 | GREEN='\033[0;32m' |
| 9 | YELLOW='\033[1;33m' |
| 10 | BLUE='\033[0;34m' |
| 11 | NC='\033[0m' |
| 12 | |
| 13 | log() { echo -e "${BLUE}[INFO]${NC} $*"; } |
| 14 | ok() { echo -e "${GREEN}[OK]${NC} $*"; } |
| 15 | warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } |
| 16 | err() { echo -e "${RED}[ERROR]${NC} $*" >&2; } |
| 17 | |
| 18 | # ============================= |
| 19 | # FLAGS & CONFIG |
| 20 | # ============================= |
| 21 | SKIP_PACKAGES=false |
| 22 | SKIP_SHELL_CHANGE=false |
| 23 | INSTALL_HOMEBREW=false |
| 24 | |
| 25 | GIST_RAW_BASE="https://opengist.rmrf.online/weehong/f0d940c3c1214bf5b7996195199fdc09/raw/HEAD" |
| 26 | CONFIG_FILES=( |
| 27 | ".alias" |
| 28 | ".func" |
| 29 | ".pathrc" |
| 30 | ".sourcerc" |
| 31 | ".vimrc" |
| 32 | ".zshrc" |
| 33 | ) |
| 34 | |
| 35 | # ============================= |
| 36 | # PLATFORM DETECTION |
| 37 | # ============================= |
| 38 | detect_os() { |
| 39 | if [ -f /etc/os-release ]; then |
| 40 | . /etc/os-release |
| 41 | echo "$ID" |
| 42 | else |
| 43 | echo "unknown" |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | is_wsl() { |
| 48 | grep -qi "microsoft" /proc/version 2>/dev/null |
| 49 | } |
| 50 | |
| 51 | # ============================= |
| 52 | # REQUIREMENTS |
| 53 | # ============================= |
| 54 | check_requirements() { |
| 55 | if [[ $EUID -eq 0 ]]; then |
| 56 | err "Do not run as root" |
| 57 | exit 1 |
| 58 | fi |
| 59 | if ! command -v sudo >/dev/null 2>&1; then |
| 60 | err "sudo required" |
| 61 | exit 1 |
| 62 | fi |
| 63 | if ! is_wsl; then |
| 64 | err "This installer is intended for WSL" |
| 65 | exit 1 |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | # ============================= |
| 70 | # INSTALLATION FUNCTIONS |
| 71 | # ============================= |
| 72 | update_system() { |
| 73 | $SKIP_PACKAGES && return |
| 74 | log "Updating system..." |
| 75 | sudo apt-get update -y |
| 76 | sudo apt-get upgrade -y |
| 77 | ok "System updated" |
| 78 | } |
| 79 | |
| 80 | install_packages() { |
| 81 | $SKIP_PACKAGES && return |
| 82 | log "Installing core packages..." |
| 83 | sudo apt-get install -y \ |
| 84 | zsh git vim curl wget unzip zip build-essential xz-utils |
| 85 | ok "Packages installed" |
| 86 | } |
| 87 | |
| 88 | set_timezone() { |
| 89 | log "Checking timezone configuration..." |
| 90 | if command -v timedatectl >/dev/null 2>&1 && timedatectl status >/dev/null 2>&1; then |
| 91 | sudo timedatectl set-timezone Asia/Singapore |
| 92 | ok "Timezone set to Asia/Singapore" |
| 93 | return |
| 94 | fi |
| 95 | |
| 96 | warn "Skipping timezone change: timedatectl is not available in this WSL environment" |
| 97 | } |
| 98 | |
| 99 | install_homebrew() { |
| 100 | ! $INSTALL_HOMEBREW && return |
| 101 | command -v brew >/dev/null 2>&1 && ok "Homebrew already installed" && return |
| 102 | log "Installing Homebrew..." |
| 103 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 104 | ok "Homebrew installed" |
| 105 | } |
| 106 | |
| 107 | configure_shell() { |
| 108 | $SKIP_SHELL_CHANGE && return |
| 109 | log "Changing default shell to zsh..." |
| 110 | local zsh_path |
| 111 | zsh_path="$(command -v zsh)" |
| 112 | grep -qx "$zsh_path" /etc/shells || echo "$zsh_path" | sudo tee -a /etc/shells >/dev/null |
| 113 | chsh -s "$zsh_path" |
| 114 | ok "Shell changed (open a new WSL session for it to take effect)" |
| 115 | } |
| 116 | |
| 117 | install_oh_my_zsh() { |
| 118 | [[ -d "$HOME/.oh-my-zsh" ]] && ok "Oh My Zsh already installed" && return |
| 119 | log "Installing Oh My Zsh..." |
| 120 | RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ |
| 121 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
| 122 | ok "Oh My Zsh installed" |
| 123 | } |
| 124 | |
| 125 | install_plugins() { |
| 126 | log "Installing plugins..." |
| 127 | local dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins" |
| 128 | mkdir -p "$dir" |
| 129 | [[ -d "$dir/zsh-autosuggestions" ]] || git clone https://github.com/zsh-users/zsh-autosuggestions "$dir/zsh-autosuggestions" |
| 130 | [[ -d "$dir/zsh-syntax-highlighting" ]] || git clone https://github.com/zsh-users/zsh-syntax-highlighting "$dir/zsh-syntax-highlighting" |
| 131 | ok "Plugins installed" |
| 132 | } |
| 133 | |
| 134 | install_theme() { |
| 135 | log "Installing Spaceship theme..." |
| 136 | local themes="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes" |
| 137 | local dir="$themes/spaceship-prompt" |
| 138 | mkdir -p "$themes" |
| 139 | [[ -d "$dir" ]] || git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$dir" --depth=1 |
| 140 | ln -sf "$dir/spaceship.zsh-theme" "$themes/spaceship.zsh-theme" |
| 141 | ok "Theme installed" |
| 142 | } |
| 143 | |
| 144 | download_configs() { |
| 145 | log "Downloading custom config files..." |
| 146 | local backup="$HOME/.config_backup_$(date +%Y%m%d_%H%M%S)" |
| 147 | mkdir -p "$backup" |
| 148 | |
| 149 | for f in "${CONFIG_FILES[@]}"; do |
| 150 | # Strip the leading dot for the download URL |
| 151 | local remote_file="${f#.}" |
| 152 | local url="$GIST_RAW_BASE/$remote_file" |
| 153 | local target="$HOME/$f" |
| 154 | local tmp="${target}.tmp.$$" |
| 155 | |
| 156 | if [[ -f "$target" ]]; then |
| 157 | cp "$target" "$backup/" |
| 158 | fi |
| 159 | |
| 160 | log "Fetching $remote_file -> $f ..." |
| 161 | if curl -fsSL "$url" -o "$tmp"; then |
| 162 | mv "$tmp" "$target" |
| 163 | else |
| 164 | rm -f "$tmp" |
| 165 | warn "Failed to download $remote_file" |
| 166 | fi |
| 167 | done |
| 168 | |
| 169 | ok "Configs downloaded (Backup at $backup)" |
| 170 | } |
| 171 | |
| 172 | update_zshrc() { |
| 173 | local zshrc="$HOME/.zshrc" |
| 174 | log "Checking .zshrc..." |
| 175 | |
| 176 | if [[ ! -f "$zshrc" ]]; then |
| 177 | warn ".zshrc not found. Run option 9 first." |
| 178 | return 1 |
| 179 | fi |
| 180 | |
| 181 | ok ".zshrc already comes from the managed gist." |
| 182 | ok "Load order is built in: .sourcerc -> .func -> .pathrc -> .alias" |
| 183 | } |
| 184 | |
| 185 | switch_shell() { |
| 186 | log "Starting Zsh session..." |
| 187 | echo -e "${YELLOW}Type 'exit' to return to this installer menu.${NC}" |
| 188 | echo "----------------------------------------" |
| 189 | zsh -l |
| 190 | echo "----------------------------------------" |
| 191 | ok "Returned from Zsh session" |
| 192 | } |
| 193 | |
| 194 | # ============================= |
| 195 | # INTERACTIVE MENU |
| 196 | # ============================= |
| 197 | show_menu() { |
| 198 | echo "===========================================" |
| 199 | echo "WSL Zsh Installer - Choose what to do" |
| 200 | echo "===========================================" |
| 201 | echo " 0) Run ALL steps (1-11)" |
| 202 | echo " 1) Update system packages" |
| 203 | echo " 2) Install core packages (zsh, git, vim, etc.)" |
| 204 | echo " 3) Set Timezone (best effort)" |
| 205 | echo " 4) Install Homebrew" |
| 206 | echo " 5) Configure shell (chsh - sets default shell)" |
| 207 | echo " 6) Install Oh My Zsh" |
| 208 | echo " 7) Install plugins (autosuggestions, syntax highlighting)" |
| 209 | echo " 8) Install Spaceship theme" |
| 210 | echo " 9) Download custom configs (~/.alias, .vimrc, etc.)" |
| 211 | echo "10) Check ~/.zshrc load order" |
| 212 | echo "11) Switch to Zsh (Temporary Sub-shell)" |
| 213 | echo "12) Quit" |
| 214 | echo "===========================================" |
| 215 | } |
| 216 | |
| 217 | run_choices() { |
| 218 | local input |
| 219 | read -p "Select: " input |
| 220 | input="${input//,/ }" |
| 221 | |
| 222 | local -a to_run=() |
| 223 | local -a to_exclude=() |
| 224 | |
| 225 | for item in $input; do |
| 226 | if [[ "$item" == !* ]]; then |
| 227 | to_exclude+=("${item:1}") |
| 228 | elif [[ "$item" == "0" ]]; then |
| 229 | to_run+=(1 2 3 4 5 6 7 8 9 10 11) |
| 230 | else |
| 231 | to_run+=("$item") |
| 232 | fi |
| 233 | done |
| 234 | |
| 235 | for choice in "${to_run[@]}"; do |
| 236 | local skip=false |
| 237 | |
| 238 | for ex in "${to_exclude[@]}"; do |
| 239 | if [[ "$choice" == "$ex" ]]; then |
| 240 | skip=true |
| 241 | break |
| 242 | fi |
| 243 | done |
| 244 | |
| 245 | $skip && continue |
| 246 | |
| 247 | case "$choice" in |
| 248 | 1) update_system ;; |
| 249 | 2) install_packages ;; |
| 250 | 3) set_timezone ;; |
| 251 | 4) install_homebrew ;; |
| 252 | 5) configure_shell ;; |
| 253 | 6) install_oh_my_zsh ;; |
| 254 | 7) install_plugins ;; |
| 255 | 8) install_theme ;; |
| 256 | 9) download_configs ;; |
| 257 | 10) update_zshrc ;; |
| 258 | 11) switch_shell ;; |
| 259 | 12) log "Exiting..."; exit 0 ;; |
| 260 | *) warn "Skipping invalid option: $choice" ;; |
| 261 | esac |
| 262 | echo |
| 263 | done |
| 264 | } |
| 265 | |
| 266 | # ============================= |
| 267 | # MAIN |
| 268 | # ============================= |
| 269 | main() { |
| 270 | check_requirements |
| 271 | while true; do |
| 272 | show_menu |
| 273 | run_choices |
| 274 | read -p "Do you want to run more options? (y/n): " again |
| 275 | [[ "$again" =~ ^[Yy]$ ]] || break |
| 276 | done |
| 277 | ok "WSL Zsh installation/configuration complete!" |
| 278 | } |
| 279 | |
| 280 | main "$@" |
zshrc
· 1.6 KiB · Bash
Неформатований
# =============================================================================
# 1. ZSH THEME & PLUGINS (Must be defined before Oh My Zsh loads)
# =============================================================================
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="spaceship"
SPACESHIP_PROMPT_ORDER=( user dir git exec_time line_sep jobs exit_code char )
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_SEPARATE_LINE=true
SPACESHIP_PROMPT_ADD_NEWLINE=true
SPACESHIP_CHAR_SYMBOL="❯"
SPACESHIP_CHAR_SUFFIX=" "
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
# =============================================================================
# 2. THIRD-PARTY INITIALIZATION (SDKMAN, NVM, Oh My Zsh)
# =============================================================================
[[ -s "$HOME/.sourcerc" ]] && source "$HOME/.sourcerc"
# =============================================================================
# 3. CUSTOM OVERRIDES (Functions must load before Path Management)
# =============================================================================
[[ -s "$HOME/.func" ]] && source "$HOME/.func"
# =============================================================================
# 4. PATH MANAGEMENT (Relies on append_path from .func)
# =============================================================================
[[ -s "$HOME/.pathrc" ]] && source "$HOME/.pathrc"
# =============================================================================
# 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh)
# =============================================================================
[[ -s "$HOME/.alias" ]] && source "$HOME/.alias"
| 1 | # ============================================================================= |
| 2 | # 1. ZSH THEME & PLUGINS (Must be defined before Oh My Zsh loads) |
| 3 | # ============================================================================= |
| 4 | export ZSH="$HOME/.oh-my-zsh" |
| 5 | ZSH_THEME="spaceship" |
| 6 | |
| 7 | SPACESHIP_PROMPT_ORDER=( user dir git exec_time line_sep jobs exit_code char ) |
| 8 | SPACESHIP_USER_SHOW=always |
| 9 | SPACESHIP_PROMPT_SEPARATE_LINE=true |
| 10 | SPACESHIP_PROMPT_ADD_NEWLINE=true |
| 11 | SPACESHIP_CHAR_SYMBOL="❯" |
| 12 | SPACESHIP_CHAR_SUFFIX=" " |
| 13 | |
| 14 | plugins=(git zsh-syntax-highlighting zsh-autosuggestions) |
| 15 | |
| 16 | # ============================================================================= |
| 17 | # 2. THIRD-PARTY INITIALIZATION (SDKMAN, NVM, Oh My Zsh) |
| 18 | # ============================================================================= |
| 19 | [[ -s "$HOME/.sourcerc" ]] && source "$HOME/.sourcerc" |
| 20 | |
| 21 | # ============================================================================= |
| 22 | # 3. CUSTOM OVERRIDES (Functions must load before Path Management) |
| 23 | # ============================================================================= |
| 24 | [[ -s "$HOME/.func" ]] && source "$HOME/.func" |
| 25 | |
| 26 | # ============================================================================= |
| 27 | # 4. PATH MANAGEMENT (Relies on append_path from .func) |
| 28 | # ============================================================================= |
| 29 | [[ -s "$HOME/.pathrc" ]] && source "$HOME/.pathrc" |
| 30 | |
| 31 | # ============================================================================= |
| 32 | # 5. ALIASES (Loaded dead last so YOUR code always wins over Oh My Zsh) |
| 33 | # ============================================================================= |
| 34 | [[ -s "$HOME/.alias" ]] && source "$HOME/.alias" |
| 35 |