Reputation: 3247
I want to write a program that will print out the autocompletions of bash.
Basically I'm writting something into bash stdin with
childProc.stdin.write("./myfi")
And would like to receive autocompletion for it like "./myfile.txt"
But childProc.stdout
is empty after childProc.stdin.write("\t")
so there has to be some other way to trigger autocompletion.
Any ideas?
Upvotes: 0
Views: 356
Reputation: 3247
I've found an answer.
The thing that made it work was Pseudoterminal.
This module actually.
https://www.npmjs.com/package/pty.js-dl
Upvotes: 0
Reputation: 241771
Command-completion in only enabled in interactive shells. Bash is interactive if:
-c
option were specified when invoking bash, andboth stdin and stderr are attached to terminals (as determined by isatty()
), or
bash was started with the -i
flag.
In your case, stdin
is clearly a pipe, which is not a terminal. So probably command completion has been disabled. But if it were enabled, you'd see the result on stderr
not stdout
.
So you could try supplying the -i
command line option when starting your bash shell, or you could attach its stdin, stdout and stderr file descriptors to a pseudo-tty. In either case, what you will see coming back from bash will be intermingled with terminal control codes, so you'll probably want to set TERM
to something basic (like dumb
).
If you want to see the completions which bash
might generate, you can use the compgen
built-in. compgen
does not know about the customized completion settings installed by the complete
command, and it is not easy to get the environment set up correctly for the -F
and -C
function, but other than that you can probably get it to generate whatever completion lists you would like. See the Bash manual for detailed option documentation.
Upvotes: 2