Search code examples
pythoncommandcommand-line-interfacefishcompletion

How to get all fish shell commands from a python script?


When I run complete -C from my regular terminal fish shell I get a list of ~4k commands, which is great. I want this to happen from my python script. I have the following but it doesn't work:

command = "fish -c 'complete -C'"
    output = (
        subprocess.run(command, shell=True, capture_output=True).stdout.decode().strip()
    )

The output stdout is just an empty string. The stderr is showing:

complete: -C: option requires an argument
Standard input (line 1):
complete -C
(Type 'help complete' for related documentation)"

How can I get this to work? Is there something outside of python subprocess I can use for this?


Solution

  • When you type complete -C in normal fish prompt it gets converted to complete -C ''

    so you have to do:

    import subprocess
    command = "fish -c \"complete -C ''\""
    output = (
        subprocess.run(command, shell=True, capture_output=True).stdout.decode().strip()
    )
    print(output)