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

no longer land in a meaningless Volumes

This commit is contained in:
Tw93
2025-11-18 10:08:30 +08:00
parent a3d925f1f1
commit 4a7f6eac2f
3 changed files with 74 additions and 47 deletions

Binary file not shown.

View File

@@ -21,8 +21,8 @@ import (
"syscall" "syscall"
"time" "time"
tea "github.com/charmbracelet/bubbletea"
"github.com/cespare/xxhash/v2" "github.com/cespare/xxhash/v2"
tea "github.com/charmbracelet/bubbletea"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
) )
@@ -444,14 +444,41 @@ func createOverviewEntries() []dirEntry {
dirEntry{name: "System Library", path: "/Library", isDir: true, size: -1}, dirEntry{name: "System Library", path: "/Library", isDir: true, size: -1},
) )
// Add Volumes if exists // Add Volumes shortcut only when it contains real mounted folders (e.g., external disks)
if _, err := os.Stat("/Volumes"); err == nil { if hasUsefulVolumeMounts("/Volumes") {
entries = append(entries, dirEntry{name: "Volumes", path: "/Volumes", isDir: true, size: -1}) entries = append(entries, dirEntry{name: "Volumes", path: "/Volumes", isDir: true, size: -1})
} }
return entries return entries
} }
func hasUsefulVolumeMounts(path string) bool {
entries, err := os.ReadDir(path)
if err != nil {
return false
}
for _, entry := range entries {
name := entry.Name()
// Skip hidden control entries for Spotlight/TimeMachine etc.
if strings.HasPrefix(name, ".") {
continue
}
info, err := os.Lstat(filepath.Join(path, name))
if err != nil {
continue
}
if info.Mode()&fs.ModeSymlink != 0 {
continue // Ignore the synthetic MacintoshHD link
}
if info.IsDir() {
return true
}
}
return false
}
func (m *model) hydrateOverviewEntries() { func (m *model) hydrateOverviewEntries() {
m.entries = createOverviewEntries() m.entries = createOverviewEntries()
if m.overviewSizeCache == nil { if m.overviewSizeCache == nil {
@@ -1760,7 +1787,7 @@ func truncateMiddle(s string, maxWidth int) string {
headIdx := 0 headIdx := 0
for i, r := range runes { for i, r := range runes {
w := runeWidth(r) w := runeWidth(r)
if headWidth + w > targetHeadWidth { if headWidth+w > targetHeadWidth {
break break
} }
headWidth += w headWidth += w
@@ -1772,7 +1799,7 @@ func truncateMiddle(s string, maxWidth int) string {
tailIdx := len(runes) tailIdx := len(runes)
for i := len(runes) - 1; i >= 0; i-- { for i := len(runes) - 1; i >= 0; i-- {
w := runeWidth(runes[i]) w := runeWidth(runes[i])
if tailWidth + w > targetTailWidth { if tailWidth+w > targetTailWidth {
break break
} }
tailWidth += w tailWidth += w

2
mole
View File

@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh" source "$SCRIPT_DIR/lib/common.sh"
# Version info # Version info
VERSION="1.9.11" VERSION="1.9.12"
MOLE_TAGLINE="can dig deep to clean your Mac." MOLE_TAGLINE="can dig deep to clean your Mac."
# Get latest version from remote repository # Get latest version from remote repository