[pve-devel] Suggest hostnames in bash completion

Tobia Conforto tobia.conforto at gruppo4.eu
Mon Jul 18 17:28:00 CEST 2016

> Using bash is clumsy, because you cannot use the existing libraries. Instead, I suggest to use API calls, maybe using curl or wget? This would avoid the perl startup overhead. (maybe we need to adopt the http server to be able to return a suitable text format).

The problem with the REST API (apart from the overhead of spawning Curl processes and doing SSL handshake and encryption) is that it requires authentication: you don't want to save your PVE password in a bashrc file, or enter it at the prompt just to have auto-complete.

> Or simply startup the binary which listens on a local socket to do the command line completion (when started with "<cmd> bashcomplete"). Such server can exit after some idle timeout.

This is certainly better. But a TCP socket will not do, for security purposes (any user can connect to a TCP socket, even if you bind on localhost.) A UNIX socket would be better, but it's not natively supported in Bash (and spawning processes on each Tab keypress is bad practice.)

I can see an easy solution in the form of coprocesses[1]. The autocomplete bash function would spawn the command on demand as a coprocess and then communicate with it over private pipes, with a simple text protocol. For example: send one line with the text the user typed; receive one line with all the completions separated by space. As an added bonus, exiting or killing the shell would terminate the coprocess.

[1] https://tiswww.case.edu/php/chet/bash/bashref.html#SEC23


$ coproc REV { stdbuf -i0 -o0 -e0 rev; }
[1] 27168
$ echo hello >&${REV[1]}
$ read line  <&${REV[0]}; echo $line
$ echo world >&${REV[1]}
$ read line  <&${REV[0]}; echo $line

More information about the pve-devel mailing list