[pve-devel] Suggest hostnames in bash completion

Tobia Conforto tobia.conforto at gruppo4.eu
Mon Jul 18 13:46:40 CEST 2016


I would like to add a feature (and contribute the code, if anybody is interested): make the 'pct' bash completion show the hostnames when a vmid parameter is being completed.

Current behaviour:

	# pct enter <Tab><Tab>
	200  201  202  ...

What I'd like to get:

	# pct enter <Tab><Tab>
	200(frontend-1)  201(frontend-2)  202(db-server)  ...

The way this is usually done is to return a list of items containing the description in a custom format (such as "$item($comment)" in this example) unless the list is down to only one possible completion: in that case the description is stripped, so that only the item is inserted into the commandline.

I found the code that prints the completion list in CLIHandler.pm around line 260 ($print_parameter_completion), but it gets the list of possible values from an anonymous sub ($info->{parameters}->{properties}->{$pname}->{completion}) which I don't have a clue where it may be defined and in how many other places it may be used.

Given this, I'd rather add a custom behaviour for the 'vmid' parameter in $print_parameter_completion, rather than changing something more generic.

Can anybody give me a hint on how to obtain the list of vmid along with the hostnames inside that module?


More information about the pve-devel mailing list