mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 22:30:08 +00:00
chore: auto format code
This commit is contained in:
@@ -84,7 +84,7 @@ scan_installed_apps() {
|
|||||||
|
|
||||||
# Performance optimization: cache results for 5 minutes
|
# Performance optimization: cache results for 5 minutes
|
||||||
local cache_file="$HOME/.cache/mole/installed_apps_cache"
|
local cache_file="$HOME/.cache/mole/installed_apps_cache"
|
||||||
local cache_age_seconds=300 # 5 minutes
|
local cache_age_seconds=300 # 5 minutes
|
||||||
|
|
||||||
if [[ -f "$cache_file" ]]; then
|
if [[ -f "$cache_file" ]]; then
|
||||||
local cache_mtime=$(get_file_mtime "$cache_file")
|
local cache_mtime=$(get_file_mtime "$cache_file")
|
||||||
@@ -95,7 +95,7 @@ scan_installed_apps() {
|
|||||||
debug_log "Using cached app list (age: ${age}s)"
|
debug_log "Using cached app list (age: ${age}s)"
|
||||||
# Verify cache file is readable and not empty
|
# Verify cache file is readable and not empty
|
||||||
if [[ -r "$cache_file" ]] && [[ -s "$cache_file" ]]; then
|
if [[ -r "$cache_file" ]] && [[ -s "$cache_file" ]]; then
|
||||||
if cat "$cache_file" > "$installed_bundles" 2>/dev/null; then
|
if cat "$cache_file" > "$installed_bundles" 2> /dev/null; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
debug_log "Warning: Failed to read cache, rebuilding"
|
debug_log "Warning: Failed to read cache, rebuilding"
|
||||||
@@ -180,9 +180,9 @@ scan_installed_apps() {
|
|||||||
|
|
||||||
# Cache the results
|
# Cache the results
|
||||||
ensure_user_dir "$(dirname "$cache_file")"
|
ensure_user_dir "$(dirname "$cache_file")"
|
||||||
cp "$installed_bundles" "$cache_file" 2>/dev/null || true
|
cp "$installed_bundles" "$cache_file" 2> /dev/null || true
|
||||||
|
|
||||||
local app_count=$(wc -l < "$installed_bundles" 2>/dev/null | tr -d ' ')
|
local app_count=$(wc -l < "$installed_bundles" 2> /dev/null | tr -d ' ')
|
||||||
debug_log "Scanned $app_count unique applications"
|
debug_log "Scanned $app_count unique applications"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -596,12 +596,12 @@ safe_clear_lines() {
|
|||||||
|
|
||||||
# Use centralized ANSI support check (defined below)
|
# Use centralized ANSI support check (defined below)
|
||||||
# Note: This forward reference works because functions are parsed before execution
|
# Note: This forward reference works because functions are parsed before execution
|
||||||
is_ansi_supported 2>/dev/null || return 1
|
is_ansi_supported 2> /dev/null || return 1
|
||||||
|
|
||||||
# Clear lines one by one (more reliable than multi-line sequences)
|
# Clear lines one by one (more reliable than multi-line sequences)
|
||||||
local i
|
local i
|
||||||
for ((i=0; i<lines; i++)); do
|
for ((i = 0; i < lines; i++)); do
|
||||||
printf "\033[1A\r\033[K" > "$tty_device" 2>/dev/null || return 1
|
printf "\033[1A\r\033[K" > "$tty_device" 2> /dev/null || return 1
|
||||||
done
|
done
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -613,9 +613,9 @@ safe_clear_line() {
|
|||||||
local tty_device="${1:-/dev/tty}"
|
local tty_device="${1:-/dev/tty}"
|
||||||
|
|
||||||
# Use centralized ANSI support check
|
# Use centralized ANSI support check
|
||||||
is_ansi_supported 2>/dev/null || return 1
|
is_ansi_supported 2> /dev/null || return 1
|
||||||
|
|
||||||
printf "\r\033[K" > "$tty_device" 2>/dev/null || return 1
|
printf "\r\033[K" > "$tty_device" 2> /dev/null || return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,8 +626,8 @@ safe_clear_line() {
|
|||||||
update_progress_if_needed() {
|
update_progress_if_needed() {
|
||||||
local completed="$1"
|
local completed="$1"
|
||||||
local total="$2"
|
local total="$2"
|
||||||
local last_update_var="$3" # Name of variable holding last update time
|
local last_update_var="$3" # Name of variable holding last update time
|
||||||
local interval="${4:-2}" # Default: update every 2 seconds
|
local interval="${4:-2}" # Default: update every 2 seconds
|
||||||
|
|
||||||
# Get current time
|
# Get current time
|
||||||
local current_time=$(date +%s)
|
local current_time=$(date +%s)
|
||||||
@@ -663,7 +663,7 @@ push_spinner_state() {
|
|||||||
local current_state=""
|
local current_state=""
|
||||||
|
|
||||||
# Save current spinner PID if running
|
# Save current spinner PID if running
|
||||||
if [[ -n "${MOLE_SPINNER_PID:-}" ]] && kill -0 "$MOLE_SPINNER_PID" 2>/dev/null; then
|
if [[ -n "${MOLE_SPINNER_PID:-}" ]] && kill -0 "$MOLE_SPINNER_PID" 2> /dev/null; then
|
||||||
current_state="running:$MOLE_SPINNER_PID"
|
current_state="running:$MOLE_SPINNER_PID"
|
||||||
else
|
else
|
||||||
current_state="stopped"
|
current_state="stopped"
|
||||||
@@ -693,7 +693,7 @@ pop_spinner_state() {
|
|||||||
# Instead of unset, rebuild array without last element
|
# Instead of unset, rebuild array without last element
|
||||||
local -a new_stack=()
|
local -a new_stack=()
|
||||||
local i
|
local i
|
||||||
for ((i=0; i<last_idx; i++)); do
|
for ((i = 0; i < last_idx; i++)); do
|
||||||
new_stack+=("${MOLE_SPINNER_STACK[$i]}")
|
new_stack+=("${MOLE_SPINNER_STACK[$i]}")
|
||||||
done
|
done
|
||||||
MOLE_SPINNER_STACK=("${new_stack[@]}")
|
MOLE_SPINNER_STACK=("${new_stack[@]}")
|
||||||
@@ -719,7 +719,7 @@ safe_start_spinner() {
|
|||||||
push_spinner_state
|
push_spinner_state
|
||||||
|
|
||||||
# Stop any existing spinner
|
# Stop any existing spinner
|
||||||
stop_section_spinner 2>/dev/null || true
|
stop_section_spinner 2> /dev/null || true
|
||||||
|
|
||||||
# Start new spinner
|
# Start new spinner
|
||||||
start_section_spinner "$message"
|
start_section_spinner "$message"
|
||||||
@@ -729,7 +729,7 @@ safe_start_spinner() {
|
|||||||
# Usage: safe_stop_spinner
|
# Usage: safe_stop_spinner
|
||||||
safe_stop_spinner() {
|
safe_stop_spinner() {
|
||||||
# Stop current spinner
|
# Stop current spinner
|
||||||
stop_section_spinner 2>/dev/null || true
|
stop_section_spinner 2> /dev/null || true
|
||||||
|
|
||||||
# Pop previous state
|
# Pop previous state
|
||||||
pop_spinner_state || true
|
pop_spinner_state || true
|
||||||
@@ -751,17 +751,17 @@ is_ansi_supported() {
|
|||||||
|
|
||||||
# Check for known ANSI-compatible terminals
|
# Check for known ANSI-compatible terminals
|
||||||
case "$TERM" in
|
case "$TERM" in
|
||||||
xterm*|vt100|vt220|screen*|tmux*|ansi|linux|rxvt*|konsole*)
|
xterm* | vt100 | vt220 | screen* | tmux* | ansi | linux | rxvt* | konsole*)
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
dumb|unknown)
|
dumb | unknown)
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# Check terminfo database if available
|
# Check terminfo database if available
|
||||||
if command -v tput >/dev/null 2>&1; then
|
if command -v tput > /dev/null 2>&1; then
|
||||||
# Test if terminal supports colors (good proxy for ANSI support)
|
# Test if terminal supports colors (good proxy for ANSI support)
|
||||||
local colors=$(tput colors 2>/dev/null || echo "0")
|
local colors=$(tput colors 2> /dev/null || echo "0")
|
||||||
[[ "$colors" -ge 8 ]] && return 0
|
[[ "$colors" -ge 8 ]] && return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
@@ -777,10 +777,10 @@ get_terminal_info() {
|
|||||||
if is_ansi_supported; then
|
if is_ansi_supported; then
|
||||||
info+=" (ANSI supported)"
|
info+=" (ANSI supported)"
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1; then
|
if command -v tput > /dev/null 2>&1; then
|
||||||
local cols=$(tput cols 2>/dev/null || echo "?")
|
local cols=$(tput cols 2> /dev/null || echo "?")
|
||||||
local lines=$(tput lines 2>/dev/null || echo "?")
|
local lines=$(tput lines 2> /dev/null || echo "?")
|
||||||
local colors=$(tput colors 2>/dev/null || echo "?")
|
local colors=$(tput colors 2> /dev/null || echo "?")
|
||||||
info+=" ${cols}x${lines}, ${colors} colors"
|
info+=" ${cols}x${lines}, ${colors} colors"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -815,8 +815,8 @@ validate_terminal_environment() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# Check terminal size if available
|
# Check terminal size if available
|
||||||
if command -v tput >/dev/null 2>&1; then
|
if command -v tput > /dev/null 2>&1; then
|
||||||
local cols=$(tput cols 2>/dev/null || echo "80")
|
local cols=$(tput cols 2> /dev/null || echo "80")
|
||||||
if [[ "$cols" -lt 60 ]]; then
|
if [[ "$cols" -lt 60 ]]; then
|
||||||
log_warning "Terminal width ($cols cols) is narrow - output may wrap"
|
log_warning "Terminal width ($cols cols) is narrow - output may wrap"
|
||||||
((warnings++))
|
((warnings++))
|
||||||
|
|||||||
10
mole
10
mole
@@ -64,7 +64,7 @@ is_homebrew_install() {
|
|||||||
# Symlink looks good, but verify brew actually manages it
|
# Symlink looks good, but verify brew actually manages it
|
||||||
if command -v brew > /dev/null 2>&1; then
|
if command -v brew > /dev/null 2>&1; then
|
||||||
# Use fast brew list check
|
# Use fast brew list check
|
||||||
brew list --formula 2>/dev/null | grep -q "^mole$" && return 0
|
brew list --formula 2> /dev/null | grep -q "^mole$" && return 0
|
||||||
else
|
else
|
||||||
# brew not available - cannot update/remove via Homebrew
|
# brew not available - cannot update/remove via Homebrew
|
||||||
return 1
|
return 1
|
||||||
@@ -74,14 +74,14 @@ is_homebrew_install() {
|
|||||||
# Fallback: check common Homebrew paths and verify with Cellar
|
# Fallback: check common Homebrew paths and verify with Cellar
|
||||||
if [[ -f "$mole_path" ]]; then
|
if [[ -f "$mole_path" ]]; then
|
||||||
case "$mole_path" in
|
case "$mole_path" in
|
||||||
/opt/homebrew/bin/mole|/usr/local/bin/mole)
|
/opt/homebrew/bin/mole | /usr/local/bin/mole)
|
||||||
# Verify Cellar directory exists
|
# Verify Cellar directory exists
|
||||||
if [[ -d /opt/homebrew/Cellar/mole ]] || [[ -d /usr/local/Cellar/mole ]]; then
|
if [[ -d /opt/homebrew/Cellar/mole ]] || [[ -d /usr/local/Cellar/mole ]]; then
|
||||||
# Double-check with brew if available
|
# Double-check with brew if available
|
||||||
if command -v brew > /dev/null 2>&1; then
|
if command -v brew > /dev/null 2>&1; then
|
||||||
brew list --formula 2>/dev/null | grep -q "^mole$" && return 0
|
brew list --formula 2> /dev/null | grep -q "^mole$" && return 0
|
||||||
else
|
else
|
||||||
return 0 # Cellar exists, probably Homebrew install
|
return 0 # Cellar exists, probably Homebrew install
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -93,7 +93,7 @@ is_homebrew_install() {
|
|||||||
local brew_prefix
|
local brew_prefix
|
||||||
brew_prefix=$(brew --prefix 2> /dev/null)
|
brew_prefix=$(brew --prefix 2> /dev/null)
|
||||||
if [[ -n "$brew_prefix" && "$mole_path" == "$brew_prefix/bin/mole" && -d "$brew_prefix/Cellar/mole" ]]; then
|
if [[ -n "$brew_prefix" && "$mole_path" == "$brew_prefix/bin/mole" && -d "$brew_prefix/Cellar/mole" ]]; then
|
||||||
brew list --formula 2>/dev/null | grep -q "^mole$" && return 0
|
brew list --formula 2> /dev/null | grep -q "^mole$" && return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user