1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-16 04:51:11 +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 PURPLE="${ESC}[0;35m"
readonly RED="${ESC}[0;31m"
readonly GRAY="${ESC}[0;90m"
readonly NC="${ESC}[0m"
# Logging configuration
@@ -104,17 +105,49 @@ read_key() {
'q'|'Q') echo "QUIT" ;;
'a'|'A') echo "ALL" ;;
'n'|'N') echo "NONE" ;;
'd'|'D') echo "DELETE" ;;
'r'|'R') echo "RETRY" ;;
'?') echo "HELP" ;;
$'\x7f'|$'\x08') echo "DELETE" ;; # Delete key (labeled "delete" on Mac, actually backspace)
$'\x1b')
# Read the next two bytes within 1s; works well on macOS bash 3.2
if IFS= read -r -s -n 2 -t 1 rest 2>/dev/null; then
case "$rest" in
"[A") echo "UP" ;;
"[B") echo "DOWN" ;;
"[C") echo "RIGHT" ;;
"[D") echo "LEFT" ;;
*) echo "OTHER" ;;
esac
# ESC sequence - could be arrow key, delete key, or ESC alone
# Read the next two bytes within 1s
if IFS= read -r -s -n 1 -t 1 rest 2>/dev/null; then
if [[ "$rest" == "[" ]]; then
# Got ESC [, read next character
if IFS= read -r -s -n 1 -t 1 rest2 2>/dev/null; then
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" ;;
esac
else
echo "QUIT" # ESC [ timeout
fi
else
echo "QUIT" # ESC + something else
fi
else
# ESC pressed alone - treat as quit
echo "QUIT"
@@ -124,6 +157,19 @@ read_key() {
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
show_menu_option() {
local number="$1"

29
mole
View File

@@ -4,11 +4,13 @@
#
# 🧹 Clean - Remove junk files and optimize system
# 🗑️ Uninstall - Remove applications completely
# 📊 Analyze - Interactive disk space explorer
#
# Usage:
# ./mole # Interactive main menu
# ./mole clean # Direct clean mode
# ./mole uninstall # Direct uninstall mode
# ./mole analyze # Disk space explorer
# ./mole --help # Show help
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 --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 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 --version" "$NC" "Show installed version"
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'
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 3 "Help & Information - Usage guide and tips" "$([[ $selected -eq 3 ]] && echo true || echo false)"
show_menu_option 4 "Exit - Close Mole" "$([[ $selected -eq 4 ]] && echo true || echo false)"
show_menu_option 3 "Analyze Disk - Interactive space explorer" "$([[ $selected -eq 3 ]] && 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
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
}
@@ -260,7 +264,7 @@ interactive_main_menu() {
case "$key" in
"UP") ((current_option > 1)) && ((current_option--)) ;;
"DOWN") ((current_option < 4)) && ((current_option++)) ;;
"DOWN") ((current_option < 5)) && ((current_option++)) ;;
"ENTER"|"$current_option")
show_cursor
case $current_option in
@@ -268,20 +272,22 @@ interactive_main_menu() {
exec "$SCRIPT_DIR/bin/clean.sh"
;;
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
3) clear; show_help; exit 0 ;;
4) cleanup_and_exit ;;
3) exec "$SCRIPT_DIR/bin/analyze.sh" ;;
4) clear; show_help; exit 0 ;;
5) cleanup_and_exit ;;
esac
;;
"QUIT") cleanup_and_exit ;;
[1-4])
[1-5])
show_cursor
case $key in
1)
exec "$SCRIPT_DIR/bin/clean.sh"
;;
2) exec "$SCRIPT_DIR/bin/uninstall.sh" ;;
3) clear; show_help; exit 0 ;;
4) cleanup_and_exit ;;
3) exec "$SCRIPT_DIR/bin/analyze.sh" ;;
4) clear; show_help; exit 0 ;;
5) cleanup_and_exit ;;
esac
;;
esac
@@ -296,6 +302,9 @@ main() {
"uninstall")
exec "$SCRIPT_DIR/bin/uninstall.sh"
;;
"analyze")
exec "$SCRIPT_DIR/bin/analyze.sh" "${@:2}"
;;
"update")
update_mole
exit 0