1

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?

Ariel Frischer
  • 1,406
  • 2
  • 12
  • 20

2 Answers2

3

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)
0

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.

Ariel Frischer
  • 1,406
  • 2
  • 12
  • 20
  • 1
    To explain why that's necessary: `complete -C` will complete the current commandline, only when you haven't started an interactive fish there is no current commandline. So it needs you to give it one. – faho Jan 20 '23 at 18:12