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