1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-06 23:00:38 +00:00

Grammar check and optimization

This commit is contained in:
Tw93
2025-12-02 17:02:14 +08:00
parent bb50a345b6
commit 443b59d9c7
14 changed files with 41 additions and 28 deletions

View File

@@ -374,8 +374,10 @@ check_mole_update() {
fi
# Normalize version strings (remove leading 'v' or 'V')
current_version=$(echo "$current_version" | sed 's/^[vV]//')
latest_version=$(echo "$latest_version" | sed 's/^[vV]//')
current_version="${current_version#v}"
current_version="${current_version#V}"
latest_version="${latest_version#v}"
latest_version="${latest_version#V}"
if [[ -n "$latest_version" && "$current_version" != "$latest_version" ]]; then
# Compare versions
@@ -398,7 +400,8 @@ check_all_updates() {
check_homebrew_updates
# Preload software update data to avoid delays between subsequent checks
get_software_updates > /dev/null 2>&1
# Only redirect stdout, keep stderr for spinner display
get_software_updates > /dev/null
check_appstore_updates
check_macos_update
@@ -599,7 +602,7 @@ check_swap_usage() {
local swap_info=$(sysctl vm.swapusage 2> /dev/null || echo "")
if [[ -n "$swap_info" ]]; then
local swap_used=$(echo "$swap_info" | grep -o "used = [0-9.]*[GM]" | awk '{print $3}' || echo "0M")
local swap_num=$(echo "$swap_used" | sed 's/[GM]//')
local swap_num="${swap_used//[GM]/}"
if [[ "$swap_used" == *"G"* ]]; then
local swap_gb=${swap_num%.*}

View File

@@ -88,7 +88,7 @@ is_interactive() {
# Get spinner characters (overridable via MO_SPINNER_CHARS)
mo_spinner_chars() {
local chars="${MO_SPINNER_CHARS:-|/-\\}"
[[ -z "$chars" ]] && chars='|/-\\'
[[ -z "$chars" ]] && chars="|/-\\"
printf "%s" "$chars"
}
@@ -803,7 +803,7 @@ request_sudo_access() {
request_sudo() {
echo "This operation requires administrator privileges."
echo -n "Please enter your password: "
read -s password
read -r -s password
echo
if echo "$password" | sudo -S true 2> /dev/null; then
return 0
@@ -822,6 +822,7 @@ update_via_homebrew() {
local brew_pid=""
local brew_tmp_file=""
local brew_exit_file=""
# shellcheck disable=SC2329
cleanup_brew_update() {
if [[ -n "$brew_pid" ]] && kill -0 "$brew_pid" 2> /dev/null; then
kill -TERM "$brew_pid" 2> /dev/null || true
@@ -971,7 +972,7 @@ start_inline_spinner() {
trap 'exit 0' TERM INT EXIT
local chars
chars="$(mo_spinner_chars)"
[[ -z "$chars" ]] && chars='|/-\'
[[ -z "$chars" ]] && chars="|/-\\"
local i=0
while true; do
local c="${chars:$((i % ${#chars})):1}"

View File

@@ -142,8 +142,10 @@ load_whitelist() {
if [[ -f "$WHITELIST_CONFIG" ]]; then
while IFS= read -r line; do
line="${line#${line%%[![:space:]]*}}"
line="${line%${line##*[![:space:]]}}"
# shellcheck disable=SC2295
line="${line#"${line%%[![:space:]]*}"}"
# shellcheck disable=SC2295
line="${line%"${line##*[![:space:]]}"}"
[[ -z "$line" || "$line" =~ ^# ]] && continue
patterns+=("$line")
done < "$WHITELIST_CONFIG"

View File

@@ -129,7 +129,7 @@ paginated_multi_select() {
for ((i = 0; i < len; i++)); do
c="${s:i:1}"
case "$c" in
'\' | '*' | '?' | '[' | ']') out+="\\$c" ;;
$'\\' | '*' | '?' | '[' | ']') out+="\\$c" ;;
*) out+="$c" ;;
esac
done
@@ -196,6 +196,7 @@ paginated_multi_select() {
}
# Interrupt handler
# shellcheck disable=SC2329
handle_interrupt() {
cleanup
exit 130 # Standard exit code for Ctrl+C
@@ -216,6 +217,7 @@ paginated_multi_select() {
hide_cursor
# Helper functions
# shellcheck disable=SC2329
print_line() { printf "\r\033[2K%s\n" "$1" >&2; }
# Print footer lines wrapping only at separators

View File

@@ -109,6 +109,7 @@ paginated_multi_select() {
}
# Interrupt handler
# shellcheck disable=SC2329
handle_interrupt() {
cleanup
exit 130 # Standard exit code for Ctrl+C
@@ -129,6 +130,7 @@ paginated_multi_select() {
hide_cursor
# Helper functions
# shellcheck disable=SC2329
print_line() { printf "\r\033[2K%s\n" "$1" >&2; }
render_item() {

View File

@@ -98,9 +98,11 @@ remove_file_list() {
}
# Batch uninstall with single confirmation
# Globals: selected_apps (read) - array of selected applications
batch_uninstall_applications() {
local total_size_freed=0
# shellcheck disable=SC2154
if [[ ${#selected_apps[@]} -eq 0 ]]; then
log_warning "No applications selected for uninstallation"
return 0
@@ -132,12 +134,16 @@ batch_uninstall_applications() {
local app_size_kb=$(get_path_size_kb "$app_path")
local related_files=$(find_app_files "$bundle_id" "$app_name")
local related_size_kb=$(calculate_total_size "$related_files")
# system_files is a newline-separated string, not an array
# shellcheck disable=SC2178,SC2128
local system_files=$(find_app_system_files "$bundle_id" "$app_name")
# shellcheck disable=SC2128
local system_size_kb=$(calculate_total_size "$system_files")
local total_kb=$((app_size_kb + related_size_kb + system_size_kb))
((total_estimated_size += total_kb))
# Check if system files require sudo
# shellcheck disable=SC2128
if [[ -n "$system_files" ]]; then
sudo_apps+=("$app_name")
fi
@@ -165,7 +171,7 @@ batch_uninstall_applications() {
local app_size_display=$(bytes_to_human "$((total_kb * 1024))")
echo -e "${BLUE}${ICON_CONFIRM}${NC} ${app_name} ${GRAY}(${app_size_display})${NC}"
echo -e " ${GREEN}${ICON_SUCCESS}${NC} $(echo "$app_path" | sed "s|$HOME|~|")"
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${app_path/$HOME/~}"
# Show related files (limit to 5 most important ones for brevity)
local file_count=0
@@ -173,7 +179,7 @@ batch_uninstall_applications() {
while IFS= read -r file; do
if [[ -n "$file" && -e "$file" ]]; then
if [[ $file_count -lt $max_files ]]; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} $(echo "$file" | sed "s|$HOME|~|")"
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${file/$HOME/~}"
fi
((file_count++))
fi