mirror of
https://github.com/gryf/vboxmanage-bash-completion.git
synced 2025-12-19 12:28:19 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6e71c51d9 | |||
| 2860d4e247 | |||
| e4618d52a5 | |||
| 6251330e9b | |||
| c05e1c4758 | |||
| 8c9812799d | |||
| 6db5b8c816 |
24
LICENSE
Normal file
24
LICENSE
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Copyright (c) 2015, Roman Dobosz
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of the organization nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL ROMAN DOBOSZ BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
8
README
8
README
@@ -1,8 +0,0 @@
|
|||||||
VBoxManage bash completion script.
|
|
||||||
|
|
||||||
This version of the completion was initially based on Sebastian T. Hafner
|
|
||||||
script. However, in some point of time I've decided to rewrite it almost from
|
|
||||||
scratch.
|
|
||||||
|
|
||||||
Current version of script was written and tested against VBoxManage in version
|
|
||||||
4.3.18, and supports all commands (in some extent ;)).
|
|
||||||
56
README.rst
Normal file
56
README.rst
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
VBoxManage bash completion script
|
||||||
|
=================================
|
||||||
|
|
||||||
|
This version of the completion was initially based on Sebastian T. Hafner
|
||||||
|
script. However, in some point of time I've decided to rewrite it almost from
|
||||||
|
scratch.
|
||||||
|
|
||||||
|
Current version of script was written and tested against VBoxManage in version
|
||||||
|
4.3.32, and supports all commands (in some extent ;)).
|
||||||
|
|
||||||
|
Unlike other attempts, I've tried to make the script context aware. See the
|
||||||
|
simple session with the VBoxManage command below, to have an idea how it works:
|
||||||
|
|
||||||
|
.. image:: /images/vboxmanage_session.gif?raw=true
|
||||||
|
:alt: VBoxManage session
|
||||||
|
|
||||||
|
|
||||||
|
Note, that ``startvm`` command proposes only VMs, which are not running, while
|
||||||
|
``controlvm`` will complete only running VMs.
|
||||||
|
|
||||||
|
What is worth to mention, this completion script is a real thing, so it only
|
||||||
|
offer things which have sense for particular commands, for example:
|
||||||
|
|
||||||
|
.. image:: /images/vboxmanage_snapshot.gif?raw=true
|
||||||
|
:alt: Take a snapshot
|
||||||
|
|
||||||
|
For ``snapshot take`` subcommand, the only options which are proposed are
|
||||||
|
``--live`` and ``--description``. Other commands and subcommands are behaving in
|
||||||
|
similar way.
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Either source the file::
|
||||||
|
|
||||||
|
$ . /path/to/this/repo/VBoxManage
|
||||||
|
|
||||||
|
or add it to a proper place depending on your distribution. Usual place would
|
||||||
|
be:
|
||||||
|
|
||||||
|
* ~/bash-completion.d/
|
||||||
|
* /usr/local/etc/bash-completion.d/
|
||||||
|
* /etc/bash_completion.d/
|
||||||
|
* etc.
|
||||||
|
|
||||||
|
It's also okay to copy it into some directory, and place proper line in
|
||||||
|
``.profile`` or ``.bashrc``::
|
||||||
|
|
||||||
|
source /some/directory/VBoxManage
|
||||||
|
|
||||||
|
License
|
||||||
|
=======
|
||||||
|
|
||||||
|
This software is licensed under 3-clause BSD license. See LICENSE file for
|
||||||
|
details.
|
||||||
41
VBoxManage
41
VBoxManage
@@ -1,6 +1,7 @@
|
|||||||
# bash command-line completion for VBoxManage command
|
# bash command-line completion for VBoxManage command
|
||||||
#
|
#
|
||||||
# Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
|
# Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
|
||||||
|
# License: 3-clause BSD-style license (see LICENSE file)
|
||||||
|
|
||||||
_VBoxManage() {
|
_VBoxManage() {
|
||||||
local cur prev opts cmd subcommand tmp items name index result
|
local cur prev opts cmd subcommand tmp items name index result
|
||||||
@@ -101,10 +102,24 @@ _VBoxManage() {
|
|||||||
# Issues are the same as in above function.
|
# Issues are the same as in above function.
|
||||||
_vms_comp() {
|
_vms_comp() {
|
||||||
local command=$1
|
local command=$1
|
||||||
|
local exclude_running=false
|
||||||
local vms
|
local vms
|
||||||
|
local running_vms
|
||||||
local item
|
local item
|
||||||
|
|
||||||
|
|
||||||
compopt -o filenames
|
compopt -o filenames
|
||||||
|
if [[ $# == 2 ]]
|
||||||
|
then
|
||||||
|
exclude_running=true
|
||||||
|
running_vms=$(VBoxManage list runningvms | \
|
||||||
|
awk -F ' {' '{ print $1 }' | \
|
||||||
|
tr '\n' '|' | \
|
||||||
|
sed 's/|$//' | \
|
||||||
|
sed 's/"//g')
|
||||||
|
IFS='|' read -ra running_vms <<< "$running_vms"
|
||||||
|
fi
|
||||||
|
|
||||||
vms=$(VBoxManage list $command | \
|
vms=$(VBoxManage list $command | \
|
||||||
awk -F ' {' '{ print $1 }' | \
|
awk -F ' {' '{ print $1 }' | \
|
||||||
tr '\n' '|' | \
|
tr '\n' '|' | \
|
||||||
@@ -113,6 +128,12 @@ _VBoxManage() {
|
|||||||
IFS='|' read -ra vms <<< "$vms"
|
IFS='|' read -ra vms <<< "$vms"
|
||||||
for item in "${vms[@]}"
|
for item in "${vms[@]}"
|
||||||
do
|
do
|
||||||
|
if $exclude_running
|
||||||
|
then
|
||||||
|
_is_in_array "$item" "${running_vms[@]}"
|
||||||
|
[[ $? == 0 ]] && continue
|
||||||
|
fi
|
||||||
|
|
||||||
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item")
|
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item")
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -369,6 +390,15 @@ _VBoxManage() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_is_in_array() {
|
||||||
|
local element
|
||||||
|
for element in "${@:2}"
|
||||||
|
do
|
||||||
|
[[ "$element" == "$1" ]] && return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
COMP_WORDBREAKS=${COMP_WORDBREAKS//|/} # remove pipe from comp word breaks
|
COMP_WORDBREAKS=${COMP_WORDBREAKS//|/} # remove pipe from comp word breaks
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
@@ -871,13 +901,14 @@ _VBoxManage() {
|
|||||||
items=(--image --username --passwordfile --password
|
items=(--image --username --passwordfile --password
|
||||||
--domain --verbose --timeout --environment
|
--domain --verbose --timeout --environment
|
||||||
--wait-exit --wait-stdout --wait-stderr --dos2unix
|
--wait-exit --wait-stdout --wait-stderr --dos2unix
|
||||||
--unix2dos)
|
--unquoted-args --unix2dos)
|
||||||
|
|
||||||
[[ " ${COMP_WORDS[@]} " == *" --password "* ||
|
[[ " ${COMP_WORDS[@]} " == *" --password "* ||
|
||||||
" ${COMP_WORDS[@]} " == *" --passwordfile "* ]] &&
|
" ${COMP_WORDS[@]} " == *" --passwordfile "* ]] &&
|
||||||
items=(--image --username --domain --verbose
|
items=(--image --username --domain --verbose
|
||||||
--timeout --environment --wait-exit --wait-stdout
|
--timeout --environment --wait-exit --wait-stdout
|
||||||
--wait-stderr --dos2unix --unix2dos)
|
--wait-stderr --dos2unix --unquoted-args
|
||||||
|
--unix2dos)
|
||||||
|
|
||||||
_get_excluded_items "${items[@]}"
|
_get_excluded_items "${items[@]}"
|
||||||
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
@@ -1392,7 +1423,7 @@ _VBoxManage() {
|
|||||||
file" -- ${cur}) )
|
file" -- ${cur}) )
|
||||||
;;
|
;;
|
||||||
--audio)
|
--audio)
|
||||||
COMPREPLY+=( $(compgen -W "none null oss alsa" \
|
COMPREPLY+=( $(compgen -W "none null oss alsa pulse" \
|
||||||
-- ${cur}) )
|
-- ${cur}) )
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -1469,7 +1500,7 @@ _VBoxManage() {
|
|||||||
setproperty)
|
setproperty)
|
||||||
items=(machinefolder hwvirtexclusive vrdeauthlibrary
|
items=(machinefolder hwvirtexclusive vrdeauthlibrary
|
||||||
websrvauthlibrary vrdeextpack autostartdbpath loghistorycount
|
websrvauthlibrary vrdeextpack autostartdbpath loghistorycount
|
||||||
defaultfrontend)
|
defaultfrontend logginglevel)
|
||||||
subcommand=${COMP_WORDS[2]}
|
subcommand=${COMP_WORDS[2]}
|
||||||
if [[ "${prev}" == "${cmd}" ]]; then
|
if [[ "${prev}" == "${cmd}" ]]; then
|
||||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||||
@@ -1603,7 +1634,7 @@ _VBoxManage() {
|
|||||||
;;
|
;;
|
||||||
startvm)
|
startvm)
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
_vms_comp vms
|
_vms_comp vms 1
|
||||||
elif [[ "${prev}" == "--type" ]]; then
|
elif [[ "${prev}" == "--type" ]]; then
|
||||||
COMPREPLY=( $(compgen -W "gui sdl headless" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "gui sdl headless" -- ${cur}) )
|
||||||
else
|
else
|
||||||
|
|||||||
BIN
images/vboxmanage_session.gif
Normal file
BIN
images/vboxmanage_session.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
BIN
images/vboxmanage_snapshot.gif
Normal file
BIN
images/vboxmanage_snapshot.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 232 KiB |
Reference in New Issue
Block a user