Home > Software engineering >  How to get all fish shell commands from a python script?
How to get all fish shell commands from a python script?

Time:01-17

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?

CodePudding user response:

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)

CodePudding user response:

Try passing in "ls" or any other command to see if your error goes away.

command = "fish -c 'complete -C ls'"

Try a new command to get available commands:

command = "fish -c 'complete -l'"

CodePudding user response:

I think I got it working with

command = "fish -c 'complete -C \"\"'"

Which adds an empty quote as an arg so that there is no more stderr.

  • Related