From f324794f54c4f3de17741515e781ddd27751a42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Sep 2022 16:20:51 +0800 Subject: [PATCH] LocalIp: add option `--localip-name-prefix` eg: --localip-name-prefix en --- completions/bash | 1 + src/common/init.c | 1 + src/data/help.txt | 1 + src/fastfetch.c | 2 ++ src/fastfetch.h | 1 + src/modules/localip.c | 3 +++ 6 files changed, 9 insertions(+) diff --git a/completions/bash b/completions/bash index bdcd67f83..11313cc65 100644 --- a/completions/bash +++ b/completions/bash @@ -184,6 +184,7 @@ __fastfetch_completion() "--localip-show-ipv4" "--localip-show-ipv6" "--localip-show-loop" + "--localip-name-prefix" "--escape-bedrock" "--pipe" "--title-fqdn" diff --git a/src/common/init.c b/src/common/init.c index 2f8a4146c..322e661c9 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -238,6 +238,7 @@ static void defaultConfig(FFinstance* instance) instance->config.localIpShowIpV4 = true; instance->config.localIpShowIpV6 = false; instance->config.localIpShowLoop = false; + ffStrbufInit(&instance->config.localIpNamePrefix); instance->config.publicIpTimeout = 0; diff --git a/src/data/help.txt b/src/data/help.txt index cd5d8d99a..59bf40e31 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -101,6 +101,7 @@ Module specific options: --localip-show-ipv4 : Show ipv4 addresses in local ip module. Default is true --localip-show-ipv6 : Show ipv6 addresses in local ip module. Default is false --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false + --localip-name-prefix : Show ips with given name prefix only. Default is empty --public-ip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0) --player-name: The name of the player to use --gl : Sets the opengl context creation library to use. Must be auto, egl, glx or osmesa. Default is auto diff --git a/src/fastfetch.c b/src/fastfetch.c index 1f021d05e..cbf56a96e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1277,6 +1277,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con instance->config.localIpShowIpV6 = optionParseBoolean(value); else if(strcasecmp(key, "--localip-show-loop") == 0) instance->config.localIpShowLoop = optionParseBoolean(value); + else if(strcasecmp(key, "--localip-name-prefix") == 0) + optionParseString(key, value, &instance->config.localIpNamePrefix); else if(strcasecmp(key, "--os-file") == 0) optionParseString(key, value, &instance->config.osFile); else if(strcasecmp(key, "--player-name") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index 6665b3bc8..a8178453d 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -170,6 +170,7 @@ typedef struct FFconfig bool localIpShowLoop; bool localIpShowIpV4; bool localIpShowIpV6; + FFstrbuf localIpNamePrefix; uint32_t publicIpTimeout; diff --git a/src/modules/localip.c b/src/modules/localip.c index 0976579a1..9308d246a 100644 --- a/src/modules/localip.c +++ b/src/modules/localip.c @@ -62,6 +62,9 @@ void ffPrintLocalIp(FFinstance* instance) if (strncmp(ifa->ifa_name, "lo", 2) == 0 && (ifa->ifa_name[2] == '\0' || isdigit(ifa->ifa_name[2])) && !instance->config.localIpShowLoop) continue; + if (instance->config.localIpNamePrefix.length && strncmp(ifa->ifa_name, instance->config.localIpNamePrefix.chars, instance->config.localIpNamePrefix.length) != 0) + continue; + if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4 // is a valid IP4 Address if (!instance->config.localIpShowIpV4)