Completion: tidy

This commit is contained in:
李通洲
2023-11-16 14:21:24 +08:00
parent 3f9462d7c8
commit f8ba138b8d
4 changed files with 42 additions and 22 deletions
+5 -5
View File
@@ -5,7 +5,7 @@ __fastfetch_complete_help()
local __ff_helps=(
"color"
"format"
"load-config"
"config"
"os-format"
"host-format"
"kernel-format"
@@ -66,7 +66,7 @@ __fastfetch_complete_path()
__fastfetch_complete_logo()
{
COMPREPLY=($(compgen -W "$(fastfetch --list-logos-autocompletion)" -- "$CURRENT_WORD"))
COMPREPLY=($(compgen -W "$(fastfetch --list-logos autocompletion)" -- "$CURRENT_WORD"))
}
__fastfetch_complete_logo_type()
@@ -218,10 +218,9 @@ __fastfetch_completion()
"--logo-color-6"
"--logo-color-7"
"--logo-color-8"
"--logo-color-9"
"--logo-width"
"--logo-height"
"--logo-color-9"
"-c"
"--color"
"--color-keys"
"--color-title"
@@ -360,7 +359,8 @@ __fastfetch_completion()
)
local FF_OPTIONS_PATH=(
"--load-config"
"-c"
"--config"
"--os-file"
"--lib-pci"
"--lib-vulkan"
+8 -6
View File
@@ -5,7 +5,7 @@ if not test -x fastfetch
end
set -l whole_text (fastfetch --pipe --help)
set -l modules (fastfetch --list-modules | string sub -s 5 | string lower)
set -l modules (fastfetch --list-modules autocompletion)
complete -c fastfetch -f
@@ -23,12 +23,13 @@ for line in (string match -- ' -*' $whole_text)
switch (string match -r -- $regexp $args)
case '<\?command>'
set -l modules_format $modules-format"\tModule_format"
set res $res -x -a "color\tSupported_colors format\tCustom_format config\tConfiguration $modules_format"
set -l temp (string lower $modules)
set -l temp $temp-format"\tModule\\ format"
set res $res -x -a "color\tSupported\\ colors format\tCustom\\ format config\tConfiguration $temp"
case '<\?bool>'
set res $res -x -a "true\tBool false\tBool"
case '<config>'
set -l presets (fastfetch --list-presets false)"\tPreset"
set -l presets (fastfetch --list-presets autocompletion)"\tPreset"
set res $res -r -a "$presets"
case '<path>'
set res $res -F -r
@@ -40,8 +41,9 @@ for line in (string match -- ' -*' $whole_text)
set temp $modules"\tModule"
set res $res -x -a "$temp"
case '<logo>'
set -l builtin_logos (fastfetch --list-logos-autocompletion)
set -l temp $builtin_logos"\tBuiltin"
set -l temp (fastfetch --list-logos autocompletion)
set -l temp (string replace -- ' ' '\\ ' $temp)
set -l temp $temp"\tBuiltin"
set res $res -x -a "none\tNone small\tSmall $temp"
case '<color>'
set res $res -x -a "black\tColor red\tColor green\tColor yellow\tColor blue\tColor magenta\tColor cyan\tColor white\tColor default\tColor"
+1 -1
View File
@@ -3,7 +3,7 @@ Usage: fastfetch --color <color>
<color> must be a color encoding as ANSI escape sequences. It is inserted between "ESC[" and "m".
Infos about them can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters.
Examples:
--color 35: sets the color to pink
--color 35: sets the color to magenta. `--color magenta` is also supported
--color 4;92: sets the color to bright Green with underline
--color 5;104: blinking text on a blue background
If no color is set, the main color of the logo will be used.
+28 -10
View File
@@ -183,7 +183,7 @@ static void listDataPaths(void)
}
}
static void listModules()
static void listModules(bool pretty)
{
unsigned count = 0;
for (int i = 0; i <= 'Z' - 'A'; ++i)
@@ -191,7 +191,10 @@ static void listModules()
for (FFModuleBaseInfo** modules = ffModuleInfos[i]; *modules; ++modules)
{
++count;
printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name);
if (pretty)
printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name);
else
puts((*modules)->name);
}
}
}
@@ -450,9 +453,9 @@ static void parseCommand(FFdata* data, char* key, char* value)
{
const char* subkey = key + strlen("--list-");
if(ffStrEqualsIgnCase(subkey, "modules"))
listModules();
listModules(!value || !ffStrEqualsIgnCase(value, "autocompletion"));
else if(ffStrEqualsIgnCase(subkey, "presets"))
listAvailablePresets(ffOptionParseBoolean(value));
listAvailablePresets(!value || !ffStrEqualsIgnCase(value, "autocompletion"));
else if(ffStrEqualsIgnCase(subkey, "config-paths"))
listConfigPaths();
else if(ffStrEqualsIgnCase(subkey, "data-paths"))
@@ -461,13 +464,28 @@ static void parseCommand(FFdata* data, char* key, char* value)
ffListFeatures();
else if(ffStrEqualsIgnCase(subkey, "logos"))
{
puts("Builtin logos:");
ffLogoBuiltinList();
puts("\nCustom logos:");
listAvailableLogos();
if (value)
{
if (ffStrEqualsIgnCase(value, "autocompletion"))
ffLogoBuiltinListAutocompletion();
else if (ffStrEqualsIgnCase(value, "builtin"))
ffLogoBuiltinList();
else if (ffStrEqualsIgnCase(value, "custom"))
listAvailableLogos();
else
{
fprintf(stderr, "Error: unsupported logo type: %s\n", value);
exit(415);
}
}
else
{
puts("Builtin logos:");
ffLogoBuiltinList();
puts("\nCustom logos:");
listAvailableLogos();
}
}
else if(ffStrEqualsIgnCase(subkey, "logos-autocompletion"))
ffLogoBuiltinListAutocompletion();
else
{
fprintf(stderr, "Error: unsupported list option: %s\n", key);