ohmu
·
2026-10-15
1#compdef fastfetch
2
3function _fastfetch() {
4
5 whence python3 &> /dev/null
6 if [ $? -ne 0 ]
7 then
8 return
9 fi
10
11 local state
12
13 local -a opts=("${(f)$(
14 python3 <<EOF
15import json
16import subprocess
17import sys
18
19
20def main():
21 data: dict[str, list[dict]] = json.loads(
22 subprocess.check_output(["fastfetch", "--help-raw"])
23 )
24
25 for key in data:
26 for flag in data[key]:
27 if flag["long"] == "logo-color-[1-9]":
28 for i in range(1, 10):
29 command_prefix = f"--logo-color-{i}[{flag['desc']} ({i})]"
30 print_command(command_prefix, flag)
31 continue
32
33 if flag.get("pseudo", False):
34 continue
35
36 if "short" in flag:
37 command_prefix = f"-{flag['short']}[{flag['desc']}]"
38 print_command(command_prefix, flag)
39
40 if "long" in flag:
41 command_prefix = f"--{flag['long']}[{flag['desc']}]"
42 print_command(command_prefix, flag)
43
44
45def print_command(command_prefix: str, flag: dict):
46 if "arg" in flag:
47 type: str = flag["arg"]["type"]
48 if type == "bool":
49 print(f"{command_prefix}::bool:(true false)")
50 elif type == "color":
51 print(f"{command_prefix}:color:->colors")
52 elif type == "command":
53 print(f"{command_prefix}::module:->modules")
54 elif type == "config":
55 print(f"{command_prefix}:preset:->presets")
56 elif type == "enum":
57 temp: str = " ".join(flag["arg"]["enum"])
58 print(f'{command_prefix}:type:({temp})')
59 elif type == "logo":
60 print(f"{command_prefix}:logo:->logos")
61 elif type == "structure":
62 print(f"{command_prefix}:structure:->structures")
63 elif type == "path":
64 print(f"{command_prefix}::path:_files")
65 else:
66 print(f"{command_prefix}:")
67 else:
68 print(f"{command_prefix}")
69
70
71if __name__ == "__main__":
72 try:
73 main()
74 except Exception:
75 sys.exit(1)
76EOF
77 )}")
78
79 _arguments "$opts[@]"
80
81 case $state in
82 colors)
83 local -a colors=(black red green yellow blue magenta cyan white default)
84 _describe 'color' colors
85 ;;
86 modules)
87 local -a modules=("${(f)$(fastfetch --list-modules autocompletion)}")
88 modules=(${(L)^modules[@]%%:*}-format format color)
89 _describe 'module' modules
90 ;;
91 presets)
92 local -a presets=(
93 "${(f)$(fastfetch --list-presets autocompletion)}"
94 "none:Disable loading config file"
95 )
96 _describe 'preset' presets || _files
97 ;;
98 structures)
99 local -a structures=("${(f)$(fastfetch --list-modules autocompletion)}")
100 _describe 'structure' structures
101 ;;
102 logos)
103 local -a logos=(
104 "${(f)$(fastfetch --list-logos autocompletion)}"
105 "none:Don't print logo"
106 "small:Print small ascii logo if available"
107 )
108 _describe 'logo' logos
109 ;;
110 esac
111}
112
113_fastfetch "$@"