mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Improve partitions module
This commit is contained in:
+14
-3
@@ -262,9 +262,10 @@ func initializeModuleMap() {
|
|||||||
RegisterModule(memoryModule)
|
RegisterModule(memoryModule)
|
||||||
|
|
||||||
// Partitions module
|
// Partitions module
|
||||||
partitionsModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "partitions", Format: "%3Partition $PART_AUTONAME: %4$PART_USED / $PART_TOTAL"}, Execute: func(sm StormfetchModule) string {
|
partitionsModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "partitions", Format: "%3Partition ${PART_AUTONAME} (${PART_FS}): %4${PART_USED} / ${PART_TOTAL}"}, Execute: func(sm StormfetchModule) string {
|
||||||
hiddenPartitionsInterface, _ := sm.GetData("hidden_partitions", make([]any, 0))
|
hiddenPartitionsInterface, _ := sm.GetData("hidden_partitions", make([]any, 0))
|
||||||
hiddenFilesystemsInterface, _ := sm.GetData("hidden_filesystems", make([]any, 0))
|
hiddenFilesystemsInterface, _ := sm.GetData("hidden_filesystems", make([]any, 0))
|
||||||
|
alternativeNamesInterface, _ := sm.GetData("alternative_names", make(map[string]any, 0))
|
||||||
|
|
||||||
// Convert interface slices to string slices
|
// Convert interface slices to string slices
|
||||||
hiddenPartitions := make([]string, 0)
|
hiddenPartitions := make([]string, 0)
|
||||||
@@ -276,12 +277,22 @@ func initializeModuleMap() {
|
|||||||
hiddenFilesystems = append(hiddenFilesystems, value.(string))
|
hiddenFilesystems = append(hiddenFilesystems, value.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert interface map to map[string]string
|
||||||
|
alternativeNames := make(map[string]string)
|
||||||
|
for key, value := range alternativeNamesInterface.(map[string]any) {
|
||||||
|
alternativeNames[key] = value.(string)
|
||||||
|
}
|
||||||
|
|
||||||
builder := strings.Builder{}
|
builder := strings.Builder{}
|
||||||
partitions := GetMountedPartitions(hiddenPartitions, hiddenFilesystems)
|
partitions := GetMountedPartitions(hiddenPartitions, hiddenFilesystems)
|
||||||
|
|
||||||
for i, partition := range partitions {
|
for i, partition := range partitions {
|
||||||
partitionAutoname := partition.Label
|
partitionAutoname := ""
|
||||||
if partitionAutoname == "" {
|
if altName, ok := alternativeNames[partition.Device]; ok {
|
||||||
|
partitionAutoname = altName
|
||||||
|
} else if partition.Label != "" {
|
||||||
|
partitionAutoname = partition.Label
|
||||||
|
} else {
|
||||||
partitionAutoname = partition.MountPoint
|
partitionAutoname = partition.MountPoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-7
@@ -72,14 +72,19 @@ func GetMountedPartitions(hiddenPartitions, hiddenFilesystems []string) []partit
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device, err := filepath.EvalSymlinks(fields[0])
|
||||||
|
if err != nil {
|
||||||
|
device = fields[0]
|
||||||
|
}
|
||||||
|
|
||||||
p := partition{
|
p := partition{
|
||||||
fields[0],
|
Device: device,
|
||||||
fields[1],
|
MountPoint: fields[1],
|
||||||
"",
|
Label: "",
|
||||||
fields[2],
|
FileystemType: fields[2],
|
||||||
0,
|
TotalSize: 0,
|
||||||
0,
|
UsedSize: 0,
|
||||||
0,
|
FreeSize: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip already added partitions
|
// Skip already added partitions
|
||||||
|
|||||||
Reference in New Issue
Block a user