Top.Mail.Ru
? ?

Previous Entry | Next Entry

Completion in vzctl

There is a nice feature in vzctl (well, technically not in vzctl binary itself; it just comes in vzctl package) that many people don't know about -- completion. This basically makes it able to save a few keystrokes when typing.

Say you want to create a container. You type vzct and press <TAB> -- it completes that to vzctl and a space after. This is usual feature of bash -- it looks all the binaries available in $PATH and tries to complete their names.

Now let's see the vzctl completion:
# vzctl cr<TAB>
completes to
# vzctl create
and then after yet another <TAB> it suggests a CT ID which is the MAX+1 (i.e. if you have containers 101, 102 and 105 it will suggest 106):
# vzctl create 106
Now we want to specify an OS template:
# vzctl create 106 --os<TAB>
will get you to
# vzctl create 106 --ostemplate
and then you press <TAB> again twice to see the list of available OS templates:
# vzctl create 106 --ostemplate <TAB><TAB>
centos-5-x86 centos-5-x86-devel fedora-9-x86 suse-11.1-x86

Now you type in the first few characters of the OS template you want to use:
# vzctl create 106 --ostemplate f<TAB>
and it will complete that to
# vzctl create 106 --ostemplate fedora-9-x86
Now, unless you want to specify --config or some other parameters, just press Enter.

This completion is smart -- say, if you want to start a container, type in
# vzctl start <TAB><TAB>
and it will give you the list of container IDs that can be started (i.e. all the stopped containers).

And so on and so forth. Well, you say, it doesn't work! In that case you have to enable it, here's how.

On a RHEL, CentOS or Fedora system run yum install bash-completion and then relogin (i.e. log out and log in again). If your host system is Gentoo, run emerge bash-completion and then eselect bashcomp enable vzctl. I hope someone will comment on how to enable this for Debian/Ubuntu/SUSE or whatever your favorite distro is.

Tags:

Comments

koct9i
May. 22nd, 2009 07:04 pm (UTC)
Re: Debian / Ubuntu
> echo "source /etc/bash_completion" >> ...

or uncomment lines in /etc/bash.bashrc or ~/.bashrc and re-exec shell

Latest Month

July 2016
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Comments

Powered by LiveJournal.com
Designed by Tiffany Chow