mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 21:55:08 +00:00
style: improve code consistency and formatting
- Rename _MOLE_HINTS_DIR to mole_hints_dir (naming convention) - Split local variable declaration and assignment - Add ICON_INFO constant to base.sh - Remove redundant has_cached_sudo function (use has_sudo_session)
This commit is contained in:
23
bin/clean.sh
23
bin/clean.sh
@@ -137,11 +137,6 @@ note_activity() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2329
|
|
||||||
has_cached_sudo() {
|
|
||||||
sudo -n true 2> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
CLEANUP_DONE=false
|
CLEANUP_DONE=false
|
||||||
# shellcheck disable=SC2329
|
# shellcheck disable=SC2329
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@@ -626,7 +621,8 @@ safe_clean() {
|
|||||||
# Stop spinner before output
|
# Stop spinner before output
|
||||||
stop_section_spinner
|
stop_section_spinner
|
||||||
|
|
||||||
local size_human=$(bytes_to_human "$((total_size_kb * 1024))")
|
local size_human
|
||||||
|
size_human=$(bytes_to_human "$((total_size_kb * 1024))")
|
||||||
|
|
||||||
local label="$description"
|
local label="$description"
|
||||||
if [[ ${#targets[@]} -gt 1 ]]; then
|
if [[ ${#targets[@]} -gt 1 ]]; then
|
||||||
@@ -636,7 +632,8 @@ safe_clean() {
|
|||||||
if [[ "$DRY_RUN" == "true" ]]; then
|
if [[ "$DRY_RUN" == "true" ]]; then
|
||||||
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} $label${NC}, ${YELLOW}$size_human dry${NC}"
|
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} $label${NC}, ${YELLOW}$size_human dry${NC}"
|
||||||
|
|
||||||
local paths_temp=$(create_temp_file)
|
local paths_temp
|
||||||
|
paths_temp=$(create_temp_file)
|
||||||
|
|
||||||
idx=0
|
idx=0
|
||||||
if [[ ${#existing_paths[@]} -gt 0 ]]; then
|
if [[ ${#existing_paths[@]} -gt 0 ]]; then
|
||||||
@@ -683,7 +680,8 @@ safe_clean() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
' | while IFS='|' read -r display_path total_size child_count; do
|
' | while IFS='|' read -r display_path total_size child_count; do
|
||||||
local size_human=$(bytes_to_human "$((total_size * 1024))")
|
local size_human
|
||||||
|
size_human=$(bytes_to_human "$((total_size * 1024))")
|
||||||
if [[ $child_count -gt 1 ]]; then
|
if [[ $child_count -gt 1 ]]; then
|
||||||
echo "$display_path # $size_human, $child_count items" >> "$EXPORT_LIST_FILE"
|
echo "$display_path # $size_human, $child_count items" >> "$EXPORT_LIST_FILE"
|
||||||
else
|
else
|
||||||
@@ -738,7 +736,7 @@ start_cleanup() {
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Preview system section when sudo is already cached (no password prompt).
|
# Preview system section when sudo is already cached (no password prompt).
|
||||||
if has_cached_sudo; then
|
if has_sudo_session; then
|
||||||
SYSTEM_CLEAN=true
|
SYSTEM_CLEAN=true
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access available, system preview included"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access available, system preview included"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -751,7 +749,7 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -t 0 ]]; then
|
if [[ -t 0 ]]; then
|
||||||
if has_cached_sudo; then
|
if has_sudo_session; then
|
||||||
SYSTEM_CLEAN=true
|
SYSTEM_CLEAN=true
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access already available"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Admin access already available"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -791,7 +789,7 @@ EOF
|
|||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
echo "Running in non-interactive mode"
|
echo "Running in non-interactive mode"
|
||||||
if has_cached_sudo; then
|
if has_sudo_session; then
|
||||||
SYSTEM_CLEAN=true
|
SYSTEM_CLEAN=true
|
||||||
echo " ${ICON_LIST} System-level cleanup enabled, sudo session active"
|
echo " ${ICON_LIST} System-level cleanup enabled, sudo session active"
|
||||||
else
|
else
|
||||||
@@ -1069,7 +1067,8 @@ perform_cleanup() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local final_free_space=$(get_free_space)
|
local final_free_space
|
||||||
|
final_free_space=$(get_free_space)
|
||||||
summary_details+=("Free space now: $final_free_space")
|
summary_details+=("Free space now: $final_free_space")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
_MOLE_HINTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
mole_hints_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$_MOLE_HINTS_DIR/purge_shared.sh"
|
source "$mole_hints_dir/purge_shared.sh"
|
||||||
|
|
||||||
# Quick reminder probe for project build artifacts handled by `mo purge`.
|
# Quick reminder probe for project build artifacts handled by `mo purge`.
|
||||||
# Designed to be very fast: shallow directory checks only, no deep find scans.
|
# Designed to be very fast: shallow directory checks only, no deep find scans.
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ readonly ICON_DRY_RUN="→"
|
|||||||
readonly ICON_REVIEW="☞"
|
readonly ICON_REVIEW="☞"
|
||||||
readonly ICON_NAV_UP="↑"
|
readonly ICON_NAV_UP="↑"
|
||||||
readonly ICON_NAV_DOWN="↓"
|
readonly ICON_NAV_DOWN="↓"
|
||||||
|
readonly ICON_INFO="ℹ"
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Global Configuration Constants
|
# Global Configuration Constants
|
||||||
|
|||||||
Reference in New Issue
Block a user