diff --git a/install.sh b/install.sh index f2654d9..75f2b6f 100755 --- a/install.sh +++ b/install.sh @@ -41,7 +41,7 @@ log_info() { __log_info "$@"; } log_success() { __log_success "$@"; } log_warning() { __log_warning "$@"; } log_error() { __log_error "$@"; } -log_skip() { __log_skip "$@"; } +log_skip() { __log_info "$@"; } cmd_exists() { __cmd_exists "$@"; } pkg_installed() { __pkg_installed "$@"; } snap_installed() { __snap_installed "$@"; } diff --git a/zsh/core b/zsh/core index 0c78816..84962a9 100644 --- a/zsh/core +++ b/zsh/core @@ -37,10 +37,6 @@ function __log_error() { __log_with_time "\033[0;31m[✗]\033[0m" "$@" } -function __log_skip() { - __log_with_time "\033[0;90m[SKIP]\033[0m" "$@" -} - ################################################################################ # System checks ################################################################################ @@ -64,7 +60,7 @@ function __safe_link() { local dst="$2" if [ -L "$dst" ] && [ "$(readlink "$dst")" = "$src" ]; then - __log_skip "Link OK: $dst" + __log_info "Link OK: $dst" return 0 fi diff --git a/zsh/disk b/zsh/disk index 8052a02..3c6528b 100644 --- a/zsh/disk +++ b/zsh/disk @@ -1,147 +1,8 @@ #!/usr/bin/env bash # -# Disk operations: wipe, sort, and shared helpers. -# All disk-related helpers live here next to the functions that use them. - -################################################################################ -# Shared disk helpers (used by disk_wipe and fat_sort) -################################################################################ -function __disk_resolve_device() { - local input="$1" - - if [ -b "$input" ] || [ -c "$input" ]; then - echo "$input" - return 0 - fi - - if [ -d "$input" ]; then - local resolved - case "$(uname)" in - Darwin) - resolved=$(diskutil info "$input" 2>/dev/null | awk -F': +' '/Device Node/ {print $2}') - ;; - Linux) - resolved=$(command findmnt -n -o SOURCE "$input" 2>/dev/null) - ;; - esac - - if [ -n "$resolved" ]; then - echo "$resolved" - return 0 - fi - - __log_error "No device found for mount point: $input" - return 1 - fi - - __log_error "Not a device or mount point: $input" - return 1 -} - -function __disk_whole_device() { - local device="$1" - - case "$(uname)" in - Darwin) - local whole - whole=$(diskutil info "$device" 2>/dev/null | awk -F': +' '/Part of Whole/ {print $2}') - if [ -n "$whole" ]; then - echo "/dev/$whole" - else - echo "$device" - fi - ;; - Linux) - local stripped - stripped=$(lsblk -no PKNAME "$device" 2>/dev/null | head -1) - if [ -n "$stripped" ]; then - echo "/dev/$stripped" - else - echo "$device" - fi - ;; - esac -} - -function __disk_mount_point() { - local partition="$1" - - case "$(uname)" in - Darwin) - diskutil info "$partition" 2>/dev/null | awk -F': +' '/Mount Point/ {print $2}' - ;; - Linux) - command findmnt -n -o TARGET "$partition" 2>/dev/null - ;; - esac -} - -function __disk_get_size() { - local disk="$1" - local size - - case "$(uname)" in - Darwin) - size=$(diskutil info "$disk" 2>/dev/null | sed -nE 's/.*Disk Size:.*\(([0-9]+) Bytes\).*/\1/p') - ;; - Linux) - size=$(command blockdev --getsize64 "$disk" 2>/dev/null) - ;; - esac - - if [ -z "$size" ] || [ "$size" -eq 0 ]; then - __log_error "Unable to determine disk size for $disk" - return 1 - fi - - echo "$size" -} - -function __disk_unmount() { - local disk="$1" - - __log_info "Unmounting $disk..." - case "$(uname)" in - Darwin) - if sudo diskutil unmountDisk force "$disk"; then - __log_success "Disk unmounted" - else - __log_warning "Failed to unmount disk (may not be mounted)" - fi - ;; - Linux) - if sudo umount "$disk" 2>/dev/null; then - __log_success "Disk unmounted" - else - __log_warning "Failed to unmount disk (may not be mounted)" - fi - ;; - esac -} - -function __disk_eject() { - local disk="$1" - - __log_info "Ejecting device..." - case "$(uname)" in - Darwin) - if sudo diskutil eject "$disk" >/dev/null 2>&1; then - __log_success "Device ejected successfully" - else - __log_error "Failed to eject device" - return 1 - fi - ;; - Linux) - sync - if sudo eject "$disk" 2>/dev/null; then - __log_success "Device ejected successfully" - else - __log_warning "Failed to eject device (may not support eject)" - fi - ;; - esac -} +# Disk operations: wipe and sort. Each function is self-contained; the +# only shared piece is the resolve-device-or-mount-point preamble, which +# is short enough to keep inlined in both callers. ################################################################################ # Wipe a storage device with write+verify passes @@ -412,17 +273,68 @@ function disk_wipe() { fi local disk - disk=$(__disk_resolve_device "$input") || return 1 - disk=$(__disk_whole_device "$disk") + if [ -b "$input" ] || [ -c "$input" ]; then + disk="$input" + elif [ -d "$input" ]; then + case "$(uname)" in + Darwin) disk=$(diskutil info "$input" 2>/dev/null | awk -F': +' '/Device Node/ {print $2}') ;; + Linux) disk=$(command findmnt -n -o SOURCE "$input" 2>/dev/null) ;; + esac + if [ -z "$disk" ]; then + __log_error "No device found for mount point: $input" + return 1 + fi + else + __log_error "Not a device or mount point: $input" + return 1 + fi + + # Walk up to the whole device (e.g., /dev/disk4s1 -> /dev/disk4) + case "$(uname)" in + Darwin) + local whole + whole=$(diskutil info "$disk" 2>/dev/null | awk -F': +' '/Part of Whole/ {print $2}') + [ -n "$whole" ] && disk="/dev/$whole" + ;; + Linux) + local stripped + stripped=$(lsblk -no PKNAME "$disk" 2>/dev/null | head -1) + [ -n "$stripped" ] && disk="/dev/$stripped" + ;; + esac __log_info "Device: $disk" __dw_validate_params "$disk" "$passes" || return 1 local size - size=$(__disk_get_size "$disk") || return 1 + case "$(uname)" in + Darwin) size=$(diskutil info "$disk" 2>/dev/null | sed -nE 's/.*Disk Size:.*\(([0-9]+) Bytes\).*/\1/p') ;; + Linux) size=$(command blockdev --getsize64 "$disk" 2>/dev/null) ;; + esac + if [ -z "$size" ] || [ "$size" -eq 0 ]; then + __log_error "Unable to determine disk size for $disk" + return 1 + fi __dw_confirm "$disk" || return 1 - __disk_unmount "$disk" + + __log_info "Unmounting $disk..." + case "$(uname)" in + Darwin) + if sudo diskutil unmountDisk force "$disk"; then + __log_success "Disk unmounted" + else + __log_warning "Failed to unmount disk (may not be mounted)" + fi + ;; + Linux) + if sudo umount "$disk" 2>/dev/null; then + __log_success "Disk unmounted" + else + __log_warning "Failed to unmount disk (may not be mounted)" + fi + ;; + esac __log_info "Cleaning $disk..." for ((index=1; index <= passes; index++)); do @@ -431,7 +343,25 @@ function disk_wipe() { [ "${CREATE}" = "y" ] && __dw_create_partition "$disk" "$size" - __disk_eject "$disk" + __log_info "Ejecting device..." + case "$(uname)" in + Darwin) + if sudo diskutil eject "$disk" >/dev/null 2>&1; then + __log_success "Device ejected successfully" + else + __log_error "Failed to eject device" + return 1 + fi + ;; + Linux) + sync + if sudo eject "$disk" 2>/dev/null; then + __log_success "Device ejected successfully" + else + __log_warning "Failed to eject device (may not support eject)" + fi + ;; + esac } ################################################################################ @@ -443,6 +373,19 @@ function fat_sort() { return 1 fi + __fat_sort_mount_point() { + local partition="$1" + + case "$(uname)" in + Darwin) + diskutil info "$partition" 2>/dev/null | awk -F': +' '/Mount Point/ {print $2}' + ;; + Linux) + command findmnt -n -o TARGET "$partition" 2>/dev/null + ;; + esac + } + __fat_sort_find_partition() { local device="$1" @@ -480,7 +423,7 @@ function fat_sort() { local partition="$1" local mount_point - mount_point=$(__disk_mount_point "$partition") + mount_point=$(__fat_sort_mount_point "$partition") if [ -n "$mount_point" ]; then echo "$mount_point" return 0 @@ -491,7 +434,7 @@ function fat_sort() { case "$(uname)" in Darwin) if diskutil mount "$partition" >/dev/null 2>&1; then - mount_point=$(__disk_mount_point "$partition") + mount_point=$(__fat_sort_mount_point "$partition") if [ -n "$mount_point" ]; then echo "$mount_point" return 0 @@ -519,11 +462,11 @@ function fat_sort() { Darwin) diskutil unmount force "$partition" >/dev/null 2>&1 local attempts=0 - while [ -n "$(__disk_mount_point "$partition")" ] && [ "$attempts" -lt 10 ]; do + while [ -n "$(__fat_sort_mount_point "$partition")" ] && [ "$attempts" -lt 10 ]; do sleep 1 attempts=$((attempts + 1)) done - if [ -n "$(__disk_mount_point "$partition")" ]; then + if [ -n "$(__fat_sort_mount_point "$partition")" ]; then __log_error "Failed to unmount $partition after ${attempts}s" return 1 fi @@ -648,7 +591,21 @@ function fat_sort() { fi local device - device=$(__disk_resolve_device "$input") || return 1 + if [ -b "$input" ] || [ -c "$input" ]; then + device="$input" + elif [ -d "$input" ]; then + case "$(uname)" in + Darwin) device=$(diskutil info "$input" 2>/dev/null | awk -F': +' '/Device Node/ {print $2}') ;; + Linux) device=$(command findmnt -n -o SOURCE "$input" 2>/dev/null) ;; + esac + if [ -z "$device" ]; then + __log_error "No device found for mount point: $input" + return 1 + fi + else + __log_error "Not a device or mount point: $input" + return 1 + fi local partition partition=$(__fat_sort_find_partition "$device") || return 1 diff --git a/zsh/f5 b/zsh/f5 index c743315..5ae88ba 100644 --- a/zsh/f5 +++ b/zsh/f5 @@ -3,15 +3,6 @@ # f5 - Update and reload everything. # All update helpers live here next to the function that calls them. -################################################################################ -# Git repo updater (shared by multiple update functions below) -################################################################################ -function __f5_update_git_repo() { - local repo_dir="$1" - git -C "$repo_dir" pull --quiet >/dev/null 2>&1 && \ - git -C "$repo_dir" fetch --prune --quiet >/dev/null 2>&1 -} - ################################################################################ # Individual update steps ################################################################################ @@ -19,11 +10,12 @@ function __f5_update_dotfiles() { __log_info "Updating dotfiles..." if [ ! -d "$HOME/.dotfiles/.git" ]; then - __log_skip "Dotfiles not a git repository" + __log_info "Dotfiles not a git repository" return fi - if __f5_update_git_repo "$HOME/.dotfiles"; then + if git -C "$HOME/.dotfiles" pull --quiet >/dev/null 2>&1 && \ + git -C "$HOME/.dotfiles" fetch --prune --quiet >/dev/null 2>&1; then if git -C "$HOME/.dotfiles" submodule update --init --recursive --quiet; then __log_success "Dotfiles and submodules updated" else @@ -42,7 +34,8 @@ function __f5_update_aws() { __log_info "Updating AWS configuration..." - if __f5_update_git_repo "$HOME/.aws"; then + if git -C "$HOME/.aws" pull --quiet >/dev/null 2>&1 && \ + git -C "$HOME/.aws" fetch --prune --quiet >/dev/null 2>&1; then __log_success "AWS configuration updated" else __log_warning "Failed to update AWS configuration" @@ -57,7 +50,8 @@ function __f5_update_claude() { __log_info "Updating Claude engineering rules..." - if __f5_update_git_repo "$HOME/.claude"; then + if git -C "$HOME/.claude" pull --quiet >/dev/null 2>&1 && \ + git -C "$HOME/.claude" fetch --prune --quiet >/dev/null 2>&1; then __log_success "Claude engineering rules updated" else __log_warning "Failed to update Claude engineering rules" @@ -66,7 +60,7 @@ function __f5_update_claude() { function __f5_update_vim() { if ! __cmd_exists vim; then - __log_skip "Vim not installed" + __log_info "Vim not installed" return fi @@ -92,7 +86,8 @@ function __f5_update_plugins() { [ ! -d "$dir/.git" ] && continue [[ "$dir" == "$HOME/.tmux/plugins/tpm/" ]] && continue - if __f5_update_git_repo "$dir"; then + if git -C "$dir" pull --quiet >/dev/null 2>&1 && \ + git -C "$dir" fetch --prune --quiet >/dev/null 2>&1; then ((plugin_count++)) else ((plugin_errors++)) @@ -108,7 +103,7 @@ function __f5_update_plugins() { function __f5_update_mise() { if ! __cmd_exists mise; then - __log_skip "mise not installed" + __log_info "mise not installed" return fi @@ -130,7 +125,7 @@ function __f5_update_mise() { function __f5_update_proton_ge() { local proton_dir="$HOME/.steam/steam/compatibilitytools.d" if [ ! -d "$proton_dir" ]; then - __log_skip "GE-Proton not set up" + __log_info "GE-Proton not set up" return fi @@ -189,7 +184,7 @@ function __f5_update_standalone_tools() { function __f5_update_nerd_fonts() { local fonts_dir="$HOME/.local/share/fonts/NerdFonts" if [ ! -d "$fonts_dir" ]; then - __log_skip "Nerd Fonts not set up" + __log_info "Nerd Fonts not set up" return fi @@ -266,12 +261,12 @@ function __f5_update_python() { # pipx CLI tools ############################################################################ if ! __cmd_exists pipx; then - __log_skip "pipx not installed, skipping CLI tools" + __log_info "pipx not installed, skipping CLI tools" return fi if [ ! -f "$pipxfile" ]; then - __log_skip "Pipxfile not found" + __log_info "Pipxfile not found" return fi @@ -323,7 +318,7 @@ function __f5_reload_configs() { __log_warning "Tmux reload failed" fi else - __log_skip "Not in tmux session" + __log_info "Not in tmux session" fi # Clear eval cache so tools re-initialize with fresh output diff --git a/zsh/infrastructure b/zsh/infrastructure index c8cc3f3..73b288d 100644 --- a/zsh/infrastructure +++ b/zsh/infrastructure @@ -103,7 +103,7 @@ function __calculate_vm_storage() { ################################################################################ function __ensure_docker_compose_plugin() { if ! __cmd_exists docker-compose; then - __log_skip "docker-compose not found, skipping plugin setup" + __log_info "docker-compose not found, skipping plugin setup" return fi diff --git a/zsh/nds-trim b/zsh/nds-trim index 5befae9..877ee4c 100644 --- a/zsh/nds-trim +++ b/zsh/nds-trim @@ -304,7 +304,7 @@ function nds-trim() { fi if (( trim_size == actual_size )); then - __log_skip "[$current/$total] Already trimmed ($(__nds_trim_format_size "$actual_size")): $fname" + __log_info "[$current/$total] Already trimmed ($(__nds_trim_format_size "$actual_size")): $fname" ((skipped++)) continue fi diff --git a/zsh/settings b/zsh/settings index 56fa6c2..ff7c8c1 100644 --- a/zsh/settings +++ b/zsh/settings @@ -264,17 +264,11 @@ function __update_token() { return 0 } -function __update_npm_token() { - __update_token "${1:-false}" "NPM_TOKEN" "$HOME/.dotfiles/nodejs/tokens/npm.gpg" "npm_token" -} - -function __update_github_token() { - __update_token "${1:-false}" "GITHUB_PAT" "$HOME/.dotfiles/git/tokens/github.gpg" "github_token" -} - # Load tokens (only if not already set) -[ -z "$NPM_TOKEN" ] && __update_npm_token 2>/dev/null || true -[ -z "$GITHUB_PAT" ] && __update_github_token 2>/dev/null || true +[ -z "$NPM_TOKEN" ] && __update_token false NPM_TOKEN \ + "$HOME/.dotfiles/nodejs/tokens/npm.gpg" npm_token 2>/dev/null || true +[ -z "$GITHUB_PAT" ] && __update_token false GITHUB_PAT \ + "$HOME/.dotfiles/git/tokens/github.gpg" github_token 2>/dev/null || true ################################################################################ # Workspace folder