Skip to content

Commit 8301628

Browse files
--set-keyless option
1 parent f9562d7 commit 8301628

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

completions/bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ __fastfetch_completion()
156156
"-s"
157157
"--structure"
158158
"--set"
159+
"--set-keyless"
159160
"--gl"
160161
"--os-format"
161162
"--os-key"

src/common/printing.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
55
{
66
ffLogoPrintLine(instance);
77

8+
//This is used by --set-keyless, in this case we wan't neither the module name nor the separator
9+
if(moduleName == NULL)
10+
return;
11+
812
if(!instance->config.pipe)
913
{
1014
fputs(FASTFETCH_TEXT_MODIFIER_RESET FASTFETCH_TEXT_MODIFIER_BOLT, stdout);

src/data/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Display options:
4343
-c,--color <color>: sets the color of the keys. Must be a linux console color code or the name of a color (+)
4444
--separator <str>: sets the separator between key and value. Default is a colon with a space
4545
--set <key=value>: hard set the value of a key
46+
--set-keyless <key=value>: hard set the value of a key, but don't print the key or the separator
4647
--show-errors <?value>: print occuring errors
4748
--disable-linewrap <?value>: weather to disable linewrap during the run
4849
--hide-cursor <?value>: weather to hide the cursor during the run

src/fastfetch.c

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
// Things only needed by fastfetch
1212
typedef struct FFdata
1313
{
14-
FFvaluestore valuestore;
14+
FFvaluestore customWithKey; //Prints with key
15+
FFvaluestore customKeyless; //Prints without
1516
FFstrbuf structure;
1617
bool loadUserConfig;
1718
} FFdata;
@@ -668,6 +669,27 @@ static uint32_t optionParseUInt32(const char* key, const char* value)
668669
return num;
669670
}
670671

672+
static void optionParseCustom(const char* key, const char* value, FFvaluestore* valuestore)
673+
{
674+
if(value == NULL)
675+
{
676+
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
677+
exit(411);
678+
}
679+
680+
char* separator = strchr(value, '=');
681+
682+
if(separator == NULL)
683+
{
684+
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
685+
exit(412);
686+
}
687+
688+
*separator = '\0';
689+
690+
ffValuestoreSet(valuestore, value, separator + 1);
691+
}
692+
671693
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value)
672694
{
673695
///////////////////////
@@ -879,25 +901,9 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
879901
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
880902
optionParseColor(key, value, &instance->config.mainColor);
881903
else if(strcasecmp(key, "--set") == 0)
882-
{
883-
if(value == NULL)
884-
{
885-
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
886-
exit(411);
887-
}
888-
889-
char* separator = strchr(value, '=');
890-
891-
if(separator == NULL)
892-
{
893-
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
894-
exit(412);
895-
}
896-
897-
*separator = '\0';
898-
899-
ffValuestoreSet(&data->valuestore, value, separator + 1);
900-
}
904+
optionParseCustom(key, value, &data->customWithKey);
905+
else if(strcasecmp(key, "--set-keyless") == 0)
906+
optionParseCustom(key, value, &data->customKeyless);
901907

902908
////////////////////////////////
903909
//Format + Key + Error options//
@@ -1279,13 +1285,20 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c
12791285

12801286
static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line)
12811287
{
1282-
const char* setValue = ffValuestoreGet(&data->valuestore, line);
1288+
const char* setValue = ffValuestoreGet(&data->customWithKey, line);
12831289
if(setValue != NULL)
12841290
{
12851291
ffPrintCustom(instance, line, setValue);
12861292
return;
12871293
}
12881294

1295+
setValue = ffValuestoreGet(&data->customKeyless, line);
1296+
if(setValue != NULL)
1297+
{
1298+
ffPrintCustom(instance, NULL, setValue);
1299+
return;
1300+
}
1301+
12891302
if(strcasecmp(line, "break") == 0)
12901303
ffPrintBreak(instance);
12911304
else if(strcasecmp(line, "title") == 0)
@@ -1373,7 +1386,8 @@ int main(int argc, const char** argv)
13731386

13741387
//Data stores things only needed for the configuration of fastfetch
13751388
FFdata data;
1376-
ffValuestoreInit(&data.valuestore);
1389+
ffValuestoreInit(&data.customWithKey);
1390+
ffValuestoreInit(&data.customKeyless);
13771391
ffStrbufInitA(&data.structure, 256);
13781392
data.loadUserConfig = true;
13791393

0 commit comments

Comments
 (0)