diff options
Diffstat (limited to 'completions')
| -rw-r--r-- | completions/fastfetch.bash | 121 | ||||
| -rwxr-xr-x | completions/fastfetch.fish | 113 | ||||
| -rw-r--r-- | completions/fastfetch.zsh | 113 |
3 files changed, 347 insertions, 0 deletions
diff --git a/completions/fastfetch.bash b/completions/fastfetch.bash new file mode 100644 index 0000000..681046d --- /dev/null +++ b/completions/fastfetch.bash @@ -0,0 +1,121 @@ +#!/usr/bin/env bash + +_fastfetch() { + # Use Bash built-in variables directly + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + + # Check if Python is available + if ! command -v python3 &>/dev/null; then + return + fi + + # Handle standard completion cases + case "$prev" in + --color|--color-keys|--color-title|--color-output|--color-separator|--*-color|--*-key-color|--*-output-color|--logo-color-[1-9]|--percent-color-*|--temp-color-*) + local -a colors=("black" "red" "green" "yellow" "blue" "magenta" "cyan" "white" "default") + COMPREPLY=($(compgen -W "${colors[*]}" -- "$cur")) + return + ;; + --logo|-l) + local -a logos + readarray -t logos < <(fastfetch --list-logos autocompletion 2>/dev/null) + logos+=("none" "small") + COMPREPLY=($(compgen -W "${logos[*]}" -- "$cur")) + return + ;; + --config|-c) + local -a presets + readarray -t presets < <(fastfetch --list-presets autocompletion 2>/dev/null) + presets+=("none") + COMPREPLY=($(compgen -W "${presets[*]}" -- "$cur")) + # Also allow file path completion + if type _filedir &>/dev/null; then + _filedir + elif type compgen &>/dev/null; then + COMPREPLY+=($(compgen -f -- "$cur")) + fi + return + ;; + --structure|-s) + # Get all module names in lowercase only + local -a structures + readarray -t structures < <(fastfetch --list-modules autocompletion 2>/dev/null | cut -d':' -f1 | tr '[:upper:]' '[:lower:]') + COMPREPLY=($(compgen -W "${structures[*]}" -- "$cur")) + return + ;; + --help|-h) + local -a modules + readarray -t modules < <(fastfetch --list-modules autocompletion 2>/dev/null) + # Convert to lowercase and keep only module names + local -a module_names=() + for module in "${modules[@]}"; do + module_names+=($(echo "$module" | cut -d':' -f1 | tr '[:upper:]' '[:lower:]')-format) + done + module_names+=("format" "color") + COMPREPLY=($(compgen -W "${module_names[*]}" -- "$cur")) + return + ;; + --format) + COMPREPLY=($(compgen -W "json default" -- "$cur")) + return + ;; + --*-format) + # Format string completion, handle spaces + return + ;; + --*path*|--*file*|--gen-config*|--*data*) + # File path completion + if type _filedir &>/dev/null; then + _filedir + elif type compgen &>/dev/null; then + COMPREPLY=($(compgen -f -- "$cur")) + fi + return + ;; + esac + + # If not a special option, generate all possible options + if [[ "$cur" == -* ]]; then + local -a opts + readarray -t opts < <(python3 - "$cur" <<'EOF' +import json +import sys +import subprocess + +def main(current): + try: + # Use fastfetch --help-raw to get option data + output = subprocess.check_output(['fastfetch', '--help-raw'], stderr=subprocess.DEVNULL) + data = json.loads(output) + + for category in data.values(): + for flag in category: + if flag.get("pseudo", False): + continue + + if "short" in flag: + print(f"-{flag['short']}") + + if "long" in flag: + if flag["long"] == "logo-color-[1-9]": + for i in range(1, 10): + print(f"--logo-color-{i}") + else: + print(f"--{flag['long']}") + except Exception: + # If error occurs, return no options + pass + +if __name__ == "__main__": + main(sys.argv[1]) +EOF +) + COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur")) + fi + + return 0 +} + +# Register completion +complete -F _fastfetch fastfetch diff --git a/completions/fastfetch.fish b/completions/fastfetch.fish new file mode 100755 index 0000000..f4804f5 --- /dev/null +++ b/completions/fastfetch.fish @@ -0,0 +1,113 @@ +if not type -q fastfetch + exit +end + +command -q python3 +if test $status -ne 0 + exit +end + +complete -c fastfetch -f + +function __fastfetch_complete_bool + echo -e "true\tBool" + echo -e "false\tBool" +end + +function __fastfetch_complete_color + echo -e "black\tColor" + echo -e "red\tColor" + echo -e "green\tColor" + echo -e "yellow\tColor" + echo -e "blue\tColor" + echo -e "magenta\tColor" + echo -e "cyan\tColor" + echo -e "white\tColor" + echo -e "default\tColor" +end + +function __fastfetch_complete_command + for line in (fastfetch --list-modules autocompletion) + set -l pair (string split -m 2 : $line) + set -l module (string lower $pair[1]) + + echo -e "$module-format\tModule format" + end + echo -e "format\tCustom format" + echo -e "color\tColor format" +end + +function __fastfetch_complete_config + for line in (fastfetch --list-presets autocompletion) + echo -e "$line\tPreset" + end + echo -e "none\tDisable loading config file" +end + +function __fastfetch_complete_logo + for line in (fastfetch --list-logos autocompletion) + echo -e "$line\tBuiltin logo" + end + echo -e "none\tDon't print logo" + echo -e "small\tPrint small ascii logo if available" +end + +function __fastfetch_complete_structure + for line in (fastfetch --list-modules autocompletion) + set -l pair (string split -m 2 : $line) + echo -e "$pair[1]\t$pair[2]" + end +end + +echo ' +import json, subprocess, 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]: + if flag["long"] == "logo-color-[1-9]": + for i in range(1, 10): + print(f"""complete -c fastfetch -d "{flag["desc"]}" -l "logo-color-{i}" -x -a "(__fastfetch_complete_color)" """) + continue + + if flag.get("pseudo", False): + continue + + command_prefix = f"""complete -c fastfetch -d "{flag["desc"]}" -l "{flag["long"]}\"""" + if "short" in flag: + command_prefix += f""" -o {flag["short"]}""" + + if "arg" in flag: + type: str = flag["arg"]["type"] + if type == "bool": + print(f"{command_prefix} -x -a \"(__fastfetch_complete_bool)\"") + elif type == "color": + print(f"{command_prefix} -x -a \"(__fastfetch_complete_color)\"") + elif type == "command": + print(f"{command_prefix} -x -a \"(__fastfetch_complete_command)\"") + elif type == "config": + print(f"{command_prefix} -x -a \"(__fastfetch_complete_config)\"") + elif type == "enum": + temp: str = " ".join(flag["arg"]["enum"]) + print(f"{command_prefix} -x -a \"{temp}\"") + elif type == "logo": + print(f"{command_prefix} -x -a \"(__fastfetch_complete_logo)\"") + elif type == "structure": + print(f"{command_prefix} -x -a \"(__fish_complete_list : __fastfetch_complete_structure)\"") + elif type == "path": + print(f"{command_prefix} -r -F") + else: + print(f"{command_prefix} -x") + else: + print(f"{command_prefix} -f") + + +if __name__ == "__main__": + try: + main() + except: + sys.exit(1) +' | python3 | source diff --git a/completions/fastfetch.zsh b/completions/fastfetch.zsh new file mode 100644 index 0000000..08b92c9 --- /dev/null +++ b/completions/fastfetch.zsh @@ -0,0 +1,113 @@ +#compdef fastfetch + +function _fastfetch() { + + whence python3 &> /dev/null + if [ $? -ne 0 ] + then + return + fi + + local state + + local -a opts=("${(f)$( + python3 <<EOF +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]: + if flag["long"] == "logo-color-[1-9]": + for i in range(1, 10): + command_prefix = f"--logo-color-{i}[{flag['desc']} ({i})]" + print_command(command_prefix, flag) + continue + + if flag.get("pseudo", False): + continue + + if "short" in flag: + command_prefix = f"-{flag['short']}[{flag['desc']}]" + print_command(command_prefix, flag) + + if "long" in flag: + command_prefix = f"--{flag['long']}[{flag['desc']}]" + 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": + print(f"{command_prefix}::bool:(true false)") + elif type == "color": + print(f"{command_prefix}:color:->colors") + elif type == "command": + print(f"{command_prefix}::module:->modules") + elif type == "config": + print(f"{command_prefix}:preset:->presets") + elif type == "enum": + temp: str = " ".join(flag["arg"]["enum"]) + print(f'{command_prefix}:type:({temp})') + elif type == "logo": + print(f"{command_prefix}:logo:->logos") + elif type == "structure": + print(f"{command_prefix}:structure:->structures") + elif type == "path": + print(f"{command_prefix}::path:_files") + else: + print(f"{command_prefix}:") + else: + print(f"{command_prefix}") + + +if __name__ == "__main__": + try: + main() + except Exception: + sys.exit(1) +EOF + )}") + + _arguments "$opts[@]" + + case $state in + colors) + local -a colors=(black red green yellow blue magenta cyan white default) + _describe 'color' colors + ;; + modules) + local -a modules=("${(f)$(fastfetch --list-modules autocompletion)}") + modules=(${(L)^modules[@]%%:*}-format format color) + _describe 'module' modules + ;; + presets) + local -a presets=( + "${(f)$(fastfetch --list-presets autocompletion)}" + "none:Disable loading config file" + ) + _describe 'preset' presets || _files + ;; + structures) + local -a structures=("${(f)$(fastfetch --list-modules autocompletion)}") + _describe 'structure' structures + ;; + logos) + local -a logos=( + "${(f)$(fastfetch --list-logos autocompletion)}" + "none:Don't print logo" + "small:Print small ascii logo if available" + ) + _describe 'logo' logos + ;; + esac +} + +_fastfetch "$@" |