mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-09-21 10:27:09 +00:00
feat(completions/vagrant): apply changes in the upstream version
This commit is contained in:
parent
0f68af869b
commit
020005bcc8
@ -1,5 +1,8 @@
|
|||||||
#! bash oh-my-bash.module
|
#! bash oh-my-bash.module
|
||||||
|
#
|
||||||
|
# The current version is based on the following upstream version:
|
||||||
|
# https://github.com/hashicorp/vagrant/blob/9df95a200280219ae5899db6eaa2e0eff4ad1a8e/contrib/bash/completion.sh
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
# (The MIT License)
|
# (The MIT License)
|
||||||
#
|
#
|
||||||
# Copyright (c) 2014 Kura
|
# Copyright (c) 2014 Kura
|
||||||
@ -53,7 +56,7 @@ function __vagrantinvestigate {
|
|||||||
function _vagrant {
|
function _vagrant {
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
commands="snapshot box connect destroy docker-logs docker-run global-status halt help init list-commands login package plugin provision rdp reload resume rsync rsync-auto share ssh ssh-config status suspend up version"
|
commands="box cloud connect destroy docker-exec docker-logs docker-run global-status halt help init list-commands login package plugin provision push rdp reload resume rsync rsync-auto share snapshot ssh ssh-config status suspend up version"
|
||||||
|
|
||||||
if [ $COMP_CWORD == 1 ]
|
if [ $COMP_CWORD == 1 ]
|
||||||
then
|
then
|
||||||
@ -65,7 +68,7 @@ function _vagrant {
|
|||||||
then
|
then
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
"init")
|
"init")
|
||||||
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
|
local box_list=$(find "${VAGRANT_HOME:-$HOME/.vagrant.d}/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//')
|
||||||
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@ -73,28 +76,45 @@ function _vagrant {
|
|||||||
vagrant_state_file=$(__vagrantinvestigate) || return 1
|
vagrant_state_file=$(__vagrantinvestigate) || return 1
|
||||||
if [[ -d $vagrant_state_file ]]
|
if [[ -d $vagrant_state_file ]]
|
||||||
then
|
then
|
||||||
vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
|
local vm_list=$(find "$vagrant_state_file/machines" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
|
||||||
fi
|
fi
|
||||||
local up_commands="--no-provision"
|
local up_commands="\
|
||||||
|
--provision \
|
||||||
|
--no-provision \
|
||||||
|
--provision-with \
|
||||||
|
--destroy-on-error \
|
||||||
|
--no-destroy-on-error \
|
||||||
|
--parallel \
|
||||||
|
--no-parallel
|
||||||
|
--provider \
|
||||||
|
--install-provider \
|
||||||
|
--no-install-provider \
|
||||||
|
-h \
|
||||||
|
--help"
|
||||||
COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur}))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
"ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config")
|
"destroy"|"ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config")
|
||||||
vagrant_state_file=$(__vagrantinvestigate) || return 1
|
vagrant_state_file=$(__vagrantinvestigate) || return 1
|
||||||
if [[ -f $vagrant_state_file ]]
|
if [[ -f $vagrant_state_file ]]
|
||||||
then
|
then
|
||||||
running_vm_list=$(grep 'active' "$vagrant_state_file" | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
|
running_vm_list=$(grep 'active' "$vagrant_state_file" | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
|
||||||
else
|
else
|
||||||
running_vm_list=$(find "$vagrant_state_file" -type f -name "id" | awk -F"/" '{print $(NF-2)}')
|
running_vm_list=$(find "$vagrant_state_file/machines" -type f -name "id" | awk -F"/" '{print $(NF-2)}')
|
||||||
fi
|
fi
|
||||||
COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur}))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
"box")
|
"box")
|
||||||
box_commands="add help list remove repackage"
|
box_commands="add help list outdated prune remove repackage update"
|
||||||
COMPREPLY=($(compgen -W "${box_commands}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${box_commands}" -- ${cur}))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
"cloud")
|
||||||
|
cloud_commands="auth box search provider publish version"
|
||||||
|
COMPREPLY=($(compgen -W "$cloud_commands" -- $cur))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
"plugin")
|
"plugin")
|
||||||
plugin_commands="install license list uninstall update"
|
plugin_commands="install license list uninstall update"
|
||||||
COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur}))
|
||||||
@ -105,7 +125,7 @@ function _vagrant {
|
|||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
"snapshot")
|
"snapshot")
|
||||||
snapshot_commands="back delete go list take"
|
snapshot_commands="delete list pop push restore save"
|
||||||
COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur}))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@ -119,27 +139,52 @@ function _vagrant {
|
|||||||
action="${COMP_WORDS[COMP_CWORD-2]}"
|
action="${COMP_WORDS[COMP_CWORD-2]}"
|
||||||
case "$action" in
|
case "$action" in
|
||||||
"up")
|
"up")
|
||||||
if [ "$prev" == "--no-provision" ]; then
|
if [ "$prev" == "--no-provision" ]
|
||||||
COMPREPLY=($(compgen -W "${vm_list}" -- ${cur}))
|
then
|
||||||
|
if [[ -d "$vagrant_state_file" ]]
|
||||||
|
then
|
||||||
|
local vm_list=$(find "$vagrant_state_file/machines" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
|
||||||
|
fi
|
||||||
|
COMPREPLY=($(compgen -W "$vm_list" -- $cur))
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"box")
|
"box")
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
"remove"|"repackage")
|
"remove"|"repackage")
|
||||||
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
|
local box_list=$(find "${VAGRANT_HOME:-$HOME/.vagrant.d}/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sed -e 's/-VAGRANTSLASH-/\//')
|
||||||
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
|
COMPREPLY=($(compgen -W "$box_list" -- $cur))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"add")
|
||||||
|
local add_commands="\
|
||||||
|
--name \
|
||||||
|
--checksum \
|
||||||
|
--checksum-type \
|
||||||
|
-c --clean \
|
||||||
|
-f --force \
|
||||||
|
"
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$add_commands" -- $cur))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -o default -- "$cur"))
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
"snapshot")
|
"snapshot")
|
||||||
if [ "$prev" == "go" ]; then
|
case "$prev" in
|
||||||
local snapshot_list=$(vagrant snapshot list | awk '/Name:/ { print $2 }')
|
"restore"|"delete")
|
||||||
COMPREPLY=($(compgen -W "${snapshot_list}" -- ${cur}))
|
local snapshot_list=$(vagrant snapshot list)
|
||||||
|
COMPREPLY=($(compgen -W "$snapshot_list" -- $cur))
|
||||||
return 0
|
return 0
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user