2024-08-25 19:58:47 +06:00
|
|
|
#compdef fastfetch
|
|
|
|
|
|
|
|
function _fastfetch() {
|
2024-10-02 23:30:19 +10:00
|
|
|
|
|
|
|
whence python3 &> /dev/null
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-08-25 19:58:47 +06:00
|
|
|
local state
|
|
|
|
|
2024-08-29 13:55:12 +06:00
|
|
|
local -a opts=("${(f)$(
|
|
|
|
python3 <<EOF
|
2024-08-25 19:58:47 +06:00
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
data: dict[str, list[dict]] = json.loads(
|
|
|
|
subprocess.check_output(["fastfetch", "--help-raw"])
|
|
|
|
)
|
|
|
|
|
|
|
|
for key in data:
|
|
|
|
for flag in data[key]:
|
2024-08-29 13:55:12 +06:00
|
|
|
if flag["long"] == "logo-color-[1-9]":
|
|
|
|
for i in range(1, 10):
|
2024-11-29 05:25:58 +03:00
|
|
|
command_prefix = f"--logo-color-{i}[{flag['desc']} ({i})]"
|
2024-08-29 13:55:12 +06:00
|
|
|
print_command(command_prefix, flag)
|
|
|
|
continue
|
|
|
|
|
2024-08-25 19:58:47 +06:00
|
|
|
if flag.get("pseudo", False):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if "short" in flag:
|
2024-11-29 05:25:58 +03:00
|
|
|
command_prefix = f"-{flag['short']}[{flag['desc']}]"
|
2024-08-25 19:58:47 +06:00
|
|
|
print_command(command_prefix, flag)
|
|
|
|
|
|
|
|
if "long" in flag:
|
2024-11-29 05:25:58 +03:00
|
|
|
command_prefix = f"--{flag['long']}[{flag['desc']}]"
|
2024-08-25 19:58:47 +06:00
|
|
|
print_command(command_prefix, flag)
|
|
|
|
|
|
|
|
|
|
|
|
def print_command(command_prefix: str, flag: dict):
|
|
|
|
if "arg" in flag:
|
|
|
|
type: str = flag["arg"]["type"]
|
|
|
|
if type == "bool":
|
2024-08-28 08:18:38 +06:00
|
|
|
print(f"{command_prefix}::bool:(true false)")
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "color":
|
2024-08-29 13:55:12 +06:00
|
|
|
print(f"{command_prefix}:color:->colors")
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "command":
|
2024-08-28 08:18:38 +06:00
|
|
|
print(f"{command_prefix}::module:->modules")
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "config":
|
2024-08-26 15:39:49 +06:00
|
|
|
print(f"{command_prefix}:preset:->presets")
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "enum":
|
|
|
|
temp: str = " ".join(flag["arg"]["enum"])
|
2024-08-26 15:39:49 +06:00
|
|
|
print(f'{command_prefix}:type:({temp})')
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "logo":
|
2024-08-26 15:39:49 +06:00
|
|
|
print(f"{command_prefix}:logo:->logos")
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "structure":
|
2024-08-26 15:39:49 +06:00
|
|
|
print(f"{command_prefix}:structure:->structures")
|
2024-08-25 19:58:47 +06:00
|
|
|
elif type == "path":
|
2024-08-28 08:18:38 +06:00
|
|
|
print(f"{command_prefix}::path:_files")
|
2024-08-25 19:58:47 +06:00
|
|
|
else:
|
|
|
|
print(f"{command_prefix}:")
|
|
|
|
else:
|
|
|
|
print(f"{command_prefix}")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except Exception:
|
|
|
|
sys.exit(1)
|
|
|
|
EOF
|
2024-08-29 13:55:12 +06:00
|
|
|
)}")
|
2024-08-25 19:58:47 +06:00
|
|
|
|
2024-08-26 15:39:49 +06:00
|
|
|
_arguments "$opts[@]"
|
2024-08-25 19:58:47 +06:00
|
|
|
|
|
|
|
case $state in
|
2024-08-29 13:55:12 +06:00
|
|
|
colors)
|
|
|
|
local -a colors=(black red green yellow blue magenta cyan white default)
|
|
|
|
_describe 'color' colors
|
|
|
|
;;
|
2024-08-25 19:58:47 +06:00
|
|
|
modules)
|
2024-08-28 08:18:38 +06:00
|
|
|
local -a modules=("${(f)$(fastfetch --list-modules autocompletion)}")
|
2024-08-29 13:55:12 +06:00
|
|
|
modules=(${(L)^modules[@]%%:*}-format format color)
|
2024-08-25 19:58:47 +06:00
|
|
|
_describe 'module' modules
|
|
|
|
;;
|
|
|
|
presets)
|
|
|
|
local -a presets=(
|
2024-08-28 08:18:38 +06:00
|
|
|
"${(f)$(fastfetch --list-presets autocompletion)}"
|
2024-08-25 19:58:47 +06:00
|
|
|
"none:Disable loading config file"
|
|
|
|
)
|
2024-08-29 13:55:12 +06:00
|
|
|
_describe 'preset' presets || _files
|
2024-08-25 19:58:47 +06:00
|
|
|
;;
|
2024-08-26 15:39:49 +06:00
|
|
|
structures)
|
2024-08-28 08:18:38 +06:00
|
|
|
local -a structures=("${(f)$(fastfetch --list-modules autocompletion)}")
|
2024-08-25 19:58:47 +06:00
|
|
|
_describe 'structure' structures
|
|
|
|
;;
|
2024-08-26 15:39:49 +06:00
|
|
|
logos)
|
2024-08-25 19:58:47 +06:00
|
|
|
local -a logos=(
|
2024-08-28 08:18:38 +06:00
|
|
|
"${(f)$(fastfetch --list-logos autocompletion)}"
|
2024-08-25 19:58:47 +06:00
|
|
|
"none:Don't print logo"
|
|
|
|
"small:Print small ascii logo if available"
|
|
|
|
)
|
|
|
|
_describe 'logo' logos
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
_fastfetch "$@"
|