[pve-devel] Suggest hostnames in bash completion

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Jul 18 14:12:25 CEST 2016


On Mon, Jul 18, 2016 at 01:46:40PM +0200, Tobia Conforto wrote:
> Hello
> 
> 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.

This should probably be optional (perhaps an env var) since it's also a
bit more expensive and completion already feels a bit sluggish.

> 
> 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.

Completion functions are provided in the parameter definitions of
commands in the CLI/ subfolders.

Eg. pct enter has this piece of description code (in CLI/pct.pm):
|    parameters => {
|    	additionalProperties => 0,
|	properties => {
|	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
|	},
|    },

This shows that it's using PVE/LXC.pm's complete_ctid_running() sub,
which in turn you'll find is using $complete_ctid_full.

> 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?

See PVE/LXC.pm's vmstatus() sub.

Anologously for 'qm' you'll have to modify the corresponding function
from the qemu-server package.



More information about the pve-devel mailing list