From 2a53b012ea487dd4569cf79ce4119c49feb48e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 14 Nov 2023 16:36:08 +0800 Subject: [PATCH] Completion (Fish): clean up --- completions/fish | 31 ++++++++++++++++++++----------- src/data/help.txt | 46 +++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/completions/fish b/completions/fish index 3a8b833fc..0c61e2500 100755 --- a/completions/fish +++ b/completions/fish @@ -1,7 +1,11 @@ #!/usr/bin/env fish +if not test -x fastfetch + return +end + set -l whole_text (fastfetch --pipe --help) -set -l modules (string lower (string sub -s 5 (fastfetch --list-modules))) +set -l modules (fastfetch --list-modules | string sub -s 5 | string lower) complete -c fastfetch -f @@ -10,23 +14,24 @@ for line in (string match -- ' -*' $whole_text) set -l args (string trim -- $kv[1]) set -l desc (string trim -- $kv[2]) - set -l res -c fastfetch + if string match -q -- '--<*' $args # ignore ---* + continue + end - switch (string match -r -- '<\??\w+>' $args) + set -l res -c fastfetch + set -l regexp '<\??[\w=]+>' + + 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" case '<\?bool>' set res $res -x -a "true\tBool false\tBool" + case '' + set -l presets (fastfetch --list-presets false)"\tPreset" + set res $res -r -a "$presets" 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>' @@ -36,11 +41,15 @@ for line in (string match -- ' -*' $whole_text) set res $res -x -a "$temp" case '' set res $res -x -a "none\tNone small\tSmall" + case '' + set res $res -x -a "black\tColor red\tColor green\tColor yellow\tColor blue\tColor magenta\tColor cyan\tColor white\tColor default\tColor" case '<*>' set res $res -x + case '*' + set res $res -f end - set args (string trim -- (string split -- ',' (string replace -r -- '<\??\w+>' '' $args))) + set args (string replace -r -- $regexp '' $args | string split ',' | string trim) for arg in $args if string match -q -- '--*' $arg diff --git a/src/data/help.txt b/src/data/help.txt index 1e1df2107..6fab811c5 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -17,9 +17,9 @@ Informative options: --print-structure: Print the default structure Config options: - -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 + -c, --config : Load a config file or preset (+) + --gen-config : Generate a config file (or print it if is `-`), with options specified in the command line (if any) + --gen-config-force : Generate a config file. Overwrite the existing one --load-user-config : Set if user config should be loaded. Default is true if env-var `NO_CONFIG` is not set General options: @@ -31,9 +31,9 @@ General options: 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-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-color-[1-9] : Overwrite a color in the logo --logo-padding : Set the padding on the left and the right of the logo @@ -43,18 +43,18 @@ Logo options: --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 + --file : Short for --logo-type file --logo + --file-raw : Short for --logo-type file-raw --logo --data : Short for --logo-type data --logo --data-raw : Short for --logo-type data-raw --logo - --sixel : Short for --logo-type sixel --logo - --kitty : Short for --logo-type kitty --logo - --iterm : Short for --logo-type iterm --logo - --chafa : Short for --logo-type chafa --logo + --sixel : Short for --logo-type sixel --logo + --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-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-color-space : Set color space used for quantization. 0 for RGB; 1 for DIN99d. 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 Display options: @@ -72,8 +72,8 @@ Display options: --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 + --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 --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 '-' @@ -81,8 +81,8 @@ Display options: --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 + --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 General module options: ---format : Set the format string to use for each specific module. @@ -117,7 +117,7 @@ Library options: Set the path of a library to load --lib-osmesa : Needed by the OpenGL module for gl context creation --lib-opencl : OpenCL module --lib-pulse : Pulseaudio. Used for Sound detection - --lib-nm: NetworkManager. Used for Wifi detection + --lib-nm : NetworkManager. Used for Wifi detection --lib-freetype : Used for Termux font detection --lib-ddcutil : Used for brightness detection of external displays @@ -128,8 +128,8 @@ Module specific options: --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 --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) + --os-file : Set the file path which 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 @@ -140,12 +140,12 @@ Module specific options: --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 - --display-compact-type : Set if all displays should be printed in one line. Default is none + --display-compact-type : Set if all displays should be printed in one line. Must be one of `none`, `original` and `scaled`. 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 --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 + --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 --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2