diff --git a/completions/fish b/completions/fish new file mode 100755 index 000000000..3a8b833fc --- /dev/null +++ b/completions/fish @@ -0,0 +1,53 @@ +#!/usr/bin/env fish + +set -l whole_text (fastfetch --pipe --help) +set -l modules (string lower (string sub -s 5 (fastfetch --list-modules))) + +complete -c fastfetch -f + +for line in (string match -- ' -*' $whole_text) + set -l kv (string split -n ':' $line -m1) + set -l args (string trim -- $kv[1]) + set -l desc (string trim -- $kv[2]) + + set -l res -c fastfetch + + switch (string match -r -- '<\??\w+>' $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" + case '<\?bool>' + set res $res -x -a "true\tBool false\tBool" + case '' + set res $res -F -r + case '' + if string match -q -- '*--config*' $args + set -l presets (fastfetch --list-presets false)"\tPreset" + set res $res -r -a "$presets" + else + set res $res -F -r + end + case '' + set res $res -x -a "0\tNumber 1\tNumber 2\tNumber 3\tNumber 4\tNumber 5\tNumber 6\tNumber 7\tNumber 8\tNumber 9\tNumber" + case '<\?num>' + set res $res -x -a "0\tNumber 1\tNumber 2\tNumber 3\tNumber 4\tNumber 5\tNumber 6\tNumber 7\tNumber 8\tNumber 9\tNumber" + case '' + set temp $modules"\tModule" + set res $res -x -a "$temp" + case '' + set res $res -x -a "none\tNone small\tSmall" + case '<*>' + set res $res -x + end + + set args (string trim -- (string split -- ',' (string replace -r -- '<\??\w+>' '' $args))) + + for arg in $args + if string match -q -- '--*' $arg + set res $res -l (string sub -s 3 -- $arg) + else + set res $res -o (string sub -s 2 -- $arg) + end + end + complete $res -d (string replace -- ' (+)' '' $desc) +end diff --git a/src/common/io/io.h b/src/common/io/io.h index f25381e51..0ea5cf411 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -99,7 +99,7 @@ static inline void ffUnsuppressIO(bool* suppressed) #define FF_SUPPRESS_IO() bool __attribute__((__cleanup__(ffUnsuppressIO), __unused__)) io_suppressed__ = ffSuppressIO(true) -void ffListFilesRecursively(const char* path); +void ffListFilesRecursively(const char* path, bool pretty); static inline bool wrapClose(FFNativeFD* pfd) { diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index db5f3c65b..018af9fa7 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -199,7 +199,7 @@ bool ffSuppressIO(bool suppress) return true; } -void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* folderName) +void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indentation, const char* folderName, bool pretty) { DIR* dir = opendir(folder->chars); if(dir == NULL) @@ -207,8 +207,12 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol uint32_t folderLength = folder->length; - if(folderName != NULL) + if(pretty && folderName != NULL) + { + for(uint8_t i = 0; i < indentation - 1; i++) + fputs(" | ", stdout); printf("%s/\n", folderName); + } struct dirent* entry; @@ -221,13 +225,20 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol ffStrbufAppendS(folder, entry->d_name); ffStrbufAppendC(folder, '/'); - listFilesRecursively(folder, (uint8_t) (indentation + 1), entry->d_name); + listFilesRecursively(baseLength, folder, (uint8_t) (indentation + 1), entry->d_name, pretty); ffStrbufSubstrBefore(folder, folderLength); continue; } - for(uint8_t i = 0; i < indentation; i++) - fputs(" | ", stdout); + if (pretty) + { + for(uint8_t i = 0; i < indentation; i++) + fputs(" | ", stdout); + } + else + { + fputs(folder->chars + baseLength, stdout); + } puts(entry->d_name); } @@ -235,9 +246,9 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol closedir(dir); } -void ffListFilesRecursively(const char* path) +void ffListFilesRecursively(const char* path, bool pretty) { FF_STRBUF_AUTO_DESTROY folder = ffStrbufCreateS(path); ffStrbufEnsureEndsWithC(&folder, '/'); - listFilesRecursively(&folder, 0, NULL); + listFilesRecursively(folder.length, &folder, 0, NULL, pretty); } diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index c4c26145b..1917bc3ed 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -114,16 +114,21 @@ bool ffSuppressIO(bool suppress) return false; } -void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* folderName) +void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indentation, const char* folderName, bool pretty) { uint32_t folderLength = folder->length; - if(folderName != NULL) + if(pretty && folderName != NULL) + { + for(uint8_t i = 0; i < indentation - 1; i++) + fputs(" | ", stdout); printf("%s/\n", folderName); + } ffStrbufAppendC(folder, '*'); WIN32_FIND_DATAA entry; HANDLE hFind = FindFirstFileA(folder->chars, &entry); + ffStrbufTrimRight(folder, '*'); if(hFind == INVALID_HANDLE_VALUE) return; @@ -137,24 +142,31 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol ffStrbufSubstrBefore(folder, folderLength); ffStrbufAppendS(folder, entry.cFileName); ffStrbufAppendC(folder, '/'); - listFilesRecursively(folder, (uint8_t) (indentation + 1), entry.cFileName); + listFilesRecursively(baseLength, folder, (uint8_t) (indentation + 1), entry.cFileName, pretty); ffStrbufSubstrBefore(folder, folderLength); continue; } - for(uint8_t i = 0; i < indentation; i++) - fputs(" | ", stdout); + if (pretty) + { + for(uint8_t i = 0; i < indentation; i++) + fputs(" | ", stdout); + } + else + { + fputs(folder->chars + baseLength, stdout); + } puts(entry.cFileName); } while (FindNextFileA(hFind, &entry)); FindClose(hFind); } -void ffListFilesRecursively(const char* path) +void ffListFilesRecursively(const char* path, bool pretty) { FF_STRBUF_AUTO_DESTROY folder = ffStrbufCreateS(path); ffStrbufEnsureEndsWithC(&folder, '/'); - listFilesRecursively(&folder, 0, NULL); + listFilesRecursively(folder.length, &folder, 0, NULL, pretty); } const char* ffGetTerminalResponse(const char* request, const char* format, ...) diff --git a/src/data/help.txt b/src/data/help.txt index 0c4aa46c4..bc2682db1 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -3,8 +3,7 @@ Fastfetch is a neofetch-like tool for fetching system information and displaying Usage: fastfetch Informative options: - -h, --help: Show this message - -h, --help : Show help for a specific command + -h, --help : Show this message, or help for a specific command -v, --version: Show the version of fastfetch --list-config-paths: List search paths of config files --list-data-paths: List search paths of presets and logos @@ -18,31 +17,31 @@ Informative options: --print-structure: Print the default structure Config options: - -c, --load-config : Load a config file or preset (+) + -c, --config : Load a config file or preset (+) --gen-config : Generate a config file (or print the file if is `-`), with options specified in the command line (if any) --gen-config-force : Generate a config file. Overwrite the existing one General options: - --thread : Use separate threads to send HTTP requests - --escape-bedrock : On Bedrock Linux, whether to escape the bedrock jail + --thread : Use separate threads to send HTTP requests + --escape-bedrock : On Bedrock Linux, whether to escape the bedrock jail --wmi-timeout : Set the timeout (ms) for WMI queries. Windows only. Default is 5000 --processing-timeout : Set the timeout (ms) when waiting for child processes. Default is 1000 - --ds-force-drm : Set if only DRM should be used to detect displays. Default is false. Linux only + --ds-force-drm : Set if only DRM should be used to detect displays. Default is false. Linux only Logo options: -l, --logo : Set the logo; if default, the name of a builtin logo or a path to a file --logo-type : Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty, iterm or chafa --logo-width : Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol --logo-height : Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol - --logo-preserve-aspect-ratio : Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol + --logo-preserve-aspect-ratio : Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol --logo-color-[1-9] : Overwrite a color in the logo - --logo-padding : Set the padding on the left and the right of the logo - --logo-padding-left : Set the padding on the left of the logo - --logo-padding-right : Set the padding on the right of the logo - --logo-padding-top : Set the padding on the top of the logo - --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display - --logo-separate : If true, print modules at bottom of the logo - --logo-recache : If true, regenerate image logo cache + --logo-padding : Set the padding on the left and the right of the logo + --logo-padding-left : Set the padding on the left of the logo + --logo-padding-right : Set the padding on the right of the logo + --logo-padding-top : Set the padding on the top of the logo + --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display + --logo-separate : If true, print modules at bottom of the logo + --logo-recache : If true, regenerate image logo cache --file : Short for --logo-type file --logo --file-raw : Short for --logo-type file-raw --logo --data : Short for --logo-type data --logo @@ -51,36 +50,36 @@ Logo options: --kitty : Short for --logo-type kitty --logo --iterm : Short for --logo-type iterm --logo --chafa : Short for --logo-type chafa --logo - --chafa-fg-only : Produce character-cell output using foreground colors only. See chafa document for detail + --chafa-fg-only : Produce character-cell output using foreground colors only. See chafa document for detail --chafa-symbols : Specify character symbols to employ in final output. See chafa document for detail - --chafa-canvas-mode : Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail + --chafa-canvas-mode : Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail --chafa-color-space : Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail - --chafa-dither-mode : Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail + --chafa-dither-mode : Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail Display options: - -s,--structure : Set the structure of the fetch. Must be a colon separated list of keys. Use `fastfetch --list-modules` to see the ones available. - --stat : Show time usage (in ms) for individual modules - --pipe : Disable logo and all escape sequences + -s, --structure : Set the structure of the fetch. Must be a colon separated list of keys. Use `fastfetch --list-modules` to see the ones available. + --stat : Show time usage (in ms) for individual modules + --pipe : Disable logo and all escape sequences --color-keys : Set the color of the keys --color-title : Set the color of the title --color : Set the color of both the keys and title --key-width : Align the width of keys to characters - --bright-color : Set if the keys, title and ASCII logo should be printed in bright color. Default is true + --bright-color : Set if the keys, title and ASCII logo should be printed in bright color. Default is true --separator : Set the separator between key and value. Default is a colon with a space --set : Hard set the value of a key --set-keyless : Hard set the value of a key, but don't print the key or the separator - --show-errors : Print occurring errors - --disable-linewrap : Whether to disable line wrap during the run - --hide-cursor : Whether to hide the cursor during the run + --show-errors : Print occurring errors + --disable-linewrap : Whether to disable line wrap during the run + --hide-cursor : Whether to hide the cursor during the run --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 9 - --percent-ndigits : Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0 + --percent-ndigits : Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0 --bar-char-elapsed : Set the character to use in elapsed part. Default is '■' --bar-char-total : Set the character to use in total part. Default is '-' --bar-width : Set the width of the bar, in number of characters. Default is 10 - --bar-border : Whether to show a border around the bar. Default is true - --no-buffer : Set if the stdout application buffer should be disabled. Default is false - --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes + --bar-border : Whether to show a border around the bar. Default is true + --no-buffer : Set if the stdout application buffer should be disabled. Default is false + --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes --size-max-prefix : Set the largest binary prefix to use when formatting sizes. Default is YB --temperature-unit : Set the unit of the temperature. Must be one of C, F and K. Default is C @@ -122,62 +121,62 @@ Library options: Set the path of a library to load --lib-ddcutil : Used for brightness detection of external displays Module specific options: - --title-fqdn : Set if the title should use fully qualified domain name. Default is false + --title-fqdn : Set if the title should use fully qualified domain name. Default is false --title-color-user : Set color of the user name (left part). Default is empty (use color of `--color-title`). --title-color-at : Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`) --title-color-host : Set color of the host name (right part). Default is empty (use color of `--color-title`) - --chassis-use-wmi : Set if WMI query should be used on Windows, which detects more information but slower. Default is false + --chassis-use-wmi : Set if WMI query should be used on Windows, which detects more information but slower. Default is false --separator-string : Set the string printed by the separator module --os-file : Set the path to the file containing OS information. Linux only --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) - --disk-show-regular : Set if regular volume should be printed. Default is true - --disk-show-external : Set if external volume should be printed. Default is true - --disk-show-hidden : Set if hidden volumes should be printed. Default is false - --disk-show-subvolumes : Set if subvolumes should be printed. Default is false - --disk-show-readonly : Set if read only volumes should be printed. Default is false - --disk-show-unknown : Set if unknown (unable to detect sizes) volumes should be printed. Default is false - --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false + --disk-show-regular : Set if regular volume should be printed. Default is true + --disk-show-external : Set if external volume should be printed. Default is true + --disk-show-hidden : Set if hidden volumes should be printed. Default is false + --disk-show-subvolumes : Set if subvolumes should be printed. Default is false + --disk-show-readonly : Set if read only volumes should be printed. Default is false + --disk-show-unknown : Set if unknown (unable to detect sizes) volumes should be printed. Default is false + --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false --diskio-name-prefix : Show disks with given name prefix only. Default is empty - --bluetooth-show-disconnected : Set if disconnected bluetooth devices should be printed. Default is false - --packages-winget : Set if winget package count should be detected. Default is false + --bluetooth-show-disconnected : Set if disconnected bluetooth devices should be printed. Default is false + --packages-winget : Set if winget package count should be detected. Default is false --display-compact-type : Set if all displays should be printed in one line. Default is none - --display-detect-name : Set if display name should be detected and printed (if supported). Default is false - --display-precise-refresh-rate : Set if decimal refresh rates should not be rounded into integers when printing. Default is true + --display-detect-name : Set if display name should be detected and printed (if supported). Default is false + --display-precise-refresh-rate : Set if decimal refresh rates should not be rounded into integers when printing. Default is true --brightness-ddcci-sleep : Set the sleep times (in ms) when sending DDC/CI requests. See for detail. Default is 10 --sound-type : Set what type of sound devices should be printed. Should be either main, active or all. Default is main --battery-dir : The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only - --battery-use-setup-api : Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only - --cpu-temp : Detect and display CPU temperature if supported. Default is false + --battery-use-setup-api : Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only + --cpu-temp : Detect and display CPU temperature if supported. Default is false --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 - --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false - --de-slow-version-detection : Set if DE version should be detected with slow operations. Default is false - --gpu-temp : Detect and display GPU temperature if supported. Default is false - --gpu-use-nvml : Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false - --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false - --gpu-hide-type : Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none - --battery-temp : Detect and display Battery temperature if supported. Default is false - --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-mac : Show mac 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 + --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false + --de-slow-version-detection : Set if DE version should be detected with slow operations. Default is false + --gpu-temp : Detect and display GPU temperature if supported. Default is false + --gpu-use-nvml : Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false + --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false + --gpu-hide-type : Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none + --battery-temp : Detect and display Battery temperature if supported. Default is false + --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-mac : Show mac 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 interfaces with given interface name prefix only. Default is empty - --localip-default-route-only : Show the interface that is used for default routing only. Default is true on non-android platforms - --localip-compact : Show all IPs in one line. Default is false + --localip-default-route-only : Show the interface that is used for default routing only. Default is true on non-android platforms + --localip-compact : Show all IPs in one line. Default is false --netio-name-prefix : Show interfaces with given name prefix only. Default is empty - --netio-default-route-only : Show the interfac that is used for default routing only. Default is true on non-android platforms + --netio-default-route-only : Show the interfac that is used for default routing only. Default is true on non-android platforms --publicip-timeout : Time in milliseconds to wait for the public ip server to respond. Default is disabled (0) --publicip-url : The URL of public IP detection server to be used. --weather-location : Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). --weather-timeout : Time in milliseconds to wait for the weather server to respond. Default is disabled (0) --weather-output-format : The output weather format to be used. It must be URI encoded. - --wm-detect-plugin : Set if window manager plugin should be detected on supported platforms. Default is false + --wm-detect-plugin : Set if window manager plugin should be detected on supported platforms. Default is false --player-name : The name of the player to use for module Media and Player. Linux only --opengl-library : Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto --command-shell : Set the shell program to execute the command text. Default is cmd for Windows, /bin/sh for *nix --command-key : Set the module key to display --command-text : Set the command text to be executed --colors-symbol : Set the symbol to be printed by Colors module. Default is block - --colors-padding-left : Set the number of white spaces to print before the symbol. Default is 0 + --colors-padding-left : Set the number of white spaces to print before the symbol. Default is 0 Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci" If a value starts with a ?, it is optional. "true" will be used if not set. diff --git a/src/fastfetch.c b/src/fastfetch.c index 89ee82491..103f0b109 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -19,8 +19,6 @@ #include "util/windows/getline.h" #endif -#include "modules/modules.h" - static void printCommandFormatHelp(const char* command) { FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command); @@ -139,12 +137,12 @@ static void printCommandHelp(const char* command) fprintf(stderr, "Error: No specific help for command '%s' provided\n", command); } -static void listAvailablePresets(void) +static void listAvailablePresets(bool pretty) { FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs) { ffStrbufAppendS(path, "fastfetch/presets/"); - ffListFilesRecursively(path->chars); + ffListFilesRecursively(path->chars, pretty); } } @@ -153,7 +151,7 @@ static void listAvailableLogos(void) FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs) { ffStrbufAppendS(path, "fastfetch/logos/"); - ffListFilesRecursively(path->chars); + ffListFilesRecursively(path->chars, true); } } @@ -453,7 +451,7 @@ static void parseCommand(FFdata* data, char* key, char* value) if(ffStrEqualsIgnCase(subkey, "modules")) listModules(); else if(ffStrEqualsIgnCase(subkey, "presets")) - listAvailablePresets(); + listAvailablePresets(ffOptionParseBoolean(value)); else if(ffStrEqualsIgnCase(subkey, "config-paths")) listConfigPaths(); else if(ffStrEqualsIgnCase(subkey, "data-paths"))