1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-16 18:45:17 +00:00

Support Disk Space Analyzer

This commit is contained in:
Tw93
2025-10-04 18:42:18 +08:00
parent a830123ac4
commit 2929ae5e26
4 changed files with 2318 additions and 19 deletions

View File

@@ -118,6 +118,28 @@ mole --help
可以查看所有可用的命令和说明。 可以查看所有可用的命令和说明。
### 磁盘空间分析 🆕
```bash
mole analyze
```
交互式查看哪些文件和文件夹最占空间,帮助你快速找到并清理大文件。
**基本操作:**
- `` ``:上下选择
- `回车`:进入文件夹 / 打开文件预览
- ``:返回上级
- `Delete`:删除(需确认)
- `q`:退出
**小提示:**
- 文件夹会按大小排序,一目了然
- 文本文件可以直接预览,其他文件用系统默认应用打开
- 超过 15 项会自动分页,继续按方向键滚动查看
--- ---
## 第五步:注意事项 ## 第五步:注意事项

2222
bin/analyze.sh Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,7 @@ readonly BLUE="${ESC}[0;34m"
readonly YELLOW="${ESC}[1;33m" readonly YELLOW="${ESC}[1;33m"
readonly PURPLE="${ESC}[0;35m" readonly PURPLE="${ESC}[0;35m"
readonly RED="${ESC}[0;31m" readonly RED="${ESC}[0;31m"
readonly GRAY="${ESC}[0;90m"
readonly NC="${ESC}[0m" readonly NC="${ESC}[0m"
# Logging configuration # Logging configuration
@@ -104,17 +105,49 @@ read_key() {
'q'|'Q') echo "QUIT" ;; 'q'|'Q') echo "QUIT" ;;
'a'|'A') echo "ALL" ;; 'a'|'A') echo "ALL" ;;
'n'|'N') echo "NONE" ;; 'n'|'N') echo "NONE" ;;
'd'|'D') echo "DELETE" ;;
'r'|'R') echo "RETRY" ;;
'?') echo "HELP" ;; '?') echo "HELP" ;;
$'\x7f'|$'\x08') echo "DELETE" ;; # Delete key (labeled "delete" on Mac, actually backspace)
$'\x1b') $'\x1b')
# Read the next two bytes within 1s; works well on macOS bash 3.2 # ESC sequence - could be arrow key, delete key, or ESC alone
if IFS= read -r -s -n 2 -t 1 rest 2>/dev/null; then # Read the next two bytes within 1s
case "$rest" in if IFS= read -r -s -n 1 -t 1 rest 2>/dev/null; then
"[A") echo "UP" ;; if [[ "$rest" == "[" ]]; then
"[B") echo "DOWN" ;; # Got ESC [, read next character
"[C") echo "RIGHT" ;; if IFS= read -r -s -n 1 -t 1 rest2 2>/dev/null; then
"[D") echo "LEFT" ;; case "$rest2" in
"A") echo "UP" ;;
"B") echo "DOWN" ;;
"C") echo "RIGHT" ;;
"D") echo "LEFT" ;;
"3")
# Delete key (Fn+Delete): ESC [ 3 ~
IFS= read -r -s -n 1 -t 1 rest3 2>/dev/null
if [[ "$rest3" == "~" ]]; then
echo "DELETE"
else
echo "OTHER"
fi
;;
"5")
# Page Up key: ESC [ 5 ~
IFS= read -r -s -n 1 -t 1 rest3 2>/dev/null
[[ "$rest3" == "~" ]] && echo "OTHER" || echo "OTHER"
;;
"6")
# Page Down key: ESC [ 6 ~
IFS= read -r -s -n 1 -t 1 rest3 2>/dev/null
[[ "$rest3" == "~" ]] && echo "OTHER" || echo "OTHER"
;;
*) echo "OTHER" ;; *) echo "OTHER" ;;
esac esac
else
echo "QUIT" # ESC [ timeout
fi
else
echo "QUIT" # ESC + something else
fi
else else
# ESC pressed alone - treat as quit # ESC pressed alone - treat as quit
echo "QUIT" echo "QUIT"
@@ -124,6 +157,19 @@ read_key() {
esac esac
} }
# Drain pending input (useful for scrolling prevention)
drain_pending_input() {
local dummy
local drained=0
# Single pass with reasonable timeout
# Touchpad scrolling can generate bursts of arrow keys
while IFS= read -r -s -n 1 -t 0.001 dummy 2>/dev/null; do
((drained++))
# Safety limit to prevent infinite loop
[[ $drained -gt 500 ]] && break
done
}
# Menu display helper # Menu display helper
show_menu_option() { show_menu_option() {
local number="$1" local number="$1"

29
mole
View File

@@ -4,11 +4,13 @@
# #
# 🧹 Clean - Remove junk files and optimize system # 🧹 Clean - Remove junk files and optimize system
# 🗑️ Uninstall - Remove applications completely # 🗑️ Uninstall - Remove applications completely
# 📊 Analyze - Interactive disk space explorer
# #
# Usage: # Usage:
# ./mole # Interactive main menu # ./mole # Interactive main menu
# ./mole clean # Direct clean mode # ./mole clean # Direct clean mode
# ./mole uninstall # Direct uninstall mode # ./mole uninstall # Direct uninstall mode
# ./mole analyze # Disk space explorer
# ./mole --help # Show help # ./mole --help # Show help
set -euo pipefail set -euo pipefail
@@ -129,6 +131,7 @@ show_help() {
printf " %s%-28s%s %s\n" "$GREEN" "mole clean" "$NC" "Deeper system cleanup" printf " %s%-28s%s %s\n" "$GREEN" "mole clean" "$NC" "Deeper system cleanup"
printf " %s%-28s%s %s\n" "$GREEN" "mole clean --dry-run" "$NC" "Preview cleanup (no deletions)" printf " %s%-28s%s %s\n" "$GREEN" "mole clean --dry-run" "$NC" "Preview cleanup (no deletions)"
printf " %s%-28s%s %s\n" "$GREEN" "mole uninstall" "$NC" "Remove applications completely" printf " %s%-28s%s %s\n" "$GREEN" "mole uninstall" "$NC" "Remove applications completely"
printf " %s%-28s%s %s\n" "$GREEN" "mole analyze" "$NC" "Interactive disk space explorer"
printf " %s%-28s%s %s\n" "$GREEN" "mole update" "$NC" "Update Mole to the latest version" printf " %s%-28s%s %s\n" "$GREEN" "mole update" "$NC" "Update Mole to the latest version"
printf " %s%-28s%s %s\n" "$GREEN" "mole --version" "$NC" "Show installed version" printf " %s%-28s%s %s\n" "$GREEN" "mole --version" "$NC" "Show installed version"
printf " %s%-28s%s %s\n" "$GREEN" "mole --help" "$NC" "Show this help message" printf " %s%-28s%s %s\n" "$GREEN" "mole --help" "$NC" "Show this help message"
@@ -213,14 +216,15 @@ show_main_menu() {
printf '\033[u\033[0J' printf '\033[u\033[0J'
fi fi
show_menu_option 1 "Clean System - Remove junk files and optimize" "$([[ $selected -eq 1 ]] && echo true || echo false)" show_menu_option 1 "Clean Mac - Remove junk files and optimize" "$([[ $selected -eq 1 ]] && echo true || echo false)"
show_menu_option 2 "Uninstall Apps - Remove applications completely" "$([[ $selected -eq 2 ]] && echo true || echo false)" show_menu_option 2 "Uninstall Apps - Remove applications completely" "$([[ $selected -eq 2 ]] && echo true || echo false)"
show_menu_option 3 "Help & Information - Usage guide and tips" "$([[ $selected -eq 3 ]] && echo true || echo false)" show_menu_option 3 "Analyze Disk - Interactive space explorer" "$([[ $selected -eq 3 ]] && echo true || echo false)"
show_menu_option 4 "Exit - Close Mole" "$([[ $selected -eq 4 ]] && echo true || echo false)" show_menu_option 4 "Help & Information - Usage guide and tips" "$([[ $selected -eq 4 ]] && echo true || echo false)"
show_menu_option 5 "Exit - Close Mole" "$([[ $selected -eq 5 ]] && echo true || echo false)"
if [[ -t 0 ]]; then if [[ -t 0 ]]; then
echo "" echo ""
echo -e "${BLUE}↑/↓ to navigate, ENTER to select, Q to quit${NC}" echo -e " ${GRAY}↑/↓${NC} Navigate ${GRAY}|${NC} ${GRAY}Enter${NC} Select ${GRAY}|${NC} ${GRAY}Q/ESC${NC} Quit"
fi fi
} }
@@ -260,7 +264,7 @@ interactive_main_menu() {
case "$key" in case "$key" in
"UP") ((current_option > 1)) && ((current_option--)) ;; "UP") ((current_option > 1)) && ((current_option--)) ;;
"DOWN") ((current_option < 4)) && ((current_option++)) ;; "DOWN") ((current_option < 5)) && ((current_option++)) ;;
"ENTER"|"$current_option") "ENTER"|"$current_option")
show_cursor show_cursor
case $current_option in case $current_option in
@@ -268,20 +272,22 @@ interactive_main_menu() {
exec "$SCRIPT_DIR/bin/clean.sh" exec "$SCRIPT_DIR/bin/clean.sh"
;; ;;
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;; 2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
3) clear; show_help; exit 0 ;; 3) exec "$SCRIPT_DIR/bin/analyze.sh" ;;
4) cleanup_and_exit ;; 4) clear; show_help; exit 0 ;;
5) cleanup_and_exit ;;
esac esac
;; ;;
"QUIT") cleanup_and_exit ;; "QUIT") cleanup_and_exit ;;
[1-4]) [1-5])
show_cursor show_cursor
case $key in case $key in
1) 1)
exec "$SCRIPT_DIR/bin/clean.sh" exec "$SCRIPT_DIR/bin/clean.sh"
;; ;;
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;; 2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
3) clear; show_help; exit 0 ;; 3) exec "$SCRIPT_DIR/bin/analyze.sh" ;;
4) cleanup_and_exit ;; 4) clear; show_help; exit 0 ;;
5) cleanup_and_exit ;;
esac esac
;; ;;
esac esac
@@ -296,6 +302,9 @@ main() {
"uninstall") "uninstall")
exec "$SCRIPT_DIR/bin/uninstall.sh" exec "$SCRIPT_DIR/bin/uninstall.sh"
;; ;;
"analyze")
exec "$SCRIPT_DIR/bin/analyze.sh" "${@:2}"
;;
"update") "update")
update_mole update_mole
exit 0 exit 0