mirror of
https://github.com/tw93/Mole.git
synced 2026-02-09 17:19:16 +00:00
chore: auto format code
This commit is contained in:
@@ -16,7 +16,6 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
source "$SCRIPT_DIR/../lib/core/common.sh"
|
source "$SCRIPT_DIR/../lib/core/common.sh"
|
||||||
source "$SCRIPT_DIR/../lib/ui/menu_paginated.sh"
|
source "$SCRIPT_DIR/../lib/ui/menu_paginated.sh"
|
||||||
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [[ "${IN_ALT_SCREEN:-0}" == "1" ]]; then
|
if [[ "${IN_ALT_SCREEN:-0}" == "1" ]]; then
|
||||||
leave_alt_screen
|
leave_alt_screen
|
||||||
@@ -31,18 +30,18 @@ trap 'trap - EXIT; cleanup; exit 130' INT TERM
|
|||||||
# Scan configuration
|
# Scan configuration
|
||||||
readonly INSTALLER_SCAN_MAX_DEPTH_DEFAULT=2
|
readonly INSTALLER_SCAN_MAX_DEPTH_DEFAULT=2
|
||||||
readonly INSTALLER_SCAN_PATHS=(
|
readonly INSTALLER_SCAN_PATHS=(
|
||||||
"$HOME/Downloads"
|
"$HOME/Downloads"
|
||||||
"$HOME/Desktop"
|
"$HOME/Desktop"
|
||||||
"$HOME/Documents"
|
"$HOME/Documents"
|
||||||
"$HOME/Public"
|
"$HOME/Public"
|
||||||
"$HOME/Library/Downloads"
|
"$HOME/Library/Downloads"
|
||||||
"/Users/Shared"
|
"/Users/Shared"
|
||||||
"/Users/Shared/Downloads"
|
"/Users/Shared/Downloads"
|
||||||
"$HOME/Library/Caches/Homebrew"
|
"$HOME/Library/Caches/Homebrew"
|
||||||
"$HOME/Library/Mobile Documents/com~apple~CloudDocs/Downloads"
|
"$HOME/Library/Mobile Documents/com~apple~CloudDocs/Downloads"
|
||||||
"$HOME/Library/Containers/com.apple.mail/Data/Library/Mail Downloads"
|
"$HOME/Library/Containers/com.apple.mail/Data/Library/Mail Downloads"
|
||||||
"$HOME/Library/Application Support/Telegram Desktop"
|
"$HOME/Library/Application Support/Telegram Desktop"
|
||||||
"$HOME/Downloads/Telegram Desktop"
|
"$HOME/Downloads/Telegram Desktop"
|
||||||
)
|
)
|
||||||
readonly MAX_ZIP_ENTRIES=5
|
readonly MAX_ZIP_ENTRIES=5
|
||||||
ZIP_LIST_CMD=()
|
ZIP_LIST_CMD=()
|
||||||
@@ -63,9 +62,9 @@ is_installer_zip() {
|
|||||||
|
|
||||||
[[ ${#ZIP_LIST_CMD[@]} -gt 0 ]] || return 1
|
[[ ${#ZIP_LIST_CMD[@]} -gt 0 ]] || return 1
|
||||||
|
|
||||||
if ! "${ZIP_LIST_CMD[@]}" "$zip" 2>/dev/null \
|
if ! "${ZIP_LIST_CMD[@]}" "$zip" 2> /dev/null |
|
||||||
| head -n $((cap + 1)) \
|
head -n $((cap + 1)) |
|
||||||
| awk -v cap="$cap" '
|
awk -v cap="$cap" '
|
||||||
/\.(app|pkg|dmg|xip)(\/|$)/ { found=1 }
|
/\.(app|pkg|dmg|xip)(\/|$)/ { found=1 }
|
||||||
END {
|
END {
|
||||||
if (NR > cap) exit 1
|
if (NR > cap) exit 1
|
||||||
@@ -81,14 +80,14 @@ is_installer_zip() {
|
|||||||
handle_candidate_file() {
|
handle_candidate_file() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
|
|
||||||
[[ -L "$file" ]] && return 0 # Skip symlinks explicitly
|
[[ -L "$file" ]] && return 0 # Skip symlinks explicitly
|
||||||
case "$file" in
|
case "$file" in
|
||||||
*.dmg|*.pkg|*.mpkg|*.iso|*.xip)
|
*.dmg | *.pkg | *.mpkg | *.iso | *.xip)
|
||||||
echo "$file"
|
echo "$file"
|
||||||
;;
|
;;
|
||||||
*.zip)
|
*.zip)
|
||||||
[[ -r "$file" ]] || return 0
|
[[ -r "$file" ]] || return 0
|
||||||
if is_installer_zip "$file" 2>/dev/null; then
|
if is_installer_zip "$file" 2> /dev/null; then
|
||||||
echo "$file"
|
echo "$file"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -109,7 +108,7 @@ scan_installers_in_path() {
|
|||||||
done < <(
|
done < <(
|
||||||
fd --no-ignore --hidden --type f --max-depth "$max_depth" \
|
fd --no-ignore --hidden --type f --max-depth "$max_depth" \
|
||||||
-e dmg -e pkg -e mpkg -e iso -e xip -e zip \
|
-e dmg -e pkg -e mpkg -e iso -e xip -e zip \
|
||||||
. "$path" 2>/dev/null || true
|
. "$path" 2> /dev/null || true
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
while IFS= read -r file; do
|
while IFS= read -r file; do
|
||||||
@@ -117,8 +116,8 @@ scan_installers_in_path() {
|
|||||||
done < <(
|
done < <(
|
||||||
find "$path" -maxdepth "$max_depth" -type f \
|
find "$path" -maxdepth "$max_depth" -type f \
|
||||||
\( -name '*.dmg' -o -name '*.pkg' -o -name '*.mpkg' \
|
\( -name '*.dmg' -o -name '*.pkg' -o -name '*.mpkg' \
|
||||||
-o -name '*.iso' -o -name '*.xip' -o -name '*.zip' \) \
|
-o -name '*.iso' -o -name '*.xip' -o -name '*.zip' \) \
|
||||||
2>/dev/null || true
|
2> /dev/null || true
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -162,7 +161,7 @@ get_source_display() {
|
|||||||
|
|
||||||
get_terminal_width() {
|
get_terminal_width() {
|
||||||
if [[ $TERMINAL_WIDTH -le 0 ]]; then
|
if [[ $TERMINAL_WIDTH -le 0 ]]; then
|
||||||
TERMINAL_WIDTH=$(tput cols 2>/dev/null || echo 80)
|
TERMINAL_WIDTH=$(tput cols 2> /dev/null || echo 80)
|
||||||
fi
|
fi
|
||||||
echo "$TERMINAL_WIDTH"
|
echo "$TERMINAL_WIDTH"
|
||||||
}
|
}
|
||||||
@@ -176,7 +175,7 @@ format_installer_display() {
|
|||||||
# Terminal width for alignment
|
# Terminal width for alignment
|
||||||
local terminal_width
|
local terminal_width
|
||||||
terminal_width=$(get_terminal_width)
|
terminal_width=$(get_terminal_width)
|
||||||
local fixed_width=24 # Reserve for size and source
|
local fixed_width=24 # Reserve for size and source
|
||||||
local available_width=$((terminal_width - fixed_width))
|
local available_width=$((terminal_width - fixed_width))
|
||||||
|
|
||||||
# Bounds check: 20-40 chars for filename
|
# Bounds check: 20-40 chars for filename
|
||||||
@@ -280,11 +279,11 @@ select_installers() {
|
|||||||
_get_items_per_page() {
|
_get_items_per_page() {
|
||||||
local term_height=24
|
local term_height=24
|
||||||
if [[ -t 0 ]] || [[ -t 2 ]]; then
|
if [[ -t 0 ]] || [[ -t 2 ]]; then
|
||||||
term_height=$(stty size </dev/tty 2>/dev/null | awk '{print $1}')
|
term_height=$(stty size < /dev/tty 2> /dev/null | awk '{print $1}')
|
||||||
fi
|
fi
|
||||||
if [[ -z "$term_height" || $term_height -le 0 ]]; then
|
if [[ -z "$term_height" || $term_height -le 0 ]]; then
|
||||||
if command -v tput > /dev/null 2>&1; then
|
if command -v tput > /dev/null 2>&1; then
|
||||||
term_height=$(tput lines 2>/dev/null || echo "24")
|
term_height=$(tput lines 2> /dev/null || echo "24")
|
||||||
else
|
else
|
||||||
term_height=24
|
term_height=24
|
||||||
fi
|
fi
|
||||||
@@ -312,7 +311,7 @@ select_installers() {
|
|||||||
|
|
||||||
local original_stty=""
|
local original_stty=""
|
||||||
if [[ -t 0 ]] && command -v stty > /dev/null 2>&1; then
|
if [[ -t 0 ]] && command -v stty > /dev/null 2>&1; then
|
||||||
original_stty=$(stty -g 2>/dev/null || echo "")
|
original_stty=$(stty -g 2> /dev/null || echo "")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
restore_terminal() {
|
restore_terminal() {
|
||||||
@@ -323,11 +322,10 @@ select_installers() {
|
|||||||
fi
|
fi
|
||||||
show_cursor
|
show_cursor
|
||||||
if [[ -n "${original_stty:-}" ]]; then
|
if [[ -n "${original_stty:-}" ]]; then
|
||||||
stty "${original_stty}" 2>/dev/null || stty sane 2>/dev/null || true
|
stty "${original_stty}" 2> /dev/null || stty sane 2> /dev/null || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
handle_interrupt() {
|
handle_interrupt() {
|
||||||
restore_terminal
|
restore_terminal
|
||||||
exit 130
|
exit 130
|
||||||
@@ -407,7 +405,7 @@ select_installers() {
|
|||||||
|
|
||||||
trap restore_terminal EXIT
|
trap restore_terminal EXIT
|
||||||
trap handle_interrupt INT TERM
|
trap handle_interrupt INT TERM
|
||||||
stty -echo -icanon intr ^C 2>/dev/null || true
|
stty -echo -icanon intr ^C 2> /dev/null || true
|
||||||
hide_cursor
|
hide_cursor
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
printf "\033[2J\033[H" >&2
|
printf "\033[2J\033[H" >&2
|
||||||
@@ -459,12 +457,12 @@ select_installers() {
|
|||||||
selected[idx]=true
|
selected[idx]=true
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"a"|"A") # Select all
|
"a" | "A") # Select all
|
||||||
for ((i = 0; i < total_items; i++)); do
|
for ((i = 0; i < total_items; i++)); do
|
||||||
selected[i]=true
|
selected[i]=true
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
"i"|"I") # Invert selection
|
"i" | "I") # Invert selection
|
||||||
for ((i = 0; i < total_items; i++)); do
|
for ((i = 0; i < total_items; i++)); do
|
||||||
if [[ ${selected[i]} == true ]]; then
|
if [[ ${selected[i]} == true ]]; then
|
||||||
selected[i]=false
|
selected[i]=false
|
||||||
@@ -473,11 +471,11 @@ select_installers() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
"q"|"Q"|$'\x03') # Quit or Ctrl-C
|
"q" | "Q" | $'\x03') # Quit or Ctrl-C
|
||||||
restore_terminal
|
restore_terminal
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
""|$'\n'|$'\r') # Enter - confirm
|
"" | $'\n' | $'\r') # Enter - confirm
|
||||||
MOLE_SELECTION_RESULT=""
|
MOLE_SELECTION_RESULT=""
|
||||||
for ((i = 0; i < total_items; i++)); do
|
for ((i = 0; i < total_items; i++)); do
|
||||||
if [[ ${selected[i]} == true ]]; then
|
if [[ ${selected[i]} == true ]]; then
|
||||||
@@ -512,7 +510,7 @@ show_installer_menu() {
|
|||||||
delete_selected_installers() {
|
delete_selected_installers() {
|
||||||
# Parse selection indices
|
# Parse selection indices
|
||||||
local -a selected_indices=()
|
local -a selected_indices=()
|
||||||
[[ -n "$MOLE_SELECTION_RESULT" ]] && IFS=',' read -ra selected_indices <<<"$MOLE_SELECTION_RESULT"
|
[[ -n "$MOLE_SELECTION_RESULT" ]] && IFS=',' read -ra selected_indices <<< "$MOLE_SELECTION_RESULT"
|
||||||
|
|
||||||
if [[ ${#selected_indices[@]} -eq 0 ]]; then
|
if [[ ${#selected_indices[@]} -eq 0 ]]; then
|
||||||
return 1
|
return 1
|
||||||
@@ -546,12 +544,12 @@ delete_selected_installers() {
|
|||||||
|
|
||||||
IFS= read -r -s -n1 confirm || confirm=""
|
IFS= read -r -s -n1 confirm || confirm=""
|
||||||
case "$confirm" in
|
case "$confirm" in
|
||||||
$'\e'|q|Q)
|
$'\e' | q | Q)
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
""|$'\n'|$'\r')
|
"" | $'\n' | $'\r')
|
||||||
printf "\r\033[K" # Clear prompt line
|
printf "\r\033[K" # Clear prompt line
|
||||||
echo "" # Single line break
|
echo "" # Single line break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
return 1
|
return 1
|
||||||
@@ -611,7 +609,7 @@ perform_installers() {
|
|||||||
printf '\n'
|
printf '\n'
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Great! No installer files to clean"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Great! No installer files to clean"
|
||||||
printf '\n'
|
printf '\n'
|
||||||
return 2 # Nothing to clean
|
return 2 # Nothing to clean
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show menu
|
# Show menu
|
||||||
@@ -620,7 +618,7 @@ perform_installers() {
|
|||||||
leave_alt_screen
|
leave_alt_screen
|
||||||
IN_ALT_SCREEN=0
|
IN_ALT_SCREEN=0
|
||||||
fi
|
fi
|
||||||
return 1 # User cancelled
|
return 1 # User cancelled
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Leave alt screen before deletion (so confirmation and results are on main screen)
|
# Leave alt screen before deletion (so confirmation and results are on main screen)
|
||||||
@@ -655,7 +653,6 @@ show_summary() {
|
|||||||
printf '\n'
|
printf '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
|
|||||||
@@ -600,7 +600,7 @@ is_path_whitelisted() {
|
|||||||
local check_pattern="${pattern%/}"
|
local check_pattern="${pattern%/}"
|
||||||
local has_glob="false"
|
local has_glob="false"
|
||||||
case "$check_pattern" in
|
case "$check_pattern" in
|
||||||
*\**|*\?*|*\[*)
|
*\** | *\?* | *\[*)
|
||||||
has_glob="true"
|
has_glob="true"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -106,18 +106,18 @@ safe_remove() {
|
|||||||
|
|
||||||
if [[ -e "$path" ]]; then
|
if [[ -e "$path" ]]; then
|
||||||
local size_kb
|
local size_kb
|
||||||
size_kb=$(get_path_size_kb "$path" 2>/dev/null || echo "0")
|
size_kb=$(get_path_size_kb "$path" 2> /dev/null || echo "0")
|
||||||
if [[ "$size_kb" -gt 0 ]]; then
|
if [[ "$size_kb" -gt 0 ]]; then
|
||||||
file_size=$(bytes_to_human "$((size_kb * 1024))")
|
file_size=$(bytes_to_human "$((size_kb * 1024))")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "$path" || -d "$path" ]] && ! [[ -L "$path" ]]; then
|
if [[ -f "$path" || -d "$path" ]] && ! [[ -L "$path" ]]; then
|
||||||
local mod_time
|
local mod_time
|
||||||
mod_time=$(stat -f%m "$path" 2>/dev/null || echo "0")
|
mod_time=$(stat -f%m "$path" 2> /dev/null || echo "0")
|
||||||
local now
|
local now
|
||||||
now=$(date +%s 2>/dev/null || echo "0")
|
now=$(date +%s 2> /dev/null || echo "0")
|
||||||
if [[ "$mod_time" -gt 0 && "$now" -gt 0 ]]; then
|
if [[ "$mod_time" -gt 0 && "$now" -gt 0 ]]; then
|
||||||
file_age=$(( (now - mod_time) / 86400 ))
|
file_age=$(((now - mod_time) / 86400))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -183,20 +183,20 @@ safe_sudo_remove() {
|
|||||||
local file_size=""
|
local file_size=""
|
||||||
local file_age=""
|
local file_age=""
|
||||||
|
|
||||||
if sudo test -e "$path" 2>/dev/null; then
|
if sudo test -e "$path" 2> /dev/null; then
|
||||||
local size_kb
|
local size_kb
|
||||||
size_kb=$(sudo du -sk "$path" 2>/dev/null | awk '{print $1}' || echo "0")
|
size_kb=$(sudo du -sk "$path" 2> /dev/null | awk '{print $1}' || echo "0")
|
||||||
if [[ "$size_kb" -gt 0 ]]; then
|
if [[ "$size_kb" -gt 0 ]]; then
|
||||||
file_size=$(bytes_to_human "$((size_kb * 1024))")
|
file_size=$(bytes_to_human "$((size_kb * 1024))")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if sudo test -f "$path" 2>/dev/null || sudo test -d "$path" 2>/dev/null; then
|
if sudo test -f "$path" 2> /dev/null || sudo test -d "$path" 2> /dev/null; then
|
||||||
local mod_time
|
local mod_time
|
||||||
mod_time=$(sudo stat -f%m "$path" 2>/dev/null || echo "0")
|
mod_time=$(sudo stat -f%m "$path" 2> /dev/null || echo "0")
|
||||||
local now
|
local now
|
||||||
now=$(date +%s 2>/dev/null || echo "0")
|
now=$(date +%s 2> /dev/null || echo "0")
|
||||||
if [[ "$mod_time" -gt 0 && "$now" -gt 0 ]]; then
|
if [[ "$mod_time" -gt 0 && "$now" -gt 0 ]]; then
|
||||||
file_age=$(( (now - mod_time) / 86400 ))
|
file_age=$(((now - mod_time) / 86400))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ debug_operation_start() {
|
|||||||
|
|
||||||
# Log detailed operation information
|
# Log detailed operation information
|
||||||
debug_operation_detail() {
|
debug_operation_detail() {
|
||||||
local detail_type="$1" # e.g., "Method", "Target", "Expected Outcome"
|
local detail_type="$1" # e.g., "Method", "Target", "Expected Outcome"
|
||||||
local detail_value="$2"
|
local detail_value="$2"
|
||||||
|
|
||||||
if [[ "${MO_DEBUG:-}" == "1" ]]; then
|
if [[ "${MO_DEBUG:-}" == "1" ]]; then
|
||||||
@@ -132,7 +132,7 @@ debug_operation_detail() {
|
|||||||
|
|
||||||
# Log individual file action with metadata
|
# Log individual file action with metadata
|
||||||
debug_file_action() {
|
debug_file_action() {
|
||||||
local action="$1" # e.g., "Would remove", "Removing"
|
local action="$1" # e.g., "Would remove", "Removing"
|
||||||
local file_path="$2"
|
local file_path="$2"
|
||||||
local file_size="${3:-}"
|
local file_size="${3:-}"
|
||||||
local file_age="${4:-}"
|
local file_age="${4:-}"
|
||||||
@@ -153,7 +153,7 @@ debug_file_action() {
|
|||||||
|
|
||||||
# Log risk level for operations
|
# Log risk level for operations
|
||||||
debug_risk_level() {
|
debug_risk_level() {
|
||||||
local risk_level="$1" # LOW, MEDIUM, HIGH
|
local risk_level="$1" # LOW, MEDIUM, HIGH
|
||||||
local reason="$2"
|
local reason="$2"
|
||||||
|
|
||||||
if [[ "${MO_DEBUG:-}" == "1" ]]; then
|
if [[ "${MO_DEBUG:-}" == "1" ]]; then
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ opt_cache_refresh() {
|
|||||||
for target_path in "${cache_targets[@]}"; do
|
for target_path in "${cache_targets[@]}"; do
|
||||||
if [[ -e "$target_path" ]]; then
|
if [[ -e "$target_path" ]]; then
|
||||||
local size_kb
|
local size_kb
|
||||||
size_kb=$(get_path_size_kb "$target_path" 2>/dev/null || echo "0")
|
size_kb=$(get_path_size_kb "$target_path" 2> /dev/null || echo "0")
|
||||||
local size_human="unknown"
|
local size_human="unknown"
|
||||||
if [[ "$size_kb" -gt 0 ]]; then
|
if [[ "$size_kb" -gt 0 ]]; then
|
||||||
size_human=$(bytes_to_human "$((size_kb * 1024))")
|
size_human=$(bytes_to_human "$((size_kb * 1024))")
|
||||||
|
|||||||
Reference in New Issue
Block a user