Disk: add --disk-hide-fs

Fix #1762
This commit is contained in:
Carter Li
2025-05-21 16:40:42 +08:00
parent d439ce8eb5
commit a0f579072f
8 changed files with 93 additions and 10 deletions
+4
View File
@@ -1758,6 +1758,10 @@
"type": "string",
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output\nDefault: /efi:/boot:/boot/efi"
},
"hideFS": {
"type": "string",
"description": "A colon separated file systems to hide from the disk output"
},
"showExternal": {
"type": "boolean",
"description": "Set if external volume should be printed",
+9 -1
View File
@@ -845,7 +845,15 @@
"desc": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output",
"arg": {
"type": "path",
"default": "Auto detection using mount-points"
"default": "/efi:/boot:/boot/efi"
}
},
{
"long": "disk-hide-fs",
"desc": "A colon separated list of file systems to hide from the disk output",
"arg": {
"type": "string",
"default": ""
}
},
{
-9
View File
@@ -54,14 +54,5 @@ const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
}
}
if (options->hideFolders.length)
{
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
{
if (ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
disk->type |= FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
}
}
return NULL;
}
+25
View File
@@ -179,6 +179,12 @@ void ffPrintDisk(FFDiskOptions* options)
if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes))
continue;
if (options->hideFolders.length && ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
continue;
if (options->hideFS.length && ffStrbufMatchSeparated(&disk->filesystem, &options->hideFS, ':'))
continue;
printDisk(options, disk, ++index);
}
}
@@ -211,6 +217,12 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch
return true;
}
if (ffStrEqualsIgnCase(subKey, "hide-fs"))
{
ffOptionParseString(key, value, &options->hideFS);
return true;
}
if (ffStrEqualsIgnCase(subKey, "show-regular"))
{
if (ffOptionParseBoolean(value))
@@ -305,6 +317,12 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "hideFS"))
{
ffStrbufSetS(&options->hideFS, yyjson_get_str(val));
continue;
}
if (ffStrEqualsIgnCase(key, "showExternal"))
{
if (yyjson_get_bool(val))
@@ -397,6 +415,9 @@ void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso
if (!ffStrbufEqual(&options->hideFolders, &defaultOptions.hideFolders))
yyjson_mut_obj_add_strbuf(doc, module, "hideFolders", &options->hideFolders);
if (!ffStrbufEqual(&options->hideFS, &defaultOptions.hideFS))
yyjson_mut_obj_add_strbuf(doc, module, "hideFS", &options->hideFS);
if (defaultOptions.calcType != options->calcType)
yyjson_mut_obj_add_bool(doc, module, "useAvailable", options->calcType == FF_DISK_CALC_TYPE_AVAILABLE);
@@ -516,6 +537,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
#else
ffStrbufInitStatic(&options->hideFolders, "/efi:/boot:/boot/efi");
#endif
ffStrbufInit(&options->hideFS);
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;
options->calcType = FF_DISK_CALC_TYPE_FREE;
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
@@ -524,4 +546,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
void ffDestroyDiskOptions(FFDiskOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
ffStrbufDestroy(&options->folders);
ffStrbufDestroy(&options->hideFolders);
ffStrbufDestroy(&options->hideFS);
}
+1
View File
@@ -30,6 +30,7 @@ typedef struct FFDiskOptions
FFstrbuf folders;
FFstrbuf hideFolders;
FFstrbuf hideFS;
FFDiskVolumeType showTypes;
FFDiskCalcType calcType;
FFPercentageModuleConfig percent;
+29
View File
@@ -607,3 +607,32 @@ bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf)
return changed;
}
/// @brief Check if a separated string contains a substring.
/// @param strbuf The substring to check.
/// @param compLength The length of the separated string to check.
/// @param comp The separated string to check.
/// @param separator The separator character.
bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator)
{
if (strbuf->length == 0)
return true;
if (compLength == 0)
return false;
for (const char* p = comp; p < comp + compLength;)
{
const char* colon = memchr(p, separator, compLength);
if (colon == NULL)
return strcmp(strbuf->chars, p) == 0;
uint32_t substrLength = (uint32_t) (colon - p);
if (strbuf->length == substrLength && memcmp(strbuf->chars, p, substrLength) == 0)
return true;
p = colon + 1;
}
return false;
}
+11
View File
@@ -92,6 +92,7 @@ void ffStrbufLowerCase(FFstrbuf* strbuf);
bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer);
void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer);
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf);
bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const char* comp, char separator);
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)
{
@@ -506,4 +507,14 @@ static inline void ffStrbufTrim(FFstrbuf* strbuf, char c)
ffStrbufTrimLeft(strbuf, c);
}
static inline bool ffStrbufMatchSeparatedS(const FFstrbuf* strbuf, const char* comp, char separator)
{
return ffStrbufMatchSeparatedNS(strbuf, (uint32_t) strlen(comp), comp, separator);
}
static inline bool ffStrbufMatchSeparated(const FFstrbuf* strbuf, const FFstrbuf* comp, char separator)
{
return ffStrbufMatchSeparatedNS(strbuf, comp->length, comp->chars, separator);
}
#define FF_STRBUF_AUTO_DESTROY FFstrbuf __attribute__((__cleanup__(ffStrbufDestroy)))
+14
View File
@@ -635,6 +635,20 @@ int main(void)
VERIFY(ffStrbufEqualS(&newStr, ""));
}
{
ffStrbufSetStatic(&strbuf, "abc");
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc:def:ghi", ' ') == false);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc:def:ghi", ':') == true);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "def:ghi", ' ') == false);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "def:ghi", ':') == false);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "def", ':') == false);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc", ':') == true);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "", ' ') == false);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, ":abc:", ':') == true);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, "abc:", ':') == true);
VERIFY(ffStrbufMatchSeparatedS(&strbuf, ":abc", ':') == true);
}
//Success
puts("\e[32mAll tests passed!" FASTFETCH_TEXT_MODIFIER_RESET);
}