Merge branch 'refactor-completions'

This commit is contained in:
Koichi Murase 2024-08-25 13:11:15 +09:00
commit dfa9e25e28
15 changed files with 2530 additions and 2081 deletions

View File

@ -1,4 +1,17 @@
#! bash oh-my-bash.module
#
# Note: I could not find the true original source of this completion, but we
# can find several versions at the following places:
#
# * https://gist.github.com/mbauman/839902
# * https://github.com/taylanpince/wiki/blob/master/scripts/bash_completion_scripts/defaults (Version 1.0)
# * https://github.com/gaelicWizard/bash-progcomp/tree/main (Version 2.0)
#
# The v2 script seems to be a complete rewrite of the original v1.0, though it
# retains the original copyright notice. The current version is based on
# Version 1.0.
#
#------------------------------------------------------------------------------
# defaults
# Bash command line completion for defaults
#
@ -7,141 +20,139 @@
#
# Version 1.0 (2006-11-08)
function _defaults_domains {
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
_defaults_domains()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur" )
local IFS=$'\n'
COMPREPLY=( $domains )
if [[ $( echo '-app' | grep "^$cur" ) ]]; then
COMPREPLY[${#COMPREPLY[@]}]="-app"
fi
return 0
local domains=$(defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur")
_omb_util_split COMPREPLY "$domains" $'\n'
if grep -q "^$cur" <<< '-app'; then
COMPREPLY[${#COMPREPLY[@]}]="-app"
fi
return 0
}
function _defaults {
local cur prev host_opts cmds cmd domain keys key_index
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
_defaults()
{
local cur prev host_opts cmds cmd domain keys key_index
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
host_opts='-currentHost -host'
cmds='read read-type write rename delete domains find help'
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $( compgen -W "$host_opts $cmds" -- $cur ) )
return 0
elif [[ $COMP_CWORD -eq 2 ]]; then
if [[ "$prev" == "-currentHost" ]]; then
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
return 0
elif [[ "$prev" == "-host" ]]; then
return 0
_known_hosts -a
else
_defaults_domains
return 0
fi
elif [[ $COMP_CWORD -eq 3 ]]; then
if [[ ${COMP_WORDS[1]} == "-host" ]]; then
_defaults_domains
return 0
fi
fi
# Both a domain and command have been specified
if [[ ${COMP_WORDS[1]} == [${cmds// /|}] ]]; then
cmd=${COMP_WORDS[1]}
domain=${COMP_WORDS[2]}
key_index=3
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 3 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[3]}"
key_index=4
fi
elif [[ ${COMP_WORDS[2]} == "-currentHost" ]] && [[ ${COMP_WORDS[2]} == [${cmds// /|}] ]]; then
cmd=${COMP_WORDS[2]}
domain=${COMP_WORDS[3]}
key_index=4
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 4 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[4]}"
key_index=5
fi
elif [[ ${COMP_WORDS[3]} == "-host" ]] && [[ ${COMP_WORDS[3]} == [${cmds// /|}] ]]; then
cmd=${COMP_WORDS[3]}
domain=${COMP_WORDS[4]}
key_index=5
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 5 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[5]}"
key_index=6
fi
fi
keys=$( defaults read $domain 2>/dev/null | sed -n -e '/^ [^}) ]/p' | sed -e 's/^ \([^" ]\{1,\}\) = .*$/\1/g' -e 's/^ "\([^"]\{1,\}\)" = .*$/\1/g' | sed -e 's/ /\\ /g' )
case $cmd in
read|read-type)
# Complete key
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
;;
write)
if [[ $key_index -eq $COMP_CWORD ]]; then
# Complete key
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
elif [[ $((key_index+1)) -eq $COMP_CWORD ]]; then
# Complete value type
# Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
local value_types='-string -data -integer -float -boolean -date -array -array-add -dict -dict-add'
local cur_type=$( defaults read-type $domain ${COMP_WORDS[key_index]} 2>/dev/null | sed -e 's/^Type is \(.*\)/-\1/' -e's/dictionary/dict/' | grep "^$cur" )
if [[ $cur_type ]]; then
COMPREPLY=( $cur_type )
else
COMPREPLY=( $( compgen -W "$value_types" -- $cur ) )
fi
elif [[ $((key_index+2)) -eq $COMP_CWORD ]]; then
# Complete value
# Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
COMPREPLY=( $( defaults read $domain ${COMP_WORDS[key_index]} 2>/dev/null | grep -i "^${cur//\\/\\\\}" ) )
fi
;;
rename)
if [[ $key_index -eq $COMP_CWORD ]] ||
[[ $((key_index+1)) -eq $COMP_CWORD ]]; then
# Complete source and destination keys
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
fi
;;
delete)
if [[ $key_index -eq $COMP_CWORD ]]; then
# Complete key
local IFS=$'\n'
COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
fi
;;
esac
host_opts='-currentHost -host'
cmds='read read-type write rename delete domains find help'
if ((COMP_CWORD == 1)); then
COMPREPLY=( $(compgen -W "$host_opts $cmds" -- "$cur") )
return 0
elif ((COMP_CWORD == 2)); then
if [[ $prev == "-currentHost" ]]; then
COMPREPLY=( $(compgen -W "$cmds" -- "$cur") )
return 0
elif [[ $prev == "-host" ]]; then
if _omb_util_function_exists _known_hosts; then
_known_hosts -a
fi
return 0
else
_defaults_domains
return 0
fi
elif ((COMP_CWORD == 3)); then
if [[ ${COMP_WORDS[1]} == "-host" ]]; then
_defaults_domains
return 0
fi
fi
# Both a domain and command have been specified
if [[ ${COMP_WORDS[1]} == @(${cmds// /|}) ]]; then
cmd=${COMP_WORDS[1]}
domain=${COMP_WORDS[2]}
key_index=3
if [[ $domain == "-app" ]]; then
if ((COMP_CWORD == 3)); then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[3]}"
key_index=4
fi
elif [[ ${COMP_WORDS[2]} == "-currentHost" && ${COMP_WORDS[2]} == @(${cmds// /|}) ]]; then
cmd=${COMP_WORDS[2]}
domain=${COMP_WORDS[3]}
key_index=4
if [[ "$domain" == "-app" ]]; then
if [[ $COMP_CWORD -eq 4 ]]; then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[4]}"
key_index=5
fi
elif [[ ${COMP_WORDS[3]} == "-host" && ${COMP_WORDS[3]} == @(${cmds// /|}) ]]; then
cmd=${COMP_WORDS[3]}
domain=${COMP_WORDS[4]}
key_index=5
if [[ $domain == "-app" ]]; then
if ((COMP_CWORD == 5)); then
# Completing application name. Can't help here, sorry
return 0
fi
domain="-app ${COMP_WORDS[5]}"
key_index=6
fi
fi
keys=$(defaults read $domain 2>/dev/null |
sed -ne '/^ [^}) ]/p' |
sed -e 's/^ \([^" ]\{1,\}\) = .*$/\1/g' -e 's/^ "\([^"]\{1,\}\)" = .*$/\1/g' |
sed -e 's/ /\\ /g' )
case $cmd in
read|read-type)
# Complete key
local IFS=$'\n'
COMPREPLY=( $(grep -i "^${cur//\\/\\\\}" <<< "$keys") )
;;
write)
if ((key_index == COMP_CWORD)); then
# Complete key
local IFS=$'\n'
COMPREPLY=( $(grep -i "^${cur//\\/\\\\}" <<< "$keys") )
elif ((key_index + 1 == COMP_CWORD)); then
# Complete value type
# Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
local value_types='-string -data -integer -float -boolean -date -array -array-add -dict -dict-add'
local cur_type=$(defaults read-type $domain ${COMP_WORDS[key_index]} 2>/dev/null | sed -e 's/^Type is \(.*\)/-\1/' -e's/dictionary/dict/' | grep "^$cur")
if [[ $cur_type ]]; then
COMPREPLY=( $cur_type )
else
COMPREPLY=( $(compgen -W "$value_types" -- "$cur") )
fi
elif ((key_index + 2 == COMP_CWORD)); then
# Complete value
# Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
COMPREPLY=( $(defaults read $domain ${COMP_WORDS[key_index]} 2>/dev/null | grep -i "^${cur//\\/\\\\}") )
fi
;;
rename)
if ((key_index == COMP_CWORD || key_index + 1 == COMP_CWORD)); then
# Complete source and destination keys
local IFS=$'\n'
COMPREPLY=( $(grep -i "^${cur//\\/\\\\}" <<< "$keys") )
fi
;;
delete)
if ((key_index == COMP_CWORD)); then
# Complete key
local IFS=$'\n'
COMPREPLY=( $(grep -i "^${cur//\\/\\\\}" <<< "$keys") )
fi
;;
esac
return 0
}
complete -F _defaults -o default defaults

View File

@ -1,4 +1,8 @@
#! bash oh-my-bash.module
#
# The current version is based on the following upstream version:
# https://github.com/owenthereal/gh/blob/04a7985fa9a1c1d4d63738f4edb7b07d228bdb12/etc/gh.bash_completion.sh
#------------------------------------------------------------------------------
# hub tab-completion script for bash.
# This script complements the completion script that ships with git.
@ -38,17 +42,17 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-s)
unset s
;;
*)
for sh in $shells; do
if [ "$sh" = "$i" ]; then
unset shells
break
fi
done
;;
-s)
unset s
;;
*)
for sh in $shells; do
if [ "$sh" = "$i" ]; then
unset shells
break
fi
done
;;
esac
((c++))
done
@ -65,16 +69,16 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$repo" ]; then
repo=$i
else
subpage=$i
fi
;;
-u)
unset u
;;
*)
if [ -z "$repo" ]; then
repo=$i
else
subpage=$i
fi
;;
esac
((c++))
done
@ -82,14 +86,14 @@ EOF
__gitcomp "$u -- $(__hub_github_repos '\p')"
elif [ -z "$subpage" ]; then
case "$cur" in
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages_}"
;;
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages_}"
;;
esac
else
__gitcomp "$u"
@ -102,26 +106,26 @@ EOF
while [ $c -gt 1 ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$rev" ]; then
# Even though the logic below is able to complete both user/repo
# and revision in the right place, when there is only one argument
# (other than -u) in the command, that argument will be taken as
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
fi
elif [ -z "$arg_repo" ]; then
-u)
unset u
;;
*)
if [ -z "$rev" ]; then
# Even though the logic below is able to complete both user/repo
# and revision in the right place, when there is only one argument
# (other than -u) in the command, that argument will be taken as
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
fi
;;
elif [ -z "$arg_repo" ]; then
arg_repo=$i
fi
;;
esac
((c--))
done
@ -163,20 +167,20 @@ EOF
local pfx cur_="$cur"
case "$cur_" in
*..*)
pfx="${cur_%%..*}..."
cur_="${cur_##*..}"
__gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_"
;;
*)
if [ -z "${arg_repo}${rev}" ]; then
__gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)"
elif [ -z "$rev" ]; then
__gitcomp "$u $(__hub_revlist $remote)"
else
__gitcomp "$u"
fi
;;
*..*)
pfx="${cur_%%..*}..."
cur_="${cur_##*..}"
__gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_"
;;
*)
if [ -z "${arg_repo}${rev}" ]; then
__gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)"
elif [ -z "$rev" ]; then
__gitcomp "$u $(__hub_revlist $remote)"
else
__gitcomp "$u"
fi
;;
esac
}
@ -186,16 +190,16 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-d|-h)
((c++))
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
name=$i
;;
-d|-h)
((c++))
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
name=$i
;;
esac
((c++))
done
@ -203,12 +207,12 @@ EOF
repo=$(basename "$PWD")
fi
case "$prev" in
-d|-h)
COMPREPLY=()
;;
-p|*)
__gitcomp "$repo $flags"
;;
-d|-h)
COMPREPLY=()
;;
-p|*)
__gitcomp "$repo $flags"
;;
esac
}
@ -218,9 +222,9 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--no-remote)
unset remote
;;
--no-remote)
unset remote
;;
esac
((c++))
done
@ -235,33 +239,33 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-m|-F|-i|-b|-h)
((c++))
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
-m|-F|-i|-b|-h)
((c++))
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
esac
((c++))
done
case "$prev" in
-i)
COMPREPLY=()
;;
-b|-h)
# (Doesn't seem to need this...)
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
;;
-i)
COMPREPLY=()
;;
-b|-h)
# (Doesn't seem to need this...)
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
;;
esac
}
@ -364,4 +368,3 @@ EOF
complete -o bashdefault -o default -o nospace -F _git gh 2>/dev/null \
|| complete -o default -o nospace -F _git gh
fi

View File

@ -1,5 +1,8 @@
#! bash oh-my-bash.module
#
# The current version is based on the following upstream version:
# https://github.com/petervanderdoes/git-flow-completion/blob/db3c032411c2d6fd897b2bfc52d15a6fc4e3bfa3/git-flow-completion.bash
#------------------------------------------------------------------------------
# git-flow-completion
# ===================
#
@ -8,8 +11,8 @@
# The contained completion routines provide support for completing:
#
# * git-flow init and version
# * feature, hotfix and release branches
# * remote feature, hotfix and release branch names
# * feature, bugfix, hotfix and release branches
# * remote feature, bugfix, hotfix and release branch names
#
#
# Installation
@ -50,461 +53,551 @@
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
__git_flow_config_file_options="
--local --global --system --file=
"
--local --global --system --file=
"
_git_flow ()
{
local subcommands="init feature release hotfix support help version config finish delete publish rebase"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
local subcommands="init feature bugfix release hotfix support help version config finish delete publish rebase"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
init)
__git_flow_init
return
;;
feature)
__git_flow_feature
return
;;
release)
__git_flow_release
return
;;
hotfix)
__git_flow_hotfix
return
;;
support)
__git_flow_support
return
;;
config)
__git_flow_config
return
;;
*)
COMPREPLY=()
;;
esac
case "$subcommand" in
init)
__git_flow_init
return
;;
feature)
__git_flow_feature
return
;;
bugfix)
__git_flow_bugfix
return
;;
release)
__git_flow_release
return
;;
hotfix)
__git_flow_hotfix
return
;;
support)
__git_flow_support
return
;;
config)
__git_flow_config
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_init ()
{
local subcommands="help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
fi
local subcommands="help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
fi
case "$cur" in
--*)
__gitcomp "
--nodefaults --defaults
--noforce --force
$__git_flow_config_file_options
"
return
;;
esac
case "$cur" in
--*)
__gitcomp "
--nodefaults --defaults
--noforce --force
$__git_flow_config_file_options
"
return
;;
esac
}
__git_flow_feature ()
{
local subcommands="list start finish publish track diff rebase checkout pull help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
local subcommands="list start finish publish track diff rebase checkout pull help delete rename"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
pull)
__gitcomp_nl "$(__git_remotes)"
return
;;
checkout)
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--norebase --rebase
--nopreserve-merges --preserve-merges
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--nosquash --squash
--no-ff
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
diff)
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'feature')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'feature')"
return
;;
*)
COMPREPLY=()
;;
esac
case "$subcommand" in
pull)
__gitcomp_nl "$(__git_remotes)"
return
;;
checkout)
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--norebase --rebase
--nopreserve-merges --preserve-merges
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--nosquash --squash
--no-ff
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
diff)
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'feature')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'feature')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'feature')"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_bugfix ()
{
local subcommands="list start finish publish track diff rebase checkout pull help delete rename"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
pull)
__gitcomp_nl "$(__git_remotes)"
return
;;
checkout)
__gitcomp_nl "$(__git_flow_list_local_branches 'bugfix')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'bugfix')"
return
;;
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--norebase --rebase
--nopreserve-merges --preserve-merges
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--nosquash --squash
--no-ff
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'bugfix')"
return
;;
diff)
__gitcomp_nl "$(__git_flow_list_local_branches 'bugfix')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'bugfix')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'bugfix')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'bugfix')"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_release ()
{
local subcommands="list start finish track publish help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
local subcommands="list start finish track publish help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--sign
--signingkey
--message
--nomessagefile --messagefile=
--nopush --push
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--notag --tag
--nonobackmerge --nobackmerge
--nosquash --squash
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'release')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'release')"
return
;;
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
*)
COMPREPLY=()
;;
esac
case "$subcommand" in
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--sign
--signingkey
--message
--nomessagefile --messagefile=
--nopush --push
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--notag --tag
--nonobackmerge --nobackmerge
--nosquash --squash
--squash-info
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'release')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'release')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'release')"
return
;;
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_hotfix ()
{
local subcommands="list start finish track publish help delete"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
local subcommands="list start finish track publish help delete rename"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--sign
--signingkey
--message
--nomessagefile --messagefile=
--nopush --push
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--notag --tag
--nonobackmerge --nobackmerge
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'hotfix')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'hotfix')"
return
;;
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
*)
COMPREPLY=()
;;
esac
case "$subcommand" in
finish)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
--sign
--signingkey
--message
--nomessagefile --messagefile=
--nopush --push
--nokeep --keep
--keepremote
--keeplocal
--noforce_delete --force_delete
--notag --tag
--nonobackmerge --nobackmerge
--nosquash --squash
--squash-info
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
delete)
case "$cur" in
--*)
__gitcomp "
--noforce --force
--noremote --remote
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'hotfix')"
return
;;
publish)
__gitcomp_nl "$(__git_flow_list_branches 'hotfix')"
return
;;
track)
__gitcomp_nl "$(__git_flow_list_branches 'hotfix')"
return
;;
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_support ()
{
local subcommands="list start help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
local subcommands="list start help"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'support')"
return
;;
*)
COMPREPLY=()
;;
esac
case "$subcommand" in
start)
case "$cur" in
--*)
__gitcomp "
--nofetch --fetch
"
return
;;
esac
return
;;
rebase)
case "$cur" in
--*)
__gitcomp "
--nointeractive --interactive
--nopreserve-merges --preserve-merges
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches 'support')"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_config ()
{
local subcommands="list set base"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
local subcommands="list set base"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
set)
case "$cur" in
--*)
__gitcomp "
$__git_flow_config_file_options
"
return
;;
esac
__gitcomp "
master develop
feature hotfix release support
versiontagprefix
"
return
;;
base)
case "$cur" in
--*)
__gitcomp "
set get
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches)"
return
;;
*)
COMPREPLY=()
;;
esac
case "$subcommand" in
set)
case "$cur" in
--*)
__gitcomp "
$__git_flow_config_file_options
"
return
;;
esac
__gitcomp "
master develop
feature bugfix hotfix release support
versiontagprefix
"
return
;;
base)
case "$cur" in
--*)
__gitcomp "
set get
"
return
;;
esac
__gitcomp_nl "$(__git_flow_list_local_branches)"
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_flow_prefix ()
{
case "$1" in
feature|release|hotfix|support)
_omb_prompt_git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/"
return
;;
esac
case "$1" in
feature|bugfix|release|hotfix|support)
_omb_prompt_git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/"
return
;;
esac
}
__git_flow_list_local_branches ()
{
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
_omb_prompt_git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref#$prefix}"
echo "$ref"
done | sort
else
_omb_prompt_git for-each-ref --format="ref=%(refname:short)" refs/heads/ | sort
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
_omb_prompt_git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref#$prefix}"
echo "$ref"
done | sort
else
_omb_prompt_git for-each-ref --format="ref=%(refname:short)" refs/heads/ | sort
fi
fi
}
__git_flow_list_remote_branches ()
{
local prefix="$(__git_flow_prefix $1)"
local origin="$(_omb_prompt_git config gitflow.origin 2> /dev/null || echo "origin")"
_omb_prompt_git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
local prefix="$(__git_flow_prefix $1)"
local origin="$(_omb_prompt_git config gitflow.origin 2> /dev/null || echo "origin")"
_omb_prompt_git for-each-ref --shell --format='%(refname:short)' refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
}
__git_flow_list_branches ()
{
local origin="$(_omb_prompt_git config gitflow.origin 2> /dev/null || echo "origin")"
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
_omb_prompt_git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
else
_omb_prompt_git for-each-ref --format="%(refname:short)" refs/heads/ refs/remotes/$origin | sort
fi
local origin="$(_omb_prompt_git config gitflow.origin 2> /dev/null || echo "origin")"
if [ -n "$1" ]; then
local prefix="$(__git_flow_prefix $1)"
_omb_prompt_git for-each-ref --shell --format="ref=%(refname:short)" refs/heads/$prefix refs/remotes/$origin/$prefix | \
while read -r entry; do
eval "$entry"
ref="${ref##$prefix}"
echo "$ref"
done | sort
else
_omb_prompt_git for-each-ref --format="%(refname:short)" refs/heads/ refs/remotes/$origin | sort
fi
}
# alias __git_find_on_cmdline for backwards compatibility
if [ -z "`type -t __git_find_on_cmdline`" ]; then
alias __git_find_on_cmdline=__git_find_subcommand
alias __git_find_on_cmdline=__git_find_subcommand
fi

View File

@ -1,8 +1,8 @@
#! bash oh-my-bash.module
#
# bash completion for go tool
# https://github.com/thomasf/go-bash-completion
# https://github.com/thomasf/go-bash-completion/blob/73c7543f2a295d27ae9bc71baa1ef1a858447eae/go-bash-completion.bash
#------------------------------------------------------------------------------
# install in /etc/bash_completion.d/ or your personal directory
complete -f -X '!*.8' 8l
@ -11,29 +11,27 @@ complete -f -X '!*.5' 5l
complete -f -X '!*.go' 8g 6g 5g gofmt gccgo
function _go_clear_cache {
unset _go_imports
unset -v _go_imports
}
function _go_importpath_cache {
if [ -z "$_go_imports" ]; then
if [[ ! ${_go_imports-} ]]; then
_go_imports=$(go list all 2>/dev/null)
export _go_imports
fi
}
_go_importpath()
{
echo "$(compgen -W "$_go_imports" -- "$1")"
function _go_importpath {
compgen -W "$_go_imports" -- "$1"
}
_go()
{
function _go {
# TODO: Only allow flags before other arguments. run already does
# this.
local cur=`_get_cword`
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local cur=$(_get_cword)
local prev=${COMP_WORDS[COMP_CWORD-1]}
local cmd="${COMP_WORDS[1]}"
local cmd=${COMP_WORDS[1]}
local cmds="build clean doc env fix fmt get
install list run test tool version vet"
@ -43,236 +41,237 @@ _go()
local env_vars="GOARCH GOBIN GOEXE GOHOSTARCH GOHOSTOS GOOS GOPATH GORACE
GOROOT GOTOOLDIR GO15VENDOREXPERIMENT CC GOGCCFLAGS CXX CGO_ENABLED"
if [ "$COMP_CWORD" == 1 ]; then
if ((COMP_CWORD == 1)); then
local opt
for opt in $cmds; do
if [[ "$opt" == "$cmd" ]]; then
if [[ $opt == "$cmd" ]]; then
COMPREPLY=("$opt")
return
return 0
fi
done
fi
case "$cmd" in
'build')
case "$prev" in
'-o')
_filedir
;;
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-a -n -o -p -v -x" -- "$cur"))
else
local found=0
for ((i=0; i < ${#COMP_WORDS[@]}; i++)); do
case "$i" in
0|1|"$COMP_CWORD")
continue
;;
esac
local opt="${COMP_WORDS[i]}"
if [[ "$opt" != -* ]]; then
if [[ "$opt" == *.go && -f "$opt" ]]; then
found=1
break
else
found=2
break
fi
fi
done
case "$found" in
0)
_filedir go
_go_importpath_cache
COMPREPLY+=(`_go_importpath "$cur"`)
;;
1)
_filedir go
;;
2)
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
esac
fi
;;
esac
case $cmd in
'build')
case $prev in
'-o')
_filedir
;;
'clean')
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-i -r -n -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
'doc')
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
'env')
COMPREPLY=($(compgen -W "$env_vars" -- "$cur"))
;;
'fix')
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
'fmt')
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
;;
'get')
case "$prev" in
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-a -d -fix -n -p -u -v -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'install')
case "$prev" in
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-a -n -p -v -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'list')
case "$prev" in
'-f')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-e -f -json" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'run')
if [[ "$cur" == -* && "$prev" != *.go ]]; then
COMPREPLY=($(compgen -W "-a -n -x" -- "$cur"))
else
_filedir
fi
;;
'test') # TODO: Support for testflags.
case "$prev" in
'-file')
_filedir go
;;
'-p')
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-c -file -i -p -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
esac
;;
'tool')
if [ "$COMP_CWORD" == 2 ]; then
COMPREPLY=($(compgen -W "$(go tool)" -- "$cur"))
else
case "${COMP_WORDS[2]}" in
[568]a) # TODO: Implement something.
#_go_tool_568a
;;
[568]c) # TODO: Implement something.
#_go_tool_568c
;;
[568]g) # TODO: Implement something.
#_go_tool_568g
;;
[568]l) # TODO: Implement something.
#_go_tool_568l
;;
'api') # TODO: Implement something.
#_go_tool_api
;;
'cgo') # TODO: Implement something.
#_go_tool_cgo
;;
'cov') # TODO: Implement something.
#_go_tool_cov
;;
'dist') # TODO: Implement something.
#_go_tool_dist
;;
'ebnflint') # TODO: Implement something.
#_go_tool_ebnflint
;;
'fix') # TODO: Implement something.
#_go_tool_fix
;;
'gotype') # TODO: Implement something.
#_go_tool_gotype
;;
'nm') # TODO: Implement something.
#_go_tool_nm
;;
'pack') # TODO: Implement something.
#_go_tool_pack
;;
'pprof') # TODO: Implement something.
#_go_tool_pprof
;;
'prof') # TODO: Implement something.
#_go_tool_prof
;;
'vet') # TODO: Implement something.
#_go_tool_vet
;;
'yacc') # TODO: Implement something.
#_go_tool_yacc
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "${COMPREPLY[*]} -h" -- "$cur"))
fi
fi
;;
'version')
;;
'vet')
if [[ "$cur" == -* ]]; then
:
else
_go_importpath_cache
COMPREPLY=(`_go_importpath "$cur"`)
fi
;;
'help')
if [ "$COMP_CWORD" == 2 ]; then
COMPREPLY=($(compgen -W "$cmds $addhelp" -- "$cur"))
fi
'-p')
;;
*)
if [ "$COMP_CWORD" == 1 ]; then
COMPREPLY=($(compgen -W "$cmds $other" -- "$cur"))
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "-a -n -o -p -v -x" -- "$cur"))
else
_filedir
local found=0 i
for ((i=0; i < ${#COMP_WORDS[@]}; i++)); do
case $i in
0|1|"$COMP_CWORD")
continue
;;
esac
local opt=${COMP_WORDS[i]}
if [[ $opt != -* ]]; then
if [[ $opt == *.go && -f $opt ]]; then
found=1
break
else
found=2
break
fi
fi
done
case $found in
0)
_filedir go
_go_importpath_cache
COMPREPLY+=($(_go_importpath "$cur"))
;;
1)
_filedir go
;;
2)
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
;;
esac
fi
;;
esac
;;
'clean')
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "-i -r -n -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
fi
;;
'doc')
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
;;
'env')
COMPREPLY=($(compgen -W "$env_vars" -- "$cur"))
;;
'fix')
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
;;
'fmt')
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
;;
'get')
case $prev in
'-p')
;;
*)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "-a -d -fix -n -p -u -v -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
fi
;;
esac
;;
'install')
case $prev in
'-p')
;;
*)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "-a -n -p -v -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
fi
;;
esac
;;
'list')
case $prev in
'-f')
;;
*)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "-e -f -json" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
fi
;;
esac
;;
'run')
if [[ $cur == -* && $prev != *.go ]]; then
COMPREPLY=($(compgen -W "-a -n -x" -- "$cur"))
else
_filedir
fi
;;
'test') # TODO: Support for testflags.
case $prev in
'-file')
_filedir go
;;
'-p')
;;
*)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "-c -file -i -p -x" -- "$cur"))
else
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
fi
;;
esac
;;
'tool')
if ((COMP_CWORD == 2)); then
COMPREPLY=($(compgen -W "$(go tool)" -- "$cur"))
else
case ${COMP_WORDS[2]} in
[568]a) # TODO: Implement something.
#_go_tool_568a
;;
[568]c) # TODO: Implement something.
#_go_tool_568c
;;
[568]g) # TODO: Implement something.
#_go_tool_568g
;;
[568]l) # TODO: Implement something.
#_go_tool_568l
;;
'api') # TODO: Implement something.
#_go_tool_api
;;
'cgo') # TODO: Implement something.
#_go_tool_cgo
;;
'cov') # TODO: Implement something.
#_go_tool_cov
;;
'dist') # TODO: Implement something.
#_go_tool_dist
;;
'ebnflint') # TODO: Implement something.
#_go_tool_ebnflint
;;
'fix') # TODO: Implement something.
#_go_tool_fix
;;
'gotype') # TODO: Implement something.
#_go_tool_gotype
;;
'nm') # TODO: Implement something.
#_go_tool_nm
;;
'pack') # TODO: Implement something.
#_go_tool_pack
;;
'pprof') # TODO: Implement something.
#_go_tool_pprof
;;
'prof') # TODO: Implement something.
#_go_tool_prof
;;
'vet') # TODO: Implement something.
#_go_tool_vet
;;
'yacc') # TODO: Implement something.
#_go_tool_yacc
;;
esac
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "${COMPREPLY[*]} -h" -- "$cur"))
fi
fi
;;
'version')
;;
'vet')
if [[ $cur == -* ]]; then
:
else
_go_importpath_cache
COMPREPLY=($(_go_importpath "$cur"))
fi
;;
'help')
if ((COMP_CWORD == 2)); then
COMPREPLY=($(compgen -W "$cmds $addhelp" -- "$cur"))
fi
;;
*)
if ((COMP_CWORD == 1)); then
COMPREPLY=($(compgen -W "$cmds $other" -- "$cur"))
else
_filedir
fi
;;
esac
}

View File

@ -1,47 +1,49 @@
#! bash oh-my-bash.module
# This completion setting seems to be only found in Oh My Bash.
#------------------------------------------------------------------------------
function __gradle {
local cur=${COMP_WORDS[COMP_CWORD]}
local tasks=''
local cache_dir="$HOME/.gradle/completion_cache"
local cache_dir=$HOME/.gradle/completion_cache
case $OSTYPE in
darwin*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5 -q | md5 -q"
;;
*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5sum | md5sum | cut -d ' ' -f 1"
;;
darwin*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5 -q | md5 -q"
;;
*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5sum | md5sum | cut -d ' ' -f 1"
;;
esac
local parsing_command="gradle --console=plain --quiet tasks | grep -v Rules | sed -nE -e 's/^([a-zA-Z]+)($| - .+)/\1/p'"
mkdir -p "${cache_dir}"
mkdir -p "$cache_dir"
local gradle_files_checksum='no_cache_file'
if [[ -f build.gradle ]]; then
gradle_files_checksum="$(eval "${checksum_command}")"
if [[ -f "${cache_dir}/${gradle_files_checksum}" ]]; then
newest_gradle_file="$(find . -type f -name build.gradle -newer "${cache_dir}/${gradle_files_checksum}")"
if [ -n "${newest_gradle_file}" ]; then
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
gradle_files_checksum=$(eval "$checksum_command")
if [[ -f $cache_dir/$gradle_files_checksum ]]; then
newest_gradle_file=$(find . -type f -name build.gradle -newer "$cache_dir/$gradle_files_checksum")
if [[ $newest_gradle_file ]]; then
tasks=$(eval "$parsing_command")
[[ $tasks ]] && echo "$tasks" > "$cache_dir/$gradle_files_checksum"
else
tasks="$(cat "${cache_dir}/${gradle_files_checksum}")"
touch "${cache_dir}/${gradle_files_checksum}"
tasks=$(< "$cache_dir/$gradle_files_checksum")
touch "$cache_dir/$gradle_files_checksum"
fi
else
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
tasks=$(eval "$parsing_command")
[[ $tasks ]] && echo "$tasks" > "$cache_dir/$gradle_files_checksum"
fi
else
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
tasks=$(eval "$parsing_command")
[[ $tasks ]] && echo "$tasks" > "$cache_dir/$gradle_files_checksum"
fi
COMPREPLY=( $(compgen -W "${tasks}" -- "${cur}") )
COMPREPLY=($(compgen -W "$tasks" -- "$cur"))
}
function __clear_gradle_cache {
local cache_dir="$HOME/.gradle/completion_cache"
[[ -d "${cache_dir}" ]] && find "${cache_dir}" -type f -mtime +7 -exec rm -f {} \;
local cache_dir=$HOME/.gradle/completion_cache
[[ -d $cache_dir ]] && find "$cache_dir" -type f -mtime +7 -exec rm -f {} \;
}
__clear_gradle_cache

View File

@ -1,5 +1,12 @@
#! bash oh-my-bash.module
#
# The current version is based on the following upstream version:
# https://github.com/gruntjs/grunt-cli/blob/8c791efc931fa8cf80cc98d09d3e20c36501fc0f/completion/bash#L33
#
# Note: The upstream version seems to have just updated the copyright year, but
# that change must be wrong. Basically, the copyright year should reflect the
# year of the first release. The years of later updates are optional.
#------------------------------------------------------------------------------
# grunt-cli
# http://gruntjs.com/
#
@ -15,33 +22,34 @@
# eval "$(grunt --completion=bash)"
# Search the current directory and all parent directories for a gruntfile.
function _grunt_gruntfile() {
local curpath="$PWD"
while [[ "$curpath" ]]; do
for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do
if [[ -e "$gruntfile" ]]; then
function _grunt_gruntfile {
local curpath=$PWD
while [[ $curpath ]]; do
local gruntfile
for gruntfile in "$curpath"/{G,g}runtfile.{js,coffee}; do
if [[ -e $gruntfile ]]; then
echo "$gruntfile"
return
return 0
fi
done
curpath="${curpath%/*}"
curpath=${curpath%/*}
done
return 1
}
# Enable bash autocompletion.
function _grunt_completions() {
function _grunt_completions {
# The currently-being-completed word.
local cur="${COMP_WORDS[COMP_CWORD]}"
local cur=${COMP_WORDS[COMP_CWORD]}
# The current gruntfile, if it exists.
local gruntfile="$(_grunt_gruntfile)"
local gruntfile=$(_grunt_gruntfile)
# The current grunt version, available tasks, options, etc.
local gruntinfo="$(grunt --version --verbose 2>/dev/null)"
local gruntinfo=$(grunt --version --verbose 2>/dev/null)
# Options and tasks.
local opts="$(echo "$gruntinfo" | awk '/Available options: / {$1=$2=""; print $0}')"
local compls="$(echo "$gruntinfo" | awk '/Available tasks: / {$1=$2=""; print $0}')"
local opts=$(awk '/Available options: / {$1=$2=""; print $0}' <<< "$gruntinfo")
local compls=$(awk '/Available tasks: / {$1=$2=""; print $0}' <<< "$gruntinfo")
# Only add -- or - options if the user has started typing -
[[ "$cur" == -* ]] && compls="$compls $opts"
[[ $cur == -* ]] && compls="$compls $opts"
# Tell complete what stuff to show.
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
}

View File

@ -1,4 +1,8 @@
#! bash oh-my-bash.module
#
# The current version is based on the following upstream version:
# https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/etc/hub.bash_completion.sh
#------------------------------------------------------------------------------
# hub tab-completion script for bash.
# This script complements the completion script that ships with git.
@ -7,8 +11,8 @@ if ! _omb_util_function_exists _git && _omb_util_function_exists _completion_loa
_completion_loader git
fi
# Check that git tab completion is available
if _omb_util_function_exists _git; then
# Check that git tab completion is available and we haven't already set up completion
if _omb_util_function_exists _git && ! _omb_util_function_exists __git_list_all_commands_without_hub ; then
# Duplicate and rename the 'list_all_commands' function
eval "$(declare -f __git_list_all_commands | \
sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"
@ -18,11 +22,16 @@ if _omb_util_function_exists _git; then
cat <<-EOF
alias
pull-request
pr
issue
release
fork
create
delete
browse
compare
ci-status
sync
EOF
__git_list_all_commands_without_hub
}
@ -40,17 +49,17 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-s)
unset s
;;
*)
for sh in $shells; do
if [ "$sh" = "$i" ]; then
unset shells
break
fi
done
;;
-s)
unset s
;;
*)
for sh in $shells; do
if [ "$sh" = "$i" ]; then
unset shells
break
fi
done
;;
esac
((c++))
done
@ -67,16 +76,16 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$repo" ]; then
repo=$i
else
subpage=$i
fi
;;
-u)
unset u
;;
*)
if [ -z "$repo" ]; then
repo=$i
else
subpage=$i
fi
;;
esac
((c++))
done
@ -84,14 +93,14 @@ EOF
__gitcomp "$u -- $(__hub_github_repos '\p')"
elif [ -z "$subpage" ]; then
case "$cur" in
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages_}"
;;
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages_}"
;;
esac
else
__gitcomp "$u"
@ -104,26 +113,26 @@ EOF
while [ $c -gt 1 ]; do
i="${words[c]}"
case "$i" in
-u)
unset u
;;
*)
if [ -z "$rev" ]; then
# Even though the logic below is able to complete both user/repo
# and revision in the right place, when there is only one argument
# (other than -u) in the command, that argument will be taken as
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
fi
elif [ -z "$arg_repo" ]; then
-u)
unset u
;;
*)
if [ -z "$rev" ]; then
# Even though the logic below is able to complete both user/repo
# and revision in the right place, when there is only one argument
# (other than -u) in the command, that argument will be taken as
# revision. For example:
# $ hub compare -u upstream
# > https://github.com/USER/REPO/compare/upstream
if __hub_github_repos '\p' | command grep -Eqx "^$i(/[^/]+)?"; then
arg_repo=$i
else
rev=$i
fi
;;
elif [ -z "$arg_repo" ]; then
arg_repo=$i
fi
;;
esac
((c--))
done
@ -165,20 +174,20 @@ EOF
local pfx cur_="$cur"
case "$cur_" in
*..*)
pfx="${cur_%%..*}..."
cur_="${cur_##*..}"
__gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_"
;;
*)
if [ -z "${arg_repo}${rev}" ]; then
__gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)"
elif [ -z "$rev" ]; then
__gitcomp "$u $(__hub_revlist $remote)"
else
__gitcomp "$u"
fi
;;
*..*)
pfx="${cur_%%..*}..."
cur_="${cur_##*..}"
__gitcomp_nl "$(__hub_revlist $remote)" "$pfx" "$cur_"
;;
*)
if [ -z "${arg_repo}${rev}" ]; then
__gitcomp "$u $(__hub_github_repos '\o\n\p') $(__hub_revlist $remote)"
elif [ -z "$rev" ]; then
__gitcomp "$u $(__hub_revlist $remote)"
else
__gitcomp "$u"
fi
;;
esac
}
@ -188,16 +197,16 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-d|-h)
((c++))
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
name=$i
;;
-d|-h)
((c++))
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
name=$i
;;
esac
((c++))
done
@ -205,30 +214,45 @@ EOF
repo=$(basename "$PWD")
fi
case "$prev" in
-d|-h)
COMPREPLY=()
;;
-p|*)
__gitcomp "$repo $flags"
;;
-d|-h)
COMPREPLY=()
;;
-p|*)
__gitcomp "$repo $flags"
;;
esac
}
# hub fork [--no-remote]
# hub fork [--no-remote] [--remote-name REMOTE] [--org ORGANIZATION]
function _git_fork {
local i c=2 remote=yes
local i c=2 flags="--no-remote --remote-name --org"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--no-remote)
unset remote
;;
--org)
((c++))
flags=${flags/$i/}
;;
--remote-name)
((c++))
flags=${flags/$i/}
flags=${flags/--no-remote/}
;;
--no-remote)
flags=${flags/$i/}
flags=${flags/--remote-name/}
;;
esac
((c++))
done
if [ -n "$remote" ]; then
__gitcomp "--no-remote"
fi
case "$prev" in
--remote-name|--org)
COMPREPLY=()
;;
*)
__gitcomp "$flags"
;;
esac
}
# hub pull-request [-f] [-m <MESSAGE>|-F <FILE>|-i <ISSUE>|<ISSUE-URL>] [-b <BASE>] [-h <HEAD>] [-a <USER>] [-M <MILESTONE>] [-l <LABELS>]
@ -237,33 +261,33 @@ EOF
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
-m|-F|-i|-b|-h|-a|-M|-l)
((c++))
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
-m|-F|-i|-b|-h|-a|-M|-l)
((c++))
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
esac
((c++))
done
case "$prev" in
-i)
COMPREPLY=()
;;
-b|-h|-a|-M|-l)
# (Doesn't seem to need this...)
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
;;
-i)
COMPREPLY=()
;;
-b|-h|-a|-M|-l)
# (Doesn't seem to need this...)
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
;;
esac
}
@ -325,7 +349,7 @@ EOF
format=${format//\o/\3}
fi
_omb_prompt_git config --get-regexp 'remote\.[^.]*\.url' |
grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
command grep -E ' ((https?|git)://|git@)github\.com[:/][^:/]+/[^/]+$' |
sed -E 's#^remote\.([^.]+)\.url +.+[:/](([^/]+)/[^.]+)(\.git)?$#'"$format"'#'
}

View File

@ -1,264 +1,259 @@
#! bash oh-my-bash.module
# Bash completion support for maven
# inspired from :
#
# Bash completion support for maven inspired from:
#
# - https://github.com/juven/maven-bash-completion
# - https://github.com/parisjug/maven-bash-completion
#
# The current version is based on the following upstream version.
# https://github.com/juven/maven-bash-completion/blob/216cd667b6119fe200c98b1ac2d030ac002be197/bash_completion.bash
#------------------------------------------------------------------------------
function_exists()
{
_omb_util_function_exists "$1"
return "$?"
_omb_deprecate_function 20000 function_exists _omb_util_function_exists
_omb_util_function_exists _get_comp_words_by_ref ||
function _get_comp_words_by_ref {
local exclude cur_ words_ cword_;
if [[ $1 == "-n" ]]; then
exclude=$2
shift 2
fi
__git_reassemble_comp_words_by_ref "$exclude"
cur_=${words_[cword_]}
while (($# > 0)); do
case $1 in
cur)
cur=$cur_
;;
prev)
prev=${words_[$cword_-1]}
;;
words)
words=("${words_[@]}")
;;
cword)
cword=$cword_
;;
esac;
shift
done
}
function_exists _get_comp_words_by_ref ||
_get_comp_words_by_ref ()
{
local exclude cur_ words_ cword_;
if [ "$1" = "-n" ]; then
exclude=$2;
shift 2;
fi;
__git_reassemble_comp_words_by_ref "$exclude";
cur_=${words_[cword_]};
while [ $# -gt 0 ]; do
case "$1" in
cur)
cur=$cur_
;;
prev)
prev=${words_[$cword_-1]}
;;
words)
words=("${words_[@]}")
;;
cword)
cword=$cword_
;;
esac;
shift;
_omb_util_function_exists __ltrim_colon_completions ||
function __ltrim_colon_completions {
if [[ $1 == *:* && $COMP_WORDBREAKS == *:* ]]; then
# Remove colon-word prefix from COMPREPLY items
local colon_word=${1%${1##*:}}
local i=${#COMPREPLY[*]}
while ((--i >= 0)); do
COMPREPLY[i]=${COMPREPLY[i]#"$colon_word"}
done
fi
}
function_exists __ltrim_colon_completions ||
__ltrim_colon_completions()
{
if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
# Remove colon-word prefix from COMPREPLY items
local colon_word=${1%${1##*:}}
local i=${#COMPREPLY[*]}
while [[ $((--i)) -ge 0 ]]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
done
fi
}
function_exists __find_mvn_projects ||
__find_mvn_projects()
{
find . -name 'pom.xml' -not -path '*/target/*' -prune | while read LINE ; do
local withoutPom=${LINE%/pom.xml}
local module=${withoutPom#./}
if [[ -z ${module} ]]; then
echo "."
else
echo ${module}
fi
done
}
function_exists _realpath ||
_realpath ()
{
if [[ -f "$1" ]]
then
# file *must* exist
if cd "$(echo "${1%/*}")" &>/dev/null
then
# file *may* not be local
# exception is ./file.ext
# try 'cd .; cd -;' *works!*
local tmppwd="$PWD"
cd - &>/dev/null
else
# file *must* be local
local tmppwd="$PWD"
fi
_omb_util_function_exists __find_mvn_projects ||
function __find_mvn_projects {
find . -name 'pom.xml' -not -path '*/target/*' -prune | while read LINE; do
local withoutPom=${LINE%/pom.xml}
local module=${withoutPom#./}
if [[ ! $module ]]; then
echo "."
else
# file *cannot* exist
return 1 # failure
echo $module
fi
done
}
_omb_util_function_exists _realpath ||
function _realpath {
if [[ -f $1 ]]; then
# file *must* exist
if cd "${1%/*}" &>/dev/null; then
# file *may* not be local
# exception is ./file.ext
# try 'cd .; cd -;' *works!*
local tmppwd=$PWD
cd - &>/dev/null
else
# file *must* be local
local tmppwd=$PWD
fi
else
# file *cannot* exist
return 1 # failure
fi
# suppress shell session termination messages on macOS
function shell_session_save {
false
}
# reassemble realpath
echo "$tmppwd/${1##*/}"
return 1 #success
}
_omb_util_function_exists __pom_hierarchy ||
function __pom_hierarchy {
local pom=$(_realpath "pom.xml")
POM_HIERARCHY+=("$pom")
while [[ $pom ]] && grep -q "<parent>" "$pom"; do
## look for a new relativePath for parent pom.xml
local parent_pom_relative=$(grep -e "<relativePath>.*</relativePath>" "$pom" | sed 's/.*<relativePath>//' | sed 's/<\/relativePath>.*//g')
## <parent> is present but not defined, assume ../pom.xml
if [[ ! $parent_pom_relative ]]; then
parent_pom_relative=../pom.xml
fi
# reassemble realpath
echo "$tmppwd"/"${1##*/}"
return 1 #success
}
function_exists __pom_hierarchy ||
__pom_hierarchy()
{
local pom=`_realpath "pom.xml"`
## if pom exists continue else break
parent_pom=$(_realpath "${pom%/*}/$parent_pom_relative")
if [[ $parent_pom ]]; then
pom=$parent_pom
else
break
fi
POM_HIERARCHY+=("$pom")
while [ -n "$pom" ] && grep -q "<parent>" "$pom"; do
## look for a new relativePath for parent pom.xml
local parent_pom_relative=`grep -e "<relativePath>.*</relativePath>" "$pom" | sed 's/.*<relativePath>//' | sed 's/<\/relativePath>.*//g'`
## <parent> is present but not defined, assume ../pom.xml
if [ -z "$parent_pom_relative" ]; then
parent_pom_relative="../pom.xml"
fi
## if pom exists continue else break
parent_pom=`_realpath "${pom%/*}/$parent_pom_relative"`
if [ -n "$parent_pom" ]; then
pom=$parent_pom
else
break
fi
POM_HIERARCHY+=("$pom")
done
done
}
_mvn()
{
local cur prev
COMPREPLY=()
POM_HIERARCHY=()
__pom_hierarchy
_get_comp_words_by_ref -n : cur prev
function _mvn {
local cur prev
COMPREPLY=()
POM_HIERARCHY=()
__pom_hierarchy
_get_comp_words_by_ref -n : cur prev
local opts="-am|-amd|-B|-C|-c|-cpu|-D|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-h|-l|-N|-npr|-npu|-nsu|-o|-P|-pl|-q|-rf|-s|-T|-t|-U|-up|-V|-v|-X"
local long_opts="--also-make|--also-make-dependents|--batch-mode|--strict-checksums|--lax-checksums|--check-plugin-updates|--define|--errors|--encrypt-master-password|--encrypt-password|--file|--fail-at-end|--fail-fast|--fail-never|--global-settings|--help|--log-file|--non-recursive|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--offline|--activate-profiles|--projects|--quiet|--resume-from|--settings|--threads|--toolchains|--update-snapshots|--update-plugins|--show-version|--version|--debug"
local opts="-am|-amd|-B|-C|-c|-cpu|-D|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-h|-l|-N|-npr|-npu|-nsu|-o|-P|-pl|-q|-rf|-s|-T|-t|-U|-up|-V|-v|-X"
local long_opts="--also-make|--also-make-dependents|--batch-mode|--strict-checksums|--lax-checksums|--check-plugin-updates|--define|--errors|--encrypt-master-password|--encrypt-password|--file|--fail-at-end|--fail-fast|--fail-never|--global-settings|--help|--log-file|--non-recursive|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--offline|--activate-profiles|--projects|--quiet|--resume-from|--settings|--threads|--toolchains|--update-snapshots|--update-plugins|--show-version|--version|--debug"
local common_clean_lifecycle="pre-clean|clean|post-clean"
local common_default_lifecycle="validate|initialize|generate-sources|process-sources|generate-resources|process-resources|compile|process-classes|generate-test-sources|process-test-sources|generate-test-resources|process-test-resources|test-compile|process-test-classes|test|prepare-package|package|pre-integration-test|integration-test|post-integration-test|verify|install|deploy"
local common_site_lifecycle="pre-site|site|post-site|site-deploy"
local common_lifecycle_phases="${common_clean_lifecycle}|${common_default_lifecycle}|${common_site_lifecycle}"
local common_clean_lifecycle="pre-clean|clean|post-clean"
local common_default_lifecycle="validate|initialize|generate-sources|process-sources|generate-resources|process-resources|compile|process-classes|generate-test-sources|process-test-sources|generate-test-resources|process-test-resources|test-compile|process-test-classes|test|prepare-package|package|pre-integration-test|integration-test|post-integration-test|verify|install|deploy"
local common_site_lifecycle="pre-site|site|post-site|site-deploy"
local common_lifecycle_phases="${common_clean_lifecycle}|${common_default_lifecycle}|${common_site_lifecycle}"
local plugin_goals_appengine="appengine:backends_configure|appengine:backends_delete|appengine:backends_rollback|appengine:backends_start|appengine:backends_stop|appengine:backends_update|appengine:debug|appengine:devserver|appengine:devserver_start|appengine:devserver_stop|appengine:endpoints_get_client_lib|appengine:endpoints_get_discovery_doc|appengine:enhance|appengine:rollback|appengine:set_default_version|appengine:start_module_version|appengine:stop_module_version|appengine:update|appengine:update_cron|appengine:update_dos|appengine:update_indexes|appengine:update_queues|appengine:vacuum_indexes"
local plugin_goals_android="android:apk|android:apklib|android:clean|android:deploy|android:deploy-dependencies|android:dex|android:emulator-start|android:emulator-stop|android:emulator-stop-all|android:generate-sources|android:help|android:instrument|android:manifest-update|android:pull|android:push|android:redeploy|android:run|android:undeploy|android:unpack|android:version-update|android:zipalign|android:devices"
local plugin_goals_ant="ant:ant|ant:clean"
local plugin_goals_antrun="antrun:run"
local plugin_goals_archetype="archetype:generate|archetype:create-from-project|archetype:crawl"
local plugin_goals_assembly="assembly:single|assembly:assembly"
local plugin_goals_build_helper="build-helper:add-resource|build-helper:add-source|build-helper:add-test-resource|build-helper:add-test-source|build-helper:attach-artifact|build-helper:bsh-property|build-helper:cpu-count|build-helper:help|build-helper:local-ip|build-helper:maven-version|build-helper:parse-version|build-helper:regex-properties|build-helper:regex-property|build-helper:released-version|build-helper:remove-project-artifact|build-helper:reserve-network-port|build-helper:timestamp-property"
local plugin_goals_buildnumber="buildnumber:create|buildnumber:create-timestamp|buildnumber:help|buildnumber:hgchangeset"
local plugin_goals_cargo="cargo:start|cargo:run|cargo:stop|cargo:deploy|cargo:undeploy|cargo:help"
local plugin_goals_checkstyle="checkstyle:checkstyle|checkstyle:check"
local plugin_goals_cobertura="cobertura:cobertura"
local plugin_goals_findbugs="findbugs:findbugs|findbugs:gui|findbugs:help"
local plugin_goals_dependency="dependency:analyze|dependency:analyze-dep-mgt|dependency:analyze-duplicate|dependency:analyze-only|dependency:analyze-report|dependency:build-classpath|dependency:copy|dependency:copy-dependencies|dependency:get|dependency:go-offline|dependency:help|dependency:list|dependency:list-repositories|dependency:properties|dependency:purge-local-repository|dependency:resolve|dependency:resolve-plugins|dependency:sources|dependency:tree|dependency:unpack|dependency:unpack-dependencies"
local plugin_goals_deploy="deploy:deploy-file"
local plugin_goals_ear="ear:ear|ear:generate-application-xml"
local plugin_goals_eclipse="eclipse:clean|eclipse:eclipse"
local plugin_goals_ejb="ejb:ejb"
local plugin_goals_enforcer="enforcer:enforce|enforcer:display-info"
local plugin_goals_exec="exec:exec|exec:java"
local plugin_goals_failsafe="failsafe:integration-test|failsafe:verify"
local plugin_goals_flyway="flyway:migrate|flyway:clean|flyway:info|flyway:validate|flyway:baseline|flyway:repair"
local plugin_goals_gpg="gpg:sign|gpg:sign-and-deploy-file"
local plugin_goals_grails="grails:clean|grails:config-directories|grails:console|grails:create-controller|grails:create-domain-class|grails:create-integration-test|grails:create-pom|grails:create-script|grails:create-service|grails:create-tag-lib|grails:create-unit-test|grails:exec|grails:generate-all|grails:generate-controller|grails:generate-views|grails:help|grails:init|grails:init-plugin|grails:install-templates|grails:list-plugins|grails:maven-clean|grails:maven-compile|grails:maven-functional-test|grails:maven-grails-app-war|grails:maven-test|grails:maven-war|grails:package|grails:package-plugin|grails:run-app|grails:run-app-https|grails:run-war|grails:set-version|grails:test-app|grails:upgrade|grails:validate|grails:validate-plugin|grails:war"
local plugin_goals_gwt="gwt:browser|gwt:clean|gwt:compile|gwt:compile-report|gwt:css|gwt:debug|gwt:eclipse|gwt:eclipseTest|gwt:generateAsync|gwt:help|gwt:i18n|gwt:mergewebxml|gwt:resources|gwt:run|gwt:run-codeserver|gwt:sdkInstall|gwt:source-jar|gwt:soyc|gwt:test"
local plugin_goals_help="help:active-profiles|help:all-profiles|help:describe|help:effective-pom|help:effective-settings|help:evaluate|help:expressions|help:help|help:system"
local plugin_goals_hibernate3="hibernate3:hbm2ddl|hibernate3:help"
local plugin_goals_idea="idea:clean|idea:idea"
local plugin_goals_install="install:install-file"
local plugin_goals_jacoco="jacoco:check|jacoco:dump|jacoco:help|jacoco:instrument|jacoco:merge|jacoco:prepare-agent|jacoco:prepare-agent-integration|jacoco:report|jacoco:report-integration|jacoco:restore-instrumented-classes"
local plugin_goals_javadoc="javadoc:javadoc|javadoc:jar|javadoc:aggregate"
local plugin_goals_jboss="jboss:start|jboss:stop|jboss:deploy|jboss:undeploy|jboss:redeploy"
local plugin_goals_jboss_as="jboss-as:add-resource|jboss-as:deploy|jboss-as:deploy-only|jboss-as:deploy-artifact|jboss-as:redeploy|jboss-as:redeploy-only|jboss-as:undeploy|jboss-as:undeploy-artifact|jboss-as:run|jboss-as:start|jboss-as:shutdown|jboss-as:execute-commands"
local plugin_goals_jetty="jetty:run|jetty:run-exploded|jetty:run-forked"
local plugin_goals_jetty="jetty:run|jetty:run-exploded|jetty:run-forked"
#mvn help:describe -Dplugin=com.google.cloud.tools:jib-maven-plugin:1.2.0
local plugin_goals_jib="jib:_skaffold-files|jib:_skaffold-files-v2|jib:_skaffold-package-goals|jib:build|jib:buildTar|jib:dockerBuild"
local plugin_goals_jxr="jxr:jxr"
local plugin_goals_license="license:format|license:check"
local plugin_goals_liquibase="liquibase:changelogSync|liquibase:changelogSyncSQL|liquibase:clearCheckSums|liquibase:dbDoc|liquibase:diff|liquibase:dropAll|liquibase:help|liquibase:migrate|liquibase:listLocks|liquibase:migrateSQL|liquibase:releaseLocks|liquibase:rollback|liquibase:rollbackSQL|liquibase:status|liquibase:tag|liquibase:update|liquibase:updateSQL|liquibase:updateTestingRollback"
local plugin_goals_nexus_staging="nexus-staging:close|nexus-staging:deploy|nexus-staging:deploy-staged|nexus-staging:deploy-staged-repository|nexus-staging:drop|nexus-staging:help|nexus-staging:promote|nexus-staging:rc-close|nexus-staging:rc-drop|nexus-staging:rc-list|nexus-staging:rc-list-profiles|nexus-staging:rc-promote|nexus-staging:rc-release|nexus-staging:release"
#mvn help:describe -Dplugin=io.quarkus:quarkus-maven-plugin:0.15.0
local plugin_goals_quarkus="quarkus:add-extension|quarkus:add-extensions|quarkus:analyze-call-tree|quarkus:build|quarkus:create|quarkus:create-example-config|quarkus:dev|quarkus:help|quarkus:list-extensions|quarkus:native-image|quarkus:remote-dev"
local plugin_goals_pmd="pmd:pmd|pmd:cpd|pmd:check|pmd:cpd-check"
local plugin_goals_properties="properties:read-project-properties|properties:write-project-properties|properties:write-active-profile-properties|properties:set-system-properties"
local plugin_goals_release="release:clean|release:prepare|release:rollback|release:perform|release:stage|release:branch|release:update-versions"
local plugin_goals_repository="repository:bundle-create|repository:bundle-pack|repository:help"
local plugin_goals_scala="scala:add-source|scala:cc|scala:cctest|scala:compile|scala:console|scala:doc|scala:doc-jar|scala:help|scala:run|scala:script|scala:testCompile"
local plugin_goals_scm="scm:add|scm:checkin|scm:checkout|scm:update|scm:status"
local plugin_goals_site="site:site|site:deploy|site:run|site:stage|site:stage-deploy"
local plugin_goals_sonar="sonar:sonar|sonar:help"
local plugin_goals_source="source:aggregate|source:jar|source:jar-no-fork"
local plugin_goals_surefire="surefire:test"
local plugin_goals_tomcat6="tomcat6:help|tomcat6:run|tomcat6:run-war|tomcat6:run-war-only|tomcat6:stop|tomcat6:deploy|tomcat6:undeploy"
local plugin_goals_tomcat7="tomcat7:help|tomcat7:run|tomcat7:run-war|tomcat7:run-war-only|tomcat7:deploy"
local plugin_goals_tomcat="tomcat:help|tomcat:start|tomcat:stop|tomcat:deploy|tomcat:undeploy"
local plugin_goals_liberty="liberty:create-server|liberty:start-server|liberty:stop-server|liberty:run-server|liberty:deploy|liberty:undeploy|liberty:java-dump-server|liberty:dump-server|liberty:package-server"
local plugin_goals_versions="versions:display-dependency-updates|versions:display-plugin-updates|versions:display-property-updates|versions:update-parent|versions:update-properties|versions:update-child-modules|versions:lock-snapshots|versions:unlock-snapshots|versions:resolve-ranges|versions:set|versions:use-releases|versions:use-next-releases|versions:use-latest-releases|versions:use-next-snapshots|versions:use-latest-snapshots|versions:use-next-versions|versions:use-latest-versions|versions:commit|versions:revert"
local plugin_goals_vertx="vertx:init|vertx:runMod|vertx:pullInDeps|vertx:fatJar"
local plugin_goals_war="war:war|war:exploded|war:inplace|war:manifest"
local plugin_goals_spring_boot="spring-boot:run|spring-boot:repackage"
local plugin_goals_jgitflow="jgitflow:feature-start|jgitflow:feature-finish|jgitflow:release-start|jgitflow:release-finish|jgitflow:hotfix-start|jgitflow:hotfix-finish|jgitflow:build-number"
local plugin_goals_wildfly="wildfly:add-resource|wildfly:deploy|wildfly:deploy-only|wildfly:deploy-artifact|wildfly:redeploy|wildfly:redeploy-only|wildfly:undeploy|wildfly:undeploy-artifact|wildfly:run|wildfly:start|wildfly:shutdown|wildfly:execute-commands"
local plugin_goals_appengine="appengine:backends_configure|appengine:backends_delete|appengine:backends_rollback|appengine:backends_start|appengine:backends_stop|appengine:backends_update|appengine:debug|appengine:devserver|appengine:devserver_start|appengine:devserver_stop|appengine:endpoints_get_client_lib|appengine:endpoints_get_discovery_doc|appengine:enhance|appengine:rollback|appengine:set_default_version|appengine:start_module_version|appengine:stop_module_version|appengine:update|appengine:update_cron|appengine:update_dos|appengine:update_indexes|appengine:update_queues|appengine:vacuum_indexes"
local plugin_goals_android="android:apk|android:apklib|android:clean|android:deploy|android:deploy-dependencies|android:dex|android:emulator-start|android:emulator-stop|android:emulator-stop-all|android:generate-sources|android:help|android:instrument|android:manifest-update|android:pull|android:push|android:redeploy|android:run|android:undeploy|android:unpack|android:version-update|android:zipalign|android:devices"
local plugin_goals_ant="ant:ant|ant:clean"
local plugin_goals_antrun="antrun:run"
local plugin_goals_archetype="archetype:generate|archetype:create-from-project|archetype:crawl"
local plugin_goals_assembly="assembly:single|assembly:assembly"
local plugin_goals_build_helper="build-helper:add-resource|build-helper:add-source|build-helper:add-test-resource|build-helper:add-test-source|build-helper:attach-artifact|build-helper:bsh-property|build-helper:cpu-count|build-helper:help|build-helper:local-ip|build-helper:maven-version|build-helper:parse-version|build-helper:regex-properties|build-helper:regex-property|build-helper:released-version|build-helper:remove-project-artifact|build-helper:reserve-network-port|build-helper:timestamp-property"
local plugin_goals_buildnumber="buildnumber:create|buildnumber:create-timestamp|buildnumber:help|buildnumber:hgchangeset"
local plugin_goals_cargo="cargo:start|cargo:run|cargo:stop|cargo:deploy|cargo:undeploy|cargo:help"
local plugin_goals_checkstyle="checkstyle:checkstyle|checkstyle:check"
local plugin_goals_cobertura="cobertura:cobertura"
local plugin_goals_findbugs="findbugs:findbugs|findbugs:gui|findbugs:help"
local plugin_goals_dependency="dependency:analyze|dependency:analyze-dep-mgt|dependency:analyze-duplicate|dependency:analyze-only|dependency:analyze-report|dependency:build-classpath|dependency:copy|dependency:copy-dependencies|dependency:get|dependency:go-offline|dependency:help|dependency:list|dependency:list-repositories|dependency:properties|dependency:purge-local-repository|dependency:resolve|dependency:resolve-plugins|dependency:sources|dependency:tree|dependency:unpack|dependency:unpack-dependencies"
local plugin_goals_deploy="deploy:deploy-file"
local plugin_goals_ear="ear:ear|ear:generate-application-xml"
local plugin_goals_eclipse="eclipse:clean|eclipse:eclipse"
local plugin_goals_ejb="ejb:ejb"
local plugin_goals_enforcer="enforcer:enforce|enforcer:display-info"
local plugin_goals_exec="exec:exec|exec:java"
local plugin_goals_failsafe="failsafe:integration-test|failsafe:verify"
local plugin_goals_flyway="flyway:migrate|flyway:clean|flyway:info|flyway:validate|flyway:baseline|flyway:repair"
local plugin_goals_gpg="gpg:sign|gpg:sign-and-deploy-file"
local plugin_goals_grails="grails:clean|grails:config-directories|grails:console|grails:create-controller|grails:create-domain-class|grails:create-integration-test|grails:create-pom|grails:create-script|grails:create-service|grails:create-tag-lib|grails:create-unit-test|grails:exec|grails:generate-all|grails:generate-controller|grails:generate-views|grails:help|grails:init|grails:init-plugin|grails:install-templates|grails:list-plugins|grails:maven-clean|grails:maven-compile|grails:maven-functional-test|grails:maven-grails-app-war|grails:maven-test|grails:maven-war|grails:package|grails:package-plugin|grails:run-app|grails:run-app-https|grails:run-war|grails:set-version|grails:test-app|grails:upgrade|grails:validate|grails:validate-plugin|grails:war"
local plugin_goals_gwt="gwt:browser|gwt:clean|gwt:compile|gwt:compile-report|gwt:css|gwt:debug|gwt:eclipse|gwt:eclipseTest|gwt:generateAsync|gwt:help|gwt:i18n|gwt:mergewebxml|gwt:resources|gwt:run|gwt:run-codeserver|gwt:sdkInstall|gwt:source-jar|gwt:soyc|gwt:test"
local plugin_goals_help="help:active-profiles|help:all-profiles|help:describe|help:effective-pom|help:effective-settings|help:evaluate|help:expressions|help:help|help:system"
local plugin_goals_hibernate3="hibernate3:hbm2ddl|hibernate3:help"
local plugin_goals_idea="idea:clean|idea:idea"
local plugin_goals_install="install:install-file"
local plugin_goals_jacoco="jacoco:check|jacoco:dump|jacoco:help|jacoco:instrument|jacoco:merge|jacoco:prepare-agent|jacoco:prepare-agent-integration|jacoco:report|jacoco:report-integration|jacoco:restore-instrumented-classes"
local plugin_goals_javadoc="javadoc:javadoc|javadoc:jar|javadoc:aggregate"
local plugin_goals_jboss="jboss:start|jboss:stop|jboss:deploy|jboss:undeploy|jboss:redeploy"
local plugin_goals_jboss_as="jboss-as:add-resource|jboss-as:deploy|jboss-as:deploy-only|jboss-as:deploy-artifact|jboss-as:redeploy|jboss-as:redeploy-only|jboss-as:undeploy|jboss-as:undeploy-artifact|jboss-as:run|jboss-as:start|jboss-as:shutdown|jboss-as:execute-commands"
local plugin_goals_jetty="jetty:run|jetty:run-war|jetty:run-exploded|jetty:deploy-war|jetty:run-forked|jetty:start|jetty:stop|jetty:effective-web-xml"
local plugin_goals_jxr="jxr:jxr"
local plugin_goals_license="license:format|license:check"
local plugin_goals_liquibase="liquibase:changelogSync|liquibase:changelogSyncSQL|liquibase:clearCheckSums|liquibase:dbDoc|liquibase:diff|liquibase:dropAll|liquibase:help|liquibase:migrate|liquibase:listLocks|liquibase:migrateSQL|liquibase:releaseLocks|liquibase:rollback|liquibase:rollbackSQL|liquibase:status|liquibase:tag|liquibase:update|liquibase:updateSQL|liquibase:updateTestingRollback"
local plugin_goals_nexus_staging="nexus-staging:close|nexus-staging:deploy|nexus-staging:deploy-staged|nexus-staging:deploy-staged-repository|nexus-staging:drop|nexus-staging:help|nexus-staging:promote|nexus-staging:rc-close|nexus-staging:rc-drop|nexus-staging:rc-list|nexus-staging:rc-list-profiles|nexus-staging:rc-promote|nexus-staging:rc-release|nexus-staging:release"
local plugin_goals_pmd="pmd:pmd|pmd:cpd|pmd:check|pmd:cpd-check"
local plugin_goals_properties="properties:read-project-properties|properties:write-project-properties|properties:write-active-profile-properties|properties:set-system-properties"
local plugin_goals_release="release:clean|release:prepare|release:rollback|release:perform|release:stage|release:branch|release:update-versions"
local plugin_goals_repository="repository:bundle-create|repository:bundle-pack|repository:help"
local plugin_goals_scala="scala:add-source|scala:cc|scala:cctest|scala:compile|scala:console|scala:doc|scala:doc-jar|scala:help|scala:run|scala:script|scala:testCompile"
local plugin_goals_scm="scm:add|scm:checkin|scm:checkout|scm:update|scm:status"
local plugin_goals_site="site:site|site:deploy|site:run|site:stage|site:stage-deploy"
local plugin_goals_sonar="sonar:sonar|sonar:help"
local plugin_goals_source="source:aggregate|source:jar|source:jar-no-fork"
local plugin_goals_spotbugs="spotbugs:spotbugs|spotbugs:check|spotbugs:gui|spotbugs:help"
local plugin_goals_surefire="surefire:test"
local plugin_goals_tomcat6="tomcat6:help|tomcat6:run|tomcat6:run-war|tomcat6:run-war-only|tomcat6:stop|tomcat6:deploy|tomcat6:redeploy|tomcat6:undeploy"
local plugin_goals_tomcat7="tomcat7:help|tomcat7:run|tomcat7:run-war|tomcat7:run-war-only|tomcat7:deploy|tomcat7:redeploy|tomcat7:undeploy"
local plugin_goals_tomcat="tomcat:help|tomcat:start|tomcat:stop|tomcat:deploy|tomcat:undeploy"
local plugin_goals_liberty="liberty:create-server|liberty:start-server|liberty:stop-server|liberty:run-server|liberty:deploy|liberty:undeploy|liberty:java-dump-server|liberty:dump-server|liberty:package-server"
local plugin_goals_versions="versions:display-dependency-updates|versions:display-plugin-updates|versions:display-property-updates|versions:update-parent|versions:update-properties|versions:update-child-modules|versions:lock-snapshots|versions:unlock-snapshots|versions:resolve-ranges|versions:set|versions:use-releases|versions:use-next-releases|versions:use-latest-releases|versions:use-next-snapshots|versions:use-latest-snapshots|versions:use-next-versions|versions:use-latest-versions|versions:commit|versions:revert"
local plugin_goals_vertx="vertx:init|vertx:runMod|vertx:pullInDeps|vertx:fatJar"
local plugin_goals_war="war:war|war:exploded|war:inplace|war:manifest"
local plugin_goals_spring_boot="spring-boot:run|spring-boot:repackage"
local plugin_goals_jgitflow="jgitflow:feature-start|jgitflow:feature-finish|jgitflow:release-start|jgitflow:release-finish|jgitflow:hotfix-start|jgitflow:hotfix-finish|jgitflow:build-number"
local plugin_goals_wildfly="wildfly:add-resource|wildfly:deploy|wildfly:deploy-only|wildfly:deploy-artifact|wildfly:redeploy|wildfly:redeploy-only|wildfly:undeploy|wildfly:undeploy-artifact|wildfly:run|wildfly:start|wildfly:shutdown|wildfly:execute-commands"
local plugin_goals_formatter="formatter:format|formatter:help|formatter:validate"
## some plugin (like jboss-as) has '-' which is not allowed in shell var name, to use '_' then replace
local common_plugins=`compgen -v | grep "^plugin_goals_.*" | sed 's/plugin_goals_//g' | tr '_' '-' | tr '\n' '|'`
## some plugin (like jboss-as) has '-' which is not allowed in shell var name, to use '_' then replace
local common_plugins=$(compgen -v | grep "^plugin_goals_.*" | sed 's/plugin_goals_//g' | tr '_' '-' | tr '\n' '|')
local options="-Dmaven.test.skip=true|-DskipTests|-DskipITs|-Dtest|-Dit.test|-DfailIfNoTests|-Dmaven.surefire.debug|-DenableCiProfile|-Dpmd.skip=true|-Dcheckstyle.skip=true|-Dtycho.mode=maven|-Dmaven.javadoc.skip=true|-Dgwt.compiler.skip|-Dcobertura.skip=true|-Dfindbugs.skip=true||-DperformRelease=true|-Dgpg.skip=true|-DforkCount"
local options="-Dmaven.test.skip=true|-DskipTests|-DskipITs|-Dtest|-Dit.test|-DfailIfNoTests|-Dmaven.surefire.debug|-DenableCiProfile|-Dpmd.skip=true|-Dcheckstyle.skip=true|-Dtycho.mode=maven|-Dmaven.javadoc.skip=true|-Dgwt.compiler.skip|-Dcobertura.skip=true|-Dfindbugs.skip=true||-DperformRelease=true|-Dgpg.skip=true|-DforkCount"
local profile_settings=`[ -e ~/.m2/settings.xml ] && grep -e "<profile>" -A 1 ~/.m2/settings.xml | grep -e "<id>.*</id>" | sed 's/.*<id>//' | sed 's/<\/id>.*//g' | tr '\n' '|' `
local profile_settings=$([[ -e ~/.m2/settings.xml ]] && grep -e "<profile>" -A 1 ~/.m2/settings.xml | grep -e "<id>.*</id>" | sed 's/.*<id>//' | sed 's/<\/id>.*//g' | tr '\n' '|')
local profiles="${profile_settings}|"
for item in ${POM_HIERARCHY[*]}
do
local profile_pom=`[ -e $item ] && grep -e "<profile>" -A 1 $item | grep -e "<id>.*</id>" | sed 's/.*<id>//' | sed 's/<\/id>.*//g' | tr '\n' '|' `
local profiles="${profiles}|${profile_pom}"
done
local profiles="$profile_settings|"
for item in ${POM_HIERARCHY[*]}; do
local profile_pom=$([[ -e $item ]] && grep -e "<profile>" -A 1 $item | grep -e "<id>.*</id>" | sed 's/.*<id>//' | sed 's/<\/id>.*//g' | tr '\n' '|')
local profiles="$profiles|$profile_pom"
done
local IFS=$'|\n'
local IFS=$'|\n'
if [[ ${cur} == -D* ]] ; then
COMPREPLY=( $(compgen -S ' ' -W "${options}" -- ${cur}) )
elif [[ ${prev} == -P ]] ; then
if [[ ${cur} == *,* ]] ; then
COMPREPLY=( $(compgen -S ',' -W "${profiles}" -P "${cur%,*}," -- ${cur##*,}) )
else
COMPREPLY=( $(compgen -S ',' -W "${profiles}" -- ${cur}) )
fi
elif [[ ${cur} == --* ]] ; then
COMPREPLY=( $(compgen -W "${long_opts}" -S ' ' -- ${cur}) )
elif [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -S ' ' -- ${cur}) )
elif [[ ${prev} == -pl ]] ; then
if [[ ${cur} == *,* ]] ; then
COMPREPLY=( $(compgen -W "$(__find_mvn_projects)" -S ',' -P "${cur%,*}," -- ${cur##*,}) )
else
COMPREPLY=( $(compgen -W "$(__find_mvn_projects)" -S ',' -- ${cur}) )
fi
elif [[ ${prev} == -rf || ${prev} == --resume-from ]] ; then
COMPREPLY=( $(compgen -d -S ' ' -- ${cur}) )
elif [[ ${cur} == *:* ]] ; then
local plugin
for plugin in $common_plugins; do
if [[ ${cur} == ${plugin}:* ]]; then
## note that here is an 'unreplace', see the comment at common_plugins
var_name="plugin_goals_${plugin//-/_}"
COMPREPLY=( $(compgen -W "${!var_name}" -S ' ' -- ${cur}) )
fi
done
if [[ $cur == -D* ]] ; then
COMPREPLY=( $(compgen -S ' ' -W "$options" -- "$cur") )
elif [[ $prev == -P ]] ; then
if [[ $cur == *,* ]] ; then
COMPREPLY=( $(compgen -S ',' -W "$profiles" -P "${cur%,*}," -- ${cur##*,}) )
else
if echo "${common_lifecycle_phases}" | tr '|' '\n' | grep -q -e "^${cur}" ; then
COMPREPLY=( $(compgen -S ' ' -W "${common_lifecycle_phases}" -- ${cur}) )
elif echo "${common_plugins}" | tr '|' '\n' | grep -q -e "^${cur}"; then
COMPREPLY=( $(compgen -S ':' -W "${common_plugins}" -- ${cur}) )
fi
COMPREPLY=( $(compgen -S ',' -W "$profiles" -- "$cur") )
fi
__ltrim_colon_completions "$cur"
elif [[ $cur == --* ]] ; then
COMPREPLY=( $(compgen -W "$long_opts" -S ' ' -- "$cur") )
elif [[ $cur == -* ]] ; then
COMPREPLY=( $(compgen -W "$opts" -S ' ' -- "$cur") )
elif [[ $prev == -pl ]] ; then
if [[ $cur == *,* ]] ; then
COMPREPLY=( $(compgen -W "$(__find_mvn_projects)" -S ',' -P "${cur%,*}," -- ${cur##*,}) )
else
COMPREPLY=( $(compgen -W "$(__find_mvn_projects)" -S ',' -- "$cur") )
fi
elif [[ $prev == -rf || $prev == --resume-from ]] ; then
COMPREPLY=( $(compgen -d -S ' ' -- "$cur") )
elif [[ $cur == *:* ]] ; then
local plugin
for plugin in $common_plugins; do
if [[ $cur == $plugin:* ]]; then
## note that here is an 'unreplace', see the comment at common_plugins
var_name="plugin_goals_${plugin//-/_}"
COMPREPLY=( $(compgen -W "${!var_name}" -S ' ' -- "$cur") )
fi
done
else
if <<< "$common_lifecycle_phases" tr '|' '\n' | grep -q -e "^$cur" ; then
COMPREPLY=( $(compgen -S ' ' -W "$common_lifecycle_phases" -- "$cur") )
elif <<< "$common_plugins" tr '|' '\n' | grep -q -e "^$cur"; then
COMPREPLY=( $(compgen -S ':' -W "$common_plugins" -- "$cur") )
fi
fi
__ltrim_colon_completions "$cur"
}
complete -o default -F _mvn -o nospace mvn
complete -o default -F _mvn -o nospace mvnDebug
complete -o default -F _mvn -o nospace mvnw

View File

@ -1,4 +1,8 @@
#! bash oh-my-bash.module
#
# The current version corresponds to the following upstream version:
# https://github.com/saltstack/salt/blob/18ca4fdfa9e9c16fb10006f1221254707bece308/pkg/common/salt.bash
#------------------------------------------------------------------------------
# written by David Pravec
# - feel free to /msg alekibango on IRC if you want to talk about this file
@ -9,118 +13,161 @@
# TODO: --compound[tab] -- how?
# TODO: use history to extract some words, esp. if ${cur} is empty
# TODO: TEST EVERYTHING a lot
# TODO: cache results of some functions? where? how long?
# TODO: is it ok to use '--timeout 2' ?
function _salt_get_grains {
if [ "$1" = 'local' ] ; then
salt-call --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g'
else
salt '*' --timeout 2 --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" |sed 's:\([a-z0-9]\) :\1\: :g'
fi
if [[ $1 == 'local' ]]; then
salt-call --log-level=error --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" | sed 's:\([a-z0-9]\) :\1\: :g'
else
salt '*' --timeout 2 --hide-timeout --log-level=error --out=txt -- grains.ls | sed 's/^.*\[//' | tr -d ",']" | sed 's:\([a-z0-9]\) :\1\: :g'
fi
}
function _salt_get_grain_values {
if [ "$1" = 'local' ] ; then
salt-call --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$'
else
salt '*' --timeout 2 --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$'
fi
if [[ $1 == 'local' ]]; then
salt-call --log-level=error --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$'
else
salt '*' --timeout 2 --hide-timeout --log-level=error --out=txt -- grains.item $1 |sed 's/^\S*:\s//' |grep -v '^\s*$'
fi
}
function _salt_get_keys {
local type
for type in $*; do
# remove header from data:
salt-key --no-color -l "$type" | tail -n+2
done
}
function _salt_list_functions {
# salt-call: get all functions on this minion
# salt: get all functions on all minions
# sed: remove all array overhead and convert to newline separated list
# sort: chop out doubled entries, so overhead is minimal later during actual completion
if [[ $1 == 'local' ]]; then
salt-call --log-level=quiet --out=txt -- sys.list_functions |
sed "s/^.*\[//;s/[],']//g;s/ /\n/g" |
sort -u
else
salt '*' --timeout 2 --hide-timeout --log-level=quiet --out=txt -- sys.list_functions |
sed "s/^.*\[//;s/[],']//g;s/ /\n/g" |
sort -u
fi
}
function _salt_get_coms {
CACHE_DIR=$HOME/.cache/salt-$1-comp-cache_functions
local _salt_cache_functions=${SALT_COMP_CACHE_FUNCTIONS:=$CACHE_DIR}
local _salt_cache_timeout=${SALT_COMP_CACHE_TIMEOUT:='last hour'}
if [[ ! -d $(dirname $_salt_cache_functions) ]]; then
mkdir -p "$(dirname $_salt_cache_functions)"
fi
# Regenerate cache if timed out
if [[ $(stat --format=%Z $_salt_cache_functions 2>/dev/null) -lt $(date --date="$_salt_cache_timeout" +%s) ]]; then
_salt_list_functions $1 > "$_salt_cache_functions"
fi
# filter results, to only print the part to next dot (or end of function)
sed 's/^\('"$cur"'\(\.\|[^.]*\)\)\?.*/\1/' "$_salt_cache_functions" | sort -u
}
function _salt {
local cur prev opts pprev ppprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ ${COMP_CWORD} -gt 2 ]; then
pprev="${COMP_WORDS[COMP_CWORD-2]}"
fi
if [ ${COMP_CWORD} -gt 3 ]; then
ppprev="${COMP_WORDS[COMP_CWORD-3]}"
fi
local cur prev opts pprev ppprev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if ((COMP_CWORD > 2)); then
pprev=${COMP_WORDS[COMP_CWORD-2]}
fi
if ((COMP_CWORD > 3)); then
ppprev=${COMP_WORDS[COMP_CWORD-3]}
fi
opts="-h --help -d --doc --documentation --version --versions-report -c \
--config-dir= -v --verbose -t --timeout= -s --static -b --batch= \
--batch-size= -E --pcre -L --list -G --grain --grain-pcre -N \
--nodegroup -R --range -C --compound -I --pillar \
--return= -a --auth= --eauth= --extended-auth= -T --make-token -S \
--ipcidr --out=pprint --out=yaml --out=overstatestage --out=json \
--out=raw --out=highstate --out=key --out=txt --no-color --out-indent= "
opts="-h --help -d --doc --documentation --version --versions-report -c \
--config-dir= -v --verbose -t --timeout= -s --static -b --batch= \
--batch-size= -E --pcre -L --list -G --grain --grain-pcre -N \
--nodegroup -R --range -C --compound -I --pillar \
--return= -a --auth= --eauth= --extended-auth= -T --make-token -S \
--ipcidr --out=pprint --out=yaml --out=overstatestage --out=json \
--out=raw --out=highstate --out=key --out=txt --no-color --out-indent= "
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
if [[ $cur == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
# 2 special cases for filling up grain values
case "${pprev}" in
-G|--grain|--grain-pcre)
if [ "${cur}" = ":" ]; then
COMPREPLY=($(compgen -W '$(_salt_get_grain_values "$prev")'))
return 0
# 2 special cases for filling up grain values
case $pprev in
-G|--grain|--grain-pcre)
if [[ $cur == ":" ]]; then
COMPREPLY=($(compgen -W '$(_salt_get_grain_values "$prev")'))
return 0
fi
;;
esac
case "${ppprev}" in
-G|--grain|--grain-pcre)
if [ "${prev}" = ":" ]; then
COMPREPLY=($(compgen -W '$(_salt_get_grain_values "$pprev")' -- "$cur"))
return 0
fi
esac
case $ppprev in
-G|--grain|--grain-pcre)
if [[ $prev == ":" ]]; then
COMPREPLY=($(compgen -W '$(_salt_get_grain_values "$pprev")' -- "$cur"))
return 0
fi
;;
esac
esac
if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then
prev="${pprev}"
fi
if [[ $cur == "=" && $prev == --* ]]; then
cur=""
fi
if [[ $prev == "=" && $pprev == --* ]]; then
prev=$pprev
fi
case "${prev}" in
-c|--config)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
salt)
COMPREPLY=($(compgen -W "\'*\' \$opts \$(salt-key --no-color -l acc)" -- "$cur"))
return 0
;;
-E|--pcre)
COMPREPLY=($(compgen -W '$(salt-key --no-color -l acc)' -- "$cur"))
return 0
;;
-G|--grain|--grain-pcre)
COMPREPLY=($(compgen -W '$(_salt_get_grains)' -- "$cur"))
return 0
;;
-C|--compound)
COMPREPLY=() # TODO: finish this one? how?
return 0
;;
-t|--timeout)
COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 60 90 120 180" -- "$cur"))
return 0
;;
-b|--batch|--batch-size)
COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 50 60 70 80 90 100 120 150 200"))
return 0
;;
-N|--nodegroup)
local MASTER_CONFIG='/etc/salt/master'
local all=$(awk -F ':' 'BEGIN {print_line = 0}; /^nodegroups/ {print_line = 1;getline } print_line && /^ */ {print $1} /^[^ ]/ {print_line = 0}' < "$MASTER_CONFIG")
COMPREPLY=($(compgen -W '$all' -- "$cur"))
return 0
;;
esac
local _salt_coms=$(salt '*' --timeout 2 --out=txt -- sys.list_functions | sed 's/^.*\[//' | tr -d ",']" )
local all="${opts} ${_salt_coms}"
case $prev in
-c|--config)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
salt)
COMPREPLY=($(compgen -W "\'*\' \$opts \$(_salt_get_keys acc)" -- "$cur"))
return 0
;;
-E|--pcre)
COMPREPLY=($(compgen -W '$(_salt_get_keys acc)' -- "$cur"))
return 0
;;
-G|--grain|--grain-pcre)
COMPREPLY=($(compgen -W '$(_salt_get_grains)' -- "$cur"))
return 0
;;
-C|--compound)
COMPREPLY=() # TODO: finish this one? how?
return 0
;;
-t|--timeout)
COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 60 90 120 180" -- "$cur"))
return 0
;;
-b|--batch|--batch-size)
COMPREPLY=($(compgen -W "1 2 3 4 5 6 7 8 9 10 15 20 30 40 50 60 70 80 90 100 120 150 200"))
return 0
;;
-N|--nodegroup)
local MASTER_CONFIG='/etc/salt/master'
local all=$(awk -F ':' 'BEGIN {print_line = 0}; /^nodegroups/ {print_line = 1;getline } print_line && /^ */ {print $1} /^[^ ]/ {print_line = 0}' < "$MASTER_CONFIG")
COMPREPLY=($(compgen -W '$all' -- "$cur"))
return 0
;;
esac
local _salt_coms=$(_salt_get_coms remote)
# If there are still dots in the suggestion, do not append space
grep "^$cur.*\." "$_salt_coms" &>/dev/null && compopt -o nospace
local all="$opts $_salt_coms"
COMPREPLY=($(compgen -W '$all' -- "$cur"))
return 0
}
@ -129,202 +176,206 @@ complete -F _salt salt
function _saltkey {
local cur prev opts prev pprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-c --config-dir= -h --help --version --versions-report -q --quiet \
-y --yes --gen-keys= --gen-keys-dir= --keysize= --key-logfile= \
-l --list= -L --list-all -a --accept= -A --accept-all \
-r --reject= -R --reject-all -p --print= -P --print-all \
-d --delete= -D --delete-all -f --finger= -F --finger-all \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [ ${COMP_CWORD} -gt 2 ]; then
pprev="${COMP_WORDS[COMP_CWORD-2]}"
fi
if [ ${COMP_CWORD} -gt 3 ]; then
ppprev="${COMP_WORDS[COMP_CWORD-3]}"
fi
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then
prev="${pprev}"
fi
case "${prev}" in
-a|--accept)
COMPREPLY=($(compgen -W '$(salt-key -l un --no-color; salt-key -l rej --no-color)' -- "$cur"))
return 0
;;
-r|--reject)
COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color)' -- "$cur"))
return 0
;;
-d|--delete)
COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)' -- "$cur"))
return 0
;;
-c|--config)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
--keysize)
COMPREPLY=($(compgen -W "2048 3072 4096 5120 6144" -- "$cur"))
return 0
;;
--gen-keys)
return 0
;;
--gen-keys-dir)
COMPREPLY=($(compgen -d -- "$cur"))
return 0
;;
-p|--print)
COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color; salt-key -l un --no-color; salt-key -l rej --no-color)' -- "$cur"))
return 0
;;
-l|--list)
COMPREPLY=($(compgen -W "pre un acc accepted unaccepted rej rejected all" -- "$cur"))
return 0
;;
--accept-all)
return 0
;;
esac
local cur prev opts prev pprev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts="-c --config-dir= -h --help --version --versions-report -q --quiet \
-y --yes --gen-keys= --gen-keys-dir= --keysize= --key-logfile= \
-l --list= -L --list-all -a --accept= -A --accept-all \
-r --reject= -R --reject-all -p --print= -P --print-all \
-d --delete= -D --delete-all -f --finger= -F --finger-all \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if ((COMP_CWORD > 2)); then
pprev=${COMP_WORDS[COMP_CWORD-2]}
fi
if ((COMP_CWORD > 3)); then
ppprev=${COMP_WORDS[COMP_CWORD-3]}
fi
if [[ $cur == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
if [[ $cur == "=" && $prev == --* ]]; then
cur=""
fi
if [[ $prev == "=" && $pprev == --* ]]; then
prev=$pprev
fi
case $prev in
-a|--accept)
COMPREPLY=($(compgen -W '$(_salt_get_keys un rej)' -- "$cur"))
return 0
;;
-r|--reject)
COMPREPLY=($(compgen -W '$(_salt_get_keys acc)' -- "$cur"))
return 0
;;
-d|--delete)
COMPREPLY=($(compgen -W '$(_salt_get_keys acc un rej)' -- "$cur"))
return 0
;;
-c|--config)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
--keysize)
COMPREPLY=($(compgen -W "2048 3072 4096 5120 6144" -- "$cur"))
return 0
;;
--gen-keys)
return 0
;;
--gen-keys-dir)
COMPREPLY=($(compgen -d -- "$cur"))
return 0
;;
-p|--print)
COMPREPLY=($(compgen -W '$(_salt_get_keys acc un rej)' -- "$cur"))
return 0
;;
-l|--list)
COMPREPLY=($(compgen -W "pre un acc accepted unaccepted rej rejected all" -- "$cur"))
return 0
;;
--accept-all)
return 0
;;
esac
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
}
complete -F _saltkey salt-key
function _saltcall {
local cur prev opts pprev ppprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-h --help -d --doc --documentation --version --versions-report \
-m --module-dirs= -g --grains --return= --local -c --config-dir= -l --log-level= \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [ ${COMP_CWORD} -gt 2 ]; then
pprev="${COMP_WORDS[COMP_CWORD-2]}"
fi
if [ ${COMP_CWORD} -gt 3 ]; then
ppprev="${COMP_WORDS[COMP_CWORD-3]}"
fi
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
if [ "${cur}" = "=" ] && [[ ${prev} == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ ${pprev} == --* ]]; then
prev="${pprev}"
fi
case ${prev} in
-m|--module-dirs)
COMPREPLY=($(compgen -d -- "$cur"))
return 0
;;
-l|--log-level)
COMPREPLY=($(compgen -W "info none garbage trace warning error debug" -- "$cur"))
return 0
;;
-g|grains)
return 0
;;
salt-call)
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
;;
esac
local _salt_coms=$(salt-call --out=txt -- sys.list_functions|sed 's/^.*\[//' | tr -d ",']")
COMPREPLY=($(compgen -W '$opts $_salt_coms' -- "$cur"))
local cur prev opts pprev ppprev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts="-h --help -d --doc --documentation --version --versions-report \
-m --module-dirs= -g --grains --return= --local -c --config-dir= -l --log-level= \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if ((COMP_CWORD > 2)); then
pprev=${COMP_WORDS[COMP_CWORD-2]}
fi
if ((COMP_CWORD > 3)); then
ppprev=${COMP_WORDS[COMP_CWORD-3]}
fi
if [[ $cur == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
if [[ $cur == "=" && $prev == --* ]]; then
cur=""
fi
if [[ $prev == "=" && $pprev == --* ]]; then
prev=$pprev
fi
case $prev in
-m|--module-dirs)
COMPREPLY=($(compgen -d -- "$cur"))
return 0
;;
-l|--log-level)
COMPREPLY=($(compgen -W "info none garbage trace warning error debug" -- "$cur"))
return 0
;;
-g|grains)
return 0
;;
salt-call)
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
;;
esac
local _salt_coms=$(_salt_get_coms local)
# If there are still dots in the suggestion, do not append space
grep "^$cur.*\." "$_salt_coms" &>/dev/null && compopt -o nospace
COMPREPLY=($(compgen -W '$opts $_salt_coms' -- "$cur"))
return 0
}
complete -F _saltcall salt-call
function _saltcp {
local cur prev opts target prefpart postpart helper filt pprev ppprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-t --timeout= -s --static -b --batch= --batch-size= \
-h --help --version --versions-report -c --config-dir= \
-E --pcre -L --list -G --grain --grain-pcre -N --nodegroup \
-R --range -C --compound -I --pillar \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [[ "${cur}" == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
local cur prev opts target prefpart postpart helper filt pprev ppprev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts="-t --timeout= -s --static -b --batch= --batch-size= \
-h --help --version --versions-report -c --config-dir= \
-E --pcre -L --list -G --grain --grain-pcre -N --nodegroup \
-R --range -C --compound -I --pillar \
--out=pprint --out=yaml --out=overstatestage --out=json --out=raw \
--out=highstate --out=key --out=txt --no-color --out-indent= "
if [[ $cur == -* ]] ; then
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
return 0
fi
if [ "${cur}" = "=" ] && [[ "${prev}" == --* ]]; then
cur=""
fi
if [ "${prev}" = "=" ] && [[ "${pprev}" == --* ]]; then
prev=${pprev}
fi
if [[ $cur == "=" && $prev == --* ]]; then
cur=""
fi
if [[ $prev == "=" && $pprev == --* ]]; then
prev=$pprev
fi
case ${prev} in
salt-cp)
COMPREPLY=($(compgen -W '$opts $(salt-key -l acc --no-color)' -- "$cur"))
return 0
;;
-t|--timeout)
# those numbers are just a hint
COMPREPLY=($(compgen -W "2 3 4 8 10 15 20 25 30 40 60 90 120 180 240 300" -- "$cur"))
return 0
;;
-E|--pcre)
COMPREPLY=($(compgen -W '$(salt-key -l acc --no-color)' -- "$cur"))
return 0
;;
-L|--list)
# IMPROVEMENTS ARE WELCOME
prefpart="${cur%,*},"
postpart=${cur##*,}
filt="^\($(echo ${cur}| sed 's:,:\\|:g')\)$"
helper=($(salt-key -l acc --no-color | grep -v "${filt}" | sed "s/^/${prefpart}/"))
COMPREPLY=($(compgen -W '"${helper[@]}"' -- "$cur"))
case $prev in
salt-cp)
COMPREPLY=($(compgen -W '$opts $(_salt_get_keys acc)' -- "$cur"))
return 0
;;
-t|--timeout)
# those numbers are just a hint
COMPREPLY=($(compgen -W "2 3 4 8 10 15 20 25 30 40 60 90 120 180 240 300" -- "$cur"))
return 0
;;
-E|--pcre)
COMPREPLY=($(compgen -W '$(_salt_get_keys acc)' -- "$cur"))
return 0
;;
-L|--list)
# IMPROVEMENTS ARE WELCOME
prefpart=${cur%,*},
postpart=${cur##*,}
filt="^\($(sed 's:,:\\|:g' <<< "$cur")\)$"
helper=($(_salt_get_keys acc | grep -v "$filt" | sed "s/^/$prefpart/"))
COMPREPLY=($(compgen -W '"${helper[@]}"' -- "$cur"))
return 0
;;
-G|--grain|--grain-pcre)
COMPREPLY=($(compgen -W '$(_salt_get_grains)' -- "$cur"))
return 0
;;
# FIXME
-R|--range)
# FIXME ??
return 0
;;
-C|--compound)
# FIXME ??
return 0
;;
-c|--config)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
esac
return 0
;;
-G|--grain|--grain-pcre)
COMPREPLY=($(compgen -W '$(_salt_get_grains)' -- "$cur"))
return 0
;;
# FIXME
-R|--range)
# FIXME ??
return 0
;;
-C|--compound)
# FIXME ??
return 0
;;
-c|--config)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
esac
# default is using opts:
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
# default is using opts:
COMPREPLY=($(compgen -W '$opts' -- "$cur"))
}
complete -F _saltcp salt-cp

View File

@ -1,4 +1,7 @@
#! bash oh-my-bash.module
#
# This probably originates from Bash-it.
#------------------------------------------------------------------------------
if ! declare -F __sdkman_build_version_csv &>/dev/null; then
# @fn __sdkman_build_version_csv
@ -8,13 +11,13 @@ if ! declare -F __sdkman_build_version_csv &>/dev/null; then
# This function was taken from "main/bash/sdkman-list.sh @
# sdkman/sdkman-cli".
# https://github.com/sdkman/sdkman-cli/blob/19e5c081297d6a8d1ce8a8b54631bb3f8e8e861b/src/main/bash/sdkman-list.sh#L51
function __sdkman_build_version_csv() {
function __sdkman_build_version_csv {
local candidate=$1
local versions_csv=""
if [[ -d ${SDKMAN_CANDIDATES_DIR}/${candidate} ]]; then
for version in $(find "${SDKMAN_CANDIDATES_DIR}/${candidate}" -maxdepth 1 -mindepth 1 \( -type l -o -type d \) -exec basename '{}' \; | sort -r); do
if [[ -d $SDKMAN_CANDIDATES_DIR/$candidate ]]; then
for version in $(find "$SDKMAN_CANDIDATES_DIR/$candidate" -maxdepth 1 -mindepth 1 \( -type l -o -type d \) -exec basename '{}' \; | sort -r); do
if [[ $version != 'current' ]]; then
versions_csv=${version},${versions_csv}
versions_csv=$version,$versions_csv
fi
done
versions_csv=${versions_csv%?}
@ -23,41 +26,40 @@ if ! declare -F __sdkman_build_version_csv &>/dev/null; then
}
fi
_omb_completion_sdkman()
{
function _omb_completion_sdkman {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
if ((COMP_CWORD == 1)); then
COMPREPLY=( $(compgen -W "install uninstall rm list ls use current outdated version default selfupdate broadcast offline help flush" -- "$cur") )
COMPREPLY=($(compgen -W "install uninstall rm list ls use current outdated version default selfupdate broadcast offline help flush" -- "$cur"))
elif ((COMP_CWORD == 2)); then
case ${COMP_WORDS[COMP_CWORD-1]} in
"install" | "uninstall" | "rm" | "list" | "ls" | "use" | "current" | "outdated" )
local candidates
candidates=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ')
COMPREPLY=( $(compgen -W "$candidates" -- "$cur") )
;;
"offline" )
COMPREPLY=( $(compgen -W "enable disable" -- "$cur") )
;;
"selfupdate" )
COMPREPLY=( $(compgen -W "force" -P "[" -S "]" -- "$cur") )
;;
"flush" )
COMPREPLY=( $(compgen -W "candidates broadcast archives temp" -- "$cur") )
;;
*)
;;
"install" | "uninstall" | "rm" | "list" | "ls" | "use" | "current" | "outdated")
local candidates
candidates=$(tr ',' ' ' <<< "$SDKMAN_CANDIDATES_CSV")
COMPREPLY=($(compgen -W "$candidates" -- "$cur"))
;;
"offline")
COMPREPLY=($(compgen -W "enable disable" -- "$cur"))
;;
"selfupdate")
COMPREPLY=($(compgen -W "force" -P "[" -S "]" -- "$cur"))
;;
"flush")
COMPREPLY=($(compgen -W "candidates broadcast archives temp" -- "$cur"))
;;
*)
;;
esac
elif ((COMP_CWORD == 3)); then
case ${COMP_WORDS[COMP_CWORD-2]} in
"install" | "uninstall" | "rm" | "use" | "default" )
local candidate_versions
_omb_completion_sdkman__candidate_versions "${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "$candidate_versions" -- "$cur") )
;;
*)
;;
"install" | "uninstall" | "rm" | "use" | "default")
local candidate_versions
_omb_completion_sdkman__candidate_versions "${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=($(compgen -W "$candidate_versions" -- "$cur"))
;;
*)
;;
esac
fi
@ -66,11 +68,11 @@ _omb_completion_sdkman()
function _omb_completion_sdkman__candidate_versions {
local local_versions=$(_omb_completion_sdkman__cleanup_local_versions "$1")
if [[ $SDKMAN_OFFLINE_MODE = "true" ]]; then
if [[ $SDKMAN_OFFLINE_MODE == "true" ]]; then
candidate_versions=$local_versions
else
local online_versions="$(curl -s "${SDKMAN_SERVICE}/candidates/$1" | tr ',' ' ')"
candidate_versions="$(echo $online_versions $local_versions |sort | uniq ) "
local online_versions=$(curl -s "$SDKMAN_SERVICE/candidates/$1" | tr ',' ' ')
candidate_versions="$(printf '%s\n' $online_versions $local_versions | sort -u) "
fi
}

View File

@ -1,4 +1,12 @@
#! bash oh-my-bash.module
#
# The completion settings are found in the following places:
# * https://github.com/Luladjiev/Subversion-Bash-Complete
# * https://svn.apache.org/repos/asf/subversion/trunk/tools/client-side/bash_completion
#
# Change history
# * 2024-08-13 updated from svn.apache.org.
#
# ------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@ -79,12 +87,13 @@ function _svn_grcut()
function _svn_info()
{
local what=$1 line=
LANG=C LC_MESSAGES=C command svn info --non-interactive 2> /dev/null | \
LANG=C LC_MESSAGES=C svn info --non-interactive 2> /dev/null | \
while read line ; do
[[ $line == *"$what: "* ]] && echo ${line#*: }
done
}
# broken since svn 1.7 | FIXME: change to svn status -v ?
# _svn_lls (dir|file|all) files...
# list svn-managed files from list
# some 'svn status --all-files' would be welcome here?
@ -107,6 +116,85 @@ function _svn_lls()
done
}
# try to complete TARGET
# 1. [nothing] lists available protocols
# 2. svn+ssh:// lists servers from .ssh/known_hosts
# 3. http[s]:// lists already used svn servers
# 4. file:// lists files from dir
# 5. ^/ or protocol except file:/ triggers svn ls
# this code expects bash 4, $cur is split by : too
#
# $1 'all' | 'remote_only'
# return true if found something
function _svn_complete_target() {
# echo -e "\n_svn_complete_target: [$cur] 1:[${COMP_WORDS[COMP_CWORD]}] 2:[${COMP_WORDS[COMP_CWORD-1]}] 3:[${COMP_WORDS[COMP_CWORD-2]}] | [${COMP_WORDS[@]}] [$COMP_WORDBREAKS]"
local prefix=${COMP_WORDS[COMP_CWORD-2]}
local colon=${COMP_WORDS[COMP_CWORD-1]}
# see about COMP_WORDBREAKS workaround in prop completion
if [[ $prefix == "file" && "$colon" == ":" ]]
then
# file completion for file:// urls
COMPREPLY=( $(compgen -d -S '/' -X '*/.*' -- $cur ) )
return
elif [[ ( $1 == "all" && $cur == ^/* ) || ( "$colon" == ":" && $cur == //*/* ) ]]
then # we already have a protocol and host: autocomplete for svn ls ^/bla | svn ls remote_url | svn checkout remote_url
local p
if [ "$colon" == ":" ] ; then
p="$prefix$colon"
fi
if [[ $cur =~ ((.*/)([^/]*)) ]] # url = everything up to the last /
then
local url="${BASH_REMATCH[2]}"
local path="${BASH_REMATCH[3]}"
local remote_files="$(svn ls --non-interactive "$p$url" 2> /dev/null )"
COMPREPLY=( $(compgen -P "$url" -W "$remote_files" -- "$path" ) )
compopt -o nospace
return 0
fi
elif [[ "$colon" == ":" ]]
then
# get known servers
# svn+ssh://
if [[ $prefix == "svn+ssh" && $cur =~ (^//(.*)) ]] ; then
local server_start=${BASH_REMATCH[2]}
# debian & suse: /usr/share/bash-completion/bash_completion
local suffix=/
_known_hosts_real -p // "$server_start"
else
local urls= file=
for file in ~/.subversion/auth/svn.simple/* ; do
if [ -r $file ] ; then
local url=$(_svn_read_hashfile svn:realmstring < $file)
url=${url/*</}
url=${url/>*/}
urls="$urls $url"
fi
done
# only suggest/show possible suffixes
local suffix=$cur c= choices=
for c in $urls ; do
[[ $c == $prefix:* ]] && choices="$choices ${c#*:}"
done
COMPREPLY=( $(compgen -W "$choices" -- $suffix ) )
fi
compopt -o nospace
return
else
# show schemas
if [ $1 == 'all' ] ; then
COMPREPLY=( $(compgen -W "^/ $urlSchemas" -- $cur) )
else
COMPREPLY=( $(compgen -W "$urlSchemas" -- $cur) )
fi
compopt -o nospace
return
fi
#echo "nothing found"
return 1
}
# This completion guides the command/option order along the one suggested
# by "svn help", although other syntaxes are allowed.
#
@ -163,12 +251,14 @@ _svn()
cur=${COMP_WORDS[COMP_CWORD]}
# Possible expansions, without pure-prefix abbreviations such as "up".
cmds='add blame annotate praise cat changelist cl checkout co cleanup'
cmds='add auth blame annotate praise cat changelist cl checkout co cleanup'
cmds="$cmds commit ci copy cp delete remove rm diff export help import"
cmds="$cmds info list ls lock log merge mergeinfo mkdir move mv rename"
cmds="$cmds patch propdel pdel propedit pedit propget pget proplist"
cmds="$cmds plist propset pset relocate resolve resolved revert status"
cmds="$cmds switch unlock update upgrade"
cmds="$cmds switch unlock update upgrade"
cmds="$cmds x-shelf-diff x-shelf-drop x-shelf-list x-shelf-list-by-paths"
cmds="$cmds x-shelf-log x-shelf-save x-shelve x-shelves x-unshelve"
# help options have a strange command status...
local helpOpts='--help -h'
@ -184,6 +274,7 @@ _svn()
optsParam="$optsParam|--native-eol|-l|--limit|-c|--change"
optsParam="$optsParam|--depth|--set-depth|--with-revprop"
optsParam="$optsParam|--cl|--changelist|--accept|--show-revs"
optsParam="$optsParam|--show-item"
# svn:* and other (env SVN_BASH_*_PROPS) properties
local svnProps revProps allProps psCmds propCmds
@ -365,7 +456,7 @@ _svn()
# then we have an argument
if [[ $cmd = 'merge' && ! $URL ]] ; then
# fist argument is the source URL for the merge
# first argument is the source URL for the merge
URL=$opt
fi
@ -393,38 +484,10 @@ _svn()
if [[ $cmd == @(co|checkout|ls|list) && $stat = 'arg' && \
$SVN_BASH_COMPL_EXT == *urls* ]]
then
# see about COMP_WORDBREAKS workaround in prop completion
if [[ $cur == file:* ]]
then
# file completion for file:// urls
local where=${cur/file:/}
COMPREPLY=( $(compgen -d -S '/' -X '*/.*' -- $where ) )
return
elif [[ $cur == *:* ]]
then
# get known urls
local urls= file=
for file in ~/.subversion/auth/svn.simple/* ; do
if [ -r $file ] ; then
local url=$(_svn_read_hashfile svn:realmstring < $file)
url=${url/*</}
url=${url/>*/}
urls="$urls $url"
fi
done
# only suggest/show possible suffixes
local prefix=${cur%:*} suffix=${cur#*:} c= choices=
for c in $urls ; do
[[ $c == $prefix:* ]] && choices="$choices ${c#*:}"
done
COMPREPLY=( $(compgen -W "$choices" -- $suffix ) )
return
if [[ $cmd == @(ls|list) ]] ; then
_svn_complete_target 'all' && return
else
# show schemas
COMPREPLY=( $(compgen -W "$urlSchemas" -- $cur) )
return
_svn_complete_target 'remote_only' && return
fi
fi
@ -441,17 +504,23 @@ _svn()
elif [[ "$here" == */trunk* ]] ; then
# we guess that it is a merge from a branch
COMPREPLY=( $(compgen -W ${here/\/trunk*/\/branches\/} -- $cur ) )
compopt -o nospace
return 0
else
# no se, let us suggest the repository root...
COMPREPLY=( $(compgen -W $(_svn_info Root) -- $cur ) )
COMPREPLY=( $(compgen -W $(_svn_info Root)/ -- $cur ) )
compopt -o nospace
return 0
fi
# this part is broken with bash 4 URL contains https only
elif [[ $URL == */branches/* && $here == */trunk* && \
! $hasReintegrateOpt && $cur = '' && $stat = 'arg' ]] ; then
# force --reintegrate only if the current word is empty
COMPREPLY=( $(compgen -W '--reintegrate' -- $cur ) )
return 0
# autocomplete for svn merge ^/bla
else
_svn_complete_target 'all' && return
fi
fi
@ -502,6 +571,10 @@ _svn()
[[ $previous = '--show-revs' ]] && values='merged eligible'
[[ $previous = '--show-item' ]] && values="kind url relative-url \
repos-root-url repos-uuid revision last-changed-revision \
last-changed-date last-changed-author wc-root"
if [[ $previous = '--username' ]] ; then
values="$SVN_BASH_USERNAME"
if [[ $SVN_BASH_COMPL_EXT == *username* ]] ; then
@ -689,7 +762,7 @@ _svn()
# build status command and options
# "--quiet" removes 'unknown' files
local status='command svn status --non-interactive'
local status='svn status --non-interactive'
[[ $SVN_BASH_COMPL_EXT == *recurse* ]] || \
status="$status --non-recursive"
@ -782,8 +855,11 @@ _svn()
# otherwise build possible options for the command
pOpts="--username --password --no-auth-cache --non-interactive \
--trust-server-cert --force-interactive"
mOpts="-m --message -F --file --encoding --force-log --with-revprop"
--password-from-stdin \
--trust-server-cert-failures \
--force-interactive"
mOpts="-m --message -F --file --encoding --force-log --with-revprop \
--editor-cmd"
rOpts="-r --revision"
qOpts="-q --quiet"
nOpts="-N --non-recursive --depth"
@ -799,12 +875,15 @@ _svn()
cmdOpts="--auto-props --no-auto-props --force --targets \
--no-ignore --parents $nOpts $qOpts $pOpts"
;;
auth)
cmdOpts="--remove --show-passwords $pOpts"
;;
blame|annotate|ann|praise)
cmdOpts="$rOpts $pOpts -v --verbose --incremental --xml \
-x --extensions --force $gOpts"
;;
cat)
cmdOpts="$rOpts $pOpts"
cmdOpts="$rOpts $pOpts --ignore-keywords"
;;
changelist|cl)
cmdOpts="--targets $pOpts $qOpts $cOpts \
@ -812,22 +891,23 @@ _svn()
;;
checkout|co)
cmdOpts="$rOpts $qOpts $nOpts $pOpts --ignore-externals \
--force"
--force --store-pristine"
;;
cleanup)
cmdOpts="--diff3-cmd $pOpts"
cmdOpts="$pOpts --include-externals -q --quiet\
--remove-ignored --remove-unversioned --vacuum-pristines"
;;
commit|ci)
cmdOpts="$mOpts $qOpts $nOpts --targets --editor-cmd $pOpts \
cmdOpts="$mOpts $qOpts $nOpts --targets $pOpts \
--no-unlock $cOpts --keep-changelists \
--include-externals"
;;
copy|cp)
cmdOpts="$mOpts $rOpts $qOpts --editor-cmd $pOpts --parents \
--ignore-externals"
cmdOpts="$mOpts $rOpts $qOpts $pOpts --parents \
--ignore-externals --pin-externals"
;;
delete|del|remove|rm)
cmdOpts="--force $mOpts $qOpts --targets --editor-cmd $pOpts \
cmdOpts="--force $mOpts $qOpts --targets $pOpts \
--keep-local"
;;
diff|di)
@ -847,19 +927,21 @@ _svn()
;;
import)
cmdOpts="--auto-props --no-auto-props $mOpts $qOpts $nOpts \
--no-ignore --editor-cmd $pOpts --force"
--no-ignore $pOpts --force"
;;
info)
cmdOpts="$pOpts $rOpts --targets -R --recursive --depth \
--incremental --xml $cOpts"
--include-externals --incremental --xml \
--show-item --no-newline $cOpts"
;;
list|ls)
cmdOpts="$rOpts -v --verbose -R --recursive $pOpts \
--incremental --xml --depth --include-externals"
--incremental --search --xml --depth \
--include-externals"
;;
lock)
cmdOpts="-m --message -F --file --encoding --force-log \
--targets --force $pOpts"
$qOpts --targets --force $pOpts"
;;
log)
cmdOpts="$rOpts -v --verbose --targets $pOpts --stop-on-copy \
@ -871,17 +953,18 @@ _svn()
merge)
cmdOpts="$rOpts $nOpts $qOpts --force --dry-run --diff3-cmd \
$pOpts --ignore-ancestry -c --change -x --extensions \
--record-only --accept --reintegrate \
--record-only --accept \
--allow-mixed-revisions -v --verbose"
;;
mergeinfo)
cmdOpts="$rOpts $pOpts --depth --show-revs -R --recursive"
cmdOpts="$rOpts $pOpts --depth --show-revs -R --recursive \
$qOpts -v --verbose --incremental --log"
;;
mkdir)
cmdOpts="$mOpts $qOpts --editor-cmd $pOpts --parents"
cmdOpts="$mOpts $qOpts $pOpts --parents"
;;
move|mv|rename|ren)
cmdOpts="$mOpts $rOpts $qOpts --force --editor-cmd $pOpts \
cmdOpts="$mOpts $qOpts --force $pOpts \
--parents --allow-mixed-revisions"
;;
patch)
@ -894,12 +977,12 @@ _svn()
[[ $isRevProp || ! $prop ]] && cmdOpts="$cmdOpts --revprop"
;;
propedit|pedit|pe)
cmdOpts="--editor-cmd $pOpts $mOpts --force"
cmdOpts="$pOpts $mOpts --force"
[[ $isRevProp || ! $prop ]] && \
cmdOpts="$cmdOpts --revprop $rOpts"
;;
propget|pget|pg)
cmdOpts="-v --verbose -R --recursive $rOpts --strict \
cmdOpts="-v --verbose -R --recursive $rOpts --no-newline \
$pOpts $cOpts --depth --xml --show-inherited-props"
[[ $isRevProp || ! $prop ]] && cmdOpts="$cmdOpts --revprop"
;;
@ -931,24 +1014,56 @@ _svn()
status|stat|st)
cmdOpts="-u --show-updates -v --verbose $nOpts $qOpts $pOpts \
--no-ignore --ignore-externals --incremental --xml \
$cOpts"
$rOpts $cOpts"
;;
switch|sw)
cmdOpts="--relocate $rOpts $nOpts $qOpts $pOpts --diff3-cmd \
cmdOpts="$rOpts $nOpts $qOpts $pOpts --diff3-cmd \
--force --accept --ignore-externals --set-depth \
--ignore-ancestry"
;;
unlock)
cmdOpts="--targets --force $pOpts"
cmdOpts="$qOpts --targets --force $pOpts"
;;
update|up)
cmdOpts="$rOpts $nOpts $qOpts $pOpts --diff3-cmd \
--ignore-externals --force --accept $cOpts \
--parents --editor-cmd --set-depth"
--parents --editor-cmd --set-depth \
--adds-as-modification"
;;
upgrade)
cmdOpts="$qOpts $pOpts"
;;
x-shelf-list-by-paths)
cmdOpts="$pOpts"
;;
x-shelf-diff)
cmdOpts="$pOpts --summarize"
;;
x-shelf-drop)
cmdOpts="$pOpts"
;;
x-shelf-list|x-shelves)
cmdOpts="$qOpts $pOpts"
;;
x-shelf-log)
cmdOpts="$qOpts $pOpts"
;;
x-shelf-save)
cmdOpts="--dry-run \
--depth --targets $cOpts \
$mOpts \
$qOpts $pOpts"
;;
x-shelve)
cmdOpts="--keep-local --dry-run \
--depth --targets $cOpts \
$mOpts \
$qOpts $pOpts"
;;
x-unshelve)
cmdOpts="--drop --dry-run \
$qOpts $pOpts"
;;
*)
;;
esac
@ -1021,7 +1136,7 @@ _svn()
COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
return 0
}
complete -F _svn -o default -X '@(*/.svn|*/.svn/|.svn|.svn/)' svn
complete -F _svn -o bashdefault -o default -X '@(*/.svn|*/.svn/|.svn|.svn/)' svn
_svnadmin ()
{
@ -1031,8 +1146,9 @@ _svnadmin ()
cur=${COMP_WORDS[COMP_CWORD]}
# Possible expansions, without pure-prefix abbreviations such as "h".
cmds='crashtest create deltify dump freeze help hotcopy list-dblogs \
list-unused-dblogs load lock lslocks lstxns pack recover rmlocks \
cmds='build-repcache crashtest create delrevprop deltify dump dump-revprops freeze \
help hotcopy info list-dblogs list-unused-dblogs \
load load-revprops lock lslocks lstxns pack recover rev-size rmlocks \
rmtxns setlog setrevprop setuuid unlock upgrade verify --version'
if [[ $COMP_CWORD -eq 1 ]] ; then
@ -1043,7 +1159,7 @@ _svnadmin ()
# options that require a parameter
# note: continued lines must end '|' continuing lines must start '|'
optsParam="-r|--revision|--parent-dir|--fs-type|-M|--memory-cache-size"
optsParam="$optsParam|-F|--file"
optsParam="$optsParam|-F|--file|--exclude|--include"
# if not typing an option, or if the previous option required a
# parameter, then fallback on ordinary filename expansion
@ -1056,17 +1172,23 @@ _svnadmin ()
cmdOpts=
case ${COMP_WORDS[1]} in
build-repcache)
cmdOpts="-r --revision -q --quiet -M --memory-cache-size"
;;
create)
cmdOpts="--bdb-txn-nosync --bdb-log-keep --config-dir \
--fs-type --pre-1.4-compatible --pre-1.5-compatible \
--pre-1.6-compatible --compatible-version"
--fs-type --compatible-version"
;;
deltify)
cmdOpts="-r --revision -q --quiet"
cmdOpts="-r --revision -q --quiet -M --memory-cache-size"
;;
dump)
cmdOpts="-r --revision --incremental -q --quiet --deltas \
-M --memory-cache-size"
-M --memory-cache-size -F --file \
--exclude --include --pattern"
;;
dump-revprops)
cmdOpts="-r --revision -q --quiet -F --file"
;;
freeze)
cmdOpts="-F --file"
@ -1075,31 +1197,53 @@ _svnadmin ()
cmdOpts="$cmds"
;;
hotcopy)
cmdOpts="--clean-logs"
cmdOpts="--clean-logs --incremental -q --quiet"
;;
load)
cmdOpts="--ignore-uuid --force-uuid --parent-dir -q --quiet \
--use-pre-commit-hook --use-post-commit-hook \
--bypass-prop-validation -M --memory-cache-size"
--bypass-prop-validation -M --memory-cache-size \
--no-flush-to-disk --normalize-props -F --file \
--ignore-dates -r --revision"
;;
load-revprops)
cmdOpts="-r --revision -q --quiet -F --file \
--bypass-prop-validation --normalize-props \
--force-uuid --no-flush-to-disk"
;;
lstxns)
cmdOpts="-r --revision"
;;
lock|unlock)
cmdOpts="--bypass-hooks"
cmdOpts="--bypass-hooks -q --quiet"
;;
pack)
cmdOpts="-M --memory-cache-size -q --quiet"
;;
recover)
cmdOpts="--wait"
;;
rev-size)
cmdOpts="-r --revision -M --memory-cache-size -q --quiet"
;;
rmlocks)
cmdOpts="-q --quiet"
;;
rmtxns)
cmdOpts="-q --quiet"
;;
setlog)
cmdOpts="-r --revision --bypass-hooks"
;;
setrevprop)
cmdOpts="-r --revision --use-pre-revprop-change-hook \
setrevprop|delrevprop)
cmdOpts="-r --revision -t --transaction \
--use-pre-revprop-change-hook \
--use-post-revprop-change-hook"
;;
verify)
cmdOpts="-r --revision -q --quiet"
cmdOpts="-r --revision -t --transaction -q --quiet \
--check-normalization --keep-going \
-M --memory-cache-size --metadata-only"
;;
*)
;;
@ -1127,6 +1271,8 @@ _svnadmin ()
--help) cmdOpts=${cmdOpts/ -h / } ;;
-r) cmdOpts=${cmdOpts/ --revision / } ;;
--revision) cmdOpts=${cmdOpts/ -r / } ;;
-t) cmdOpts=${cmdOpts/ --transaction / } ;;
--transaction) cmdOpts=${cmdOpts/ -t / } ;;
-F) cmdOpts=${cmdOpts/ --file / } ;;
--file) cmdOpts=${cmdOpts/ -F / } ;;
-M) cmdOpts=${cmdOpts/ --memory-cache-size / } ;;
@ -1143,7 +1289,7 @@ _svnadmin ()
return 0
}
complete -F _svnadmin -o default svnadmin
complete -F _svnadmin -o bashdefault -o default svnadmin
_svndumpfilter ()
{
@ -1176,9 +1322,9 @@ _svndumpfilter ()
cmdOpts=
case ${COMP_WORDS[1]} in
exclude|include)
cmdOpts="--drop-empty-revs --renumber-revs
cmdOpts="--drop-empty-revs --drop-all-empty-revs --renumber-revs
--skip-missing-merge-sources --targets
--preserve-revprops --quiet"
--preserve-revprops --quiet --pattern"
;;
help|h|\?)
cmdOpts="$cmds"
@ -1217,7 +1363,7 @@ _svndumpfilter ()
return 0
}
complete -F _svndumpfilter -o default svndumpfilter
complete -F _svndumpfilter -o bashdefault -o default svndumpfilter
_svnlook ()
{
@ -1227,8 +1373,8 @@ _svnlook ()
cur=${COMP_WORDS[COMP_CWORD]}
# Possible expansions, without pure-prefix abbreviations such as "h".
cmds='author cat changed date diff dirs-changed help history info \
lock log propget proplist tree uuid youngest --version'
cmds='author cat changed date diff dirs-changed filesize help history \
info lock log propget proplist tree uuid youngest --version'
if [[ $COMP_CWORD -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
@ -1269,6 +1415,9 @@ _svnlook ()
dirs-changed)
cmdOpts="-r --revision -t --transaction"
;;
filesize)
cmdOpts="-r --revision -t --transaction"
;;
help|h|\?)
cmdOpts="$cmds"
;;
@ -1345,7 +1494,7 @@ _svnlook ()
return 0
}
complete -F _svnlook -o default svnlook
complete -F _svnlook -o bashdefault -o default svnlook
_svnsync ()
{
@ -1381,7 +1530,8 @@ _svnsync ()
copy-revprops|initialize|init|synchronize|sync)
cmdOpts="--non-interactive --no-auth-cache --trust-server-cert \
--source-username --source-password --sync-username \
--sync-password --config-dir --config-option -q --quiet"
--sync-password --config-dir --config-option \
-q --quiet -M --memory-cache-size"
;;
help|h|\?)
cmdOpts="$cmds"
@ -1427,7 +1577,7 @@ _svnsync ()
return 0
}
complete -F _svnsync -o default svnsync
complete -F _svnsync -o bashdefault -o default svnsync
# reasonable completion for 'svnversion'
_svnversion ()

View File

@ -5,184 +5,177 @@
# Usage: Put "source bash_completion_tmux.sh" into your .bashrc
# Based upon the example at http://paste-it.appspot.com/Pj4mLycDE
_tmux_expand ()
{
[ "$cur" != "${cur%\\}" ] && cur="$cur"'\';
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur;
else
if [[ "$cur" == \~* ]]; then
cur=${cur#\~};
COMPREPLY=($( compgen -P '~' -u $cur ));
return ${#COMPREPLY[@]};
fi;
fi
function _tmux_expand {
[[ $cur != "${cur%\\}" ]] && cur=$cur'\'
if [[ $cur == \~*/* ]]; then
eval "cur=$cur"
elif [[ $cur == \~* ]]; then
cur=${cur#\~}
COMPREPLY=($(compgen -P '~' -u "$cur"))
((${#COMPREPLY[@]} == 0))
fi
}
_tmux_filedir ()
{
local IFS='
';
_tmux_expand || return 0;
if [ "$1" = -d ]; then
COMPREPLY=(${COMPREPLY[@]} $( compgen -d -- $cur ));
return 0;
fi;
COMPREPLY=(${COMPREPLY[@]} $( eval compgen -f -- \"$cur\" ))
function _tmux_filedir {
local IFS=$'\n'
_tmux_expand || return 0
if [[ $1 == -d ]]; then
COMPREPLY=("${COMPREPLY[@]}" $(compgen -d -- "$cur"));
return 0;
fi;
COMPREPLY=("${COMPREPLY[@]}" $(eval "compgen -f -- \"$cur\""))
}
function _tmux_complete_client() {
local IFS=$'\n'
local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
function _tmux_complete_client {
local IFS=$'\n'
local cur=$1
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(tmux -q list-clients 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
}
function _tmux_complete_session() {
local IFS=$'\n'
local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
function _tmux_complete_session {
local IFS=$'\n'
local cur=$1
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(tmux -q list-sessions 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
}
function _tmux_complete_window() {
local IFS=$'\n'
local cur="${1}"
local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)"
local sessions
function _tmux_complete_window {
local IFS=$'\n'
local cur=$1
local session_name=$(<<< "$cur" sed 's/\\//g' | cut -d ':' -f 1)
local sessions
sessions="$(tmux -q list-sessions 2>/dev/null | sed -re 's/([^:]+:).*$/\1/')"
if [[ -n "${session_name}" ]]; then
sessions="${sessions}
$(tmux -q list-windows -t "${session_name}" 2>/dev/null | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')"
fi
cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')"
sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}") )
sessions="$(tmux -q list-sessions 2>/dev/null | sed -re 's/([^:]+:).*$/\1/')"
if [[ $session_name ]]; then
sessions="$sessions
$(tmux -q list-windows -t "$session_name" 2>/dev/null | sed -re 's/^([^:]+):.*$/'"$session_name"':\1/')"
fi
cur=$(<<< "$cur" sed -e 's/:/\\\\:/')
sessions=$(<<< "$sessions" sed -e 's/:/\\\\:/')
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$sessions" -- "$cur"))
}
function _tmux {
local cur prev
local i cmd cmd_index option option_index
local opts=""
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local cur prev
local i cmd cmd_index option option_index
local opts=""
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ ${prev} == -f ]; then
_tmux_filedir
else
if [[ $prev == -f ]]; then
_tmux_filedir
else
# Search for the command
local skip_next=0
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${skip_next} -eq 1 ]]; then
#echo "Skipping"
skip_next=0;
elif [[ ${COMP_WORDS[i]} != -* ]]; then
cmd="${COMP_WORDS[i]}"
cmd_index=${i}
break
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
fi
for ((i = 1; i <= COMP_CWORD; i++)); do
if ((skip_next == 1)) then
#echo "Skipping"
skip_next=0;
elif [[ ${COMP_WORDS[i]} != -* ]]; then
cmd=${COMP_WORDS[i]}
cmd_index=$i
break
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
fi
done
# Search for the last option command
skip_next=0
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${skip_next} -eq 1 ]]; then
#echo "Skipping"
skip_next=0;
elif [[ ${COMP_WORDS[i]} == -* ]]; then
option="${COMP_WORDS[i]}"
option_index=${i}
if [[ ${COMP_WORDS[i]} == -- ]]; then
break;
fi
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
for ((i = 1; i <= COMP_CWORD; i++)); do
if ((skip_next == 1)); then
#echo "Skipping"
skip_next=0
elif [[ ${COMP_WORDS[i]} == -* ]]; then
option=${COMP_WORDS[i]}
option_index=$i
if [[ ${COMP_WORDS[i]} == -- ]]; then
break
fi
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
fi
done
if [[ $COMP_CWORD -le $cmd_index ]]; then
# The user has not specified a command yet
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "${cur}") )
if ((COMP_CWORD <= cmd_index)); then
# The user has not specified a command yet
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(tmux start-server \; list-commands | cut -d' ' -f1)" -- "$cur"))
else
case ${cmd} in
attach-session|attach)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t -d" ;;
esac ;;
detach-client|detach)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
lock-client|lockc)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
lock-session|locks)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t -d" ;;
esac ;;
new-session|new)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
-[n|d|s]) options="-d -n -s -t --" ;;
*)
if [[ ${COMP_WORDS[option_index]} == -- ]]; then
_command_offset ${option_index}
else
options="-d -n -s -t --"
fi
;;
esac
;;
refresh-client|refresh)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
rename-session|rename)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t" ;;
esac ;;
source-file|source) _tmux_filedir ;;
has-session|has|kill-session)
case "$prev" in
-t) _tmux_complete_session "${cur}" ;;
*) options="-t" ;;
esac ;;
suspend-client|suspendc)
case "$prev" in
-t) _tmux_complete_client "${cur}" ;;
*) options="-t" ;;
esac ;;
switch-client|switchc)
case "$prev" in
-c) _tmux_complete_client "${cur}" ;;
-t) _tmux_complete_session "${cur}" ;;
*) options="-l -n -p -c -t" ;;
esac ;;
case $cmd in
attach-session|attach)
case $prev in
-t) _tmux_complete_session "$cur" ;;
*) options="-t -d" ;;
esac ;;
detach-client|detach)
case $prev in
-t) _tmux_complete_client "$cur" ;;
*) options="-t" ;;
esac ;;
lock-client|lockc)
case $prev in
-t) _tmux_complete_client "$cur" ;;
*) options="-t" ;;
esac ;;
lock-session|locks)
case $prev in
-t) _tmux_complete_session "$cur" ;;
*) options="-t -d" ;;
esac ;;
new-session|new)
case $prev in
-t) _tmux_complete_session "$cur" ;;
-[n|d|s]) options="-d -n -s -t --" ;;
*)
if [[ ${COMP_WORDS[option_index]} == -- ]]; then
_command_offset ${option_index}
else
options="-d -n -s -t --"
fi
;;
esac
;;
refresh-client|refresh)
case $prev in
-t) _tmux_complete_client "$cur" ;;
*) options="-t" ;;
esac ;;
rename-session|rename)
case $prev in
-t) _tmux_complete_session "$cur" ;;
*) options="-t" ;;
esac ;;
source-file|source) _tmux_filedir ;;
has-session|has|kill-session)
case $prev in
-t) _tmux_complete_session "$cur" ;;
*) options="-t" ;;
esac ;;
suspend-client|suspendc)
case $prev in
-t) _tmux_complete_client "$cur" ;;
*) options="-t" ;;
esac ;;
switch-client|switchc)
case $prev in
-c) _tmux_complete_client "$cur" ;;
-t) _tmux_complete_session "$cur" ;;
*) options="-l -n -p -c -t" ;;
esac ;;
send-keys|send)
case "$option" in
-t) _tmux_complete_window "${cur}" ;;
*) options="-t" ;;
esac ;;
esac # case ${cmd}
fi # command specified
fi # not -f
send-keys|send)
case $option in
-t) _tmux_complete_window "$cur" ;;
*) options="-t" ;;
esac ;;
esac # case $cmd
fi # command specified
fi # not -f
if [[ -n "${options}" ]]; then
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}") )
fi
return 0
if [[ $options ]]; then
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$options" -- "$cur"))
fi
return 0
}
complete -F _tmux tmux
# END tmux completion

View File

@ -1,5 +1,8 @@
#! 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)
#
# Copyright (c) 2014 Kura
@ -24,124 +27,160 @@
function __pwdln {
pwdmod="${PWD}/"
itr=0
until [[ -z "$pwdmod" ]];do
itr=$(($itr+1))
pwdmod="${pwdmod#*/}"
done
echo -n $(($itr-1))
pwdmod=$PWD/
itr=0
until [[ ! $pwdmod ]]; do
((itr++))
pwdmod="${pwdmod#*/}"
done
echo -n $((itr-1))
}
function __vagrantinvestigate {
if [ -f "${PWD}/.vagrant" -o -d "${PWD}/.vagrant" ];then
echo "${PWD}/.vagrant"
return 0
else
pwdmod2="${PWD}"
for (( i=2; i<=$(__pwdln); i++ ));do
pwdmod2="${pwdmod2%/*}"
if [ -f "${pwdmod2}/.vagrant" -o -d "${pwdmod2}/.vagrant" ];then
echo "${pwdmod2}/.vagrant"
return 0
fi
done
fi
return 1
if [[ -f $PWD/.vagrant || -d $PWD/.vagrant ]]; then
echo "$PWD/.vagrant"
return 0
else
pwdmod2=$PWD
for ((i = 2; i <= $(__pwdln); i++)); do
pwdmod2=${pwdmod2%/*}
if [[ -f $pwdmod2/.vagrant || -d $pwdmod2/.vagrant ]]; then
echo "$pwdmod2/.vagrant"
return 0
fi
done
fi
return 1
}
function _vagrant {
cur="${COMP_WORDS[COMP_CWORD]}"
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"
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
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 ]
then
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
if ((COMP_CWORD == 1)); then
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
return 0
fi
if ((COMP_CWORD == 2)); then
case $prev in
"init")
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"))
return 0
fi
;;
"up")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -d $vagrant_state_file ]]; then
local vm_list=$(find "$vagrant_state_file/machines" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
fi
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"))
return 0
;;
"destroy"|"ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -f $vagrant_state_file ]]
then
running_vm_list=$(grep 'active' "$vagrant_state_file" | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
else
running_vm_list=$(find "$vagrant_state_file/machines" -type f -name "id" | awk -F"/" '{print $(NF-2)}')
fi
COMPREPLY=($(compgen -W "$running_vm_list" -- "$cur"))
return 0
;;
"box")
box_commands="add help list outdated prune remove repackage update"
COMPREPLY=($(compgen -W "$box_commands" -- "$cur"))
return 0
;;
"cloud")
cloud_commands="auth box search provider publish version"
COMPREPLY=($(compgen -W "$cloud_commands" -- "$cur"))
return 0
;;
"plugin")
plugin_commands="install license list uninstall update"
COMPREPLY=($(compgen -W "$plugin_commands" -- "$cur"))
return 0
;;
"help")
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
return 0
;;
"snapshot")
snapshot_commands="delete list pop push restore save"
COMPREPLY=($(compgen -W "$snapshot_commands" -- "$cur"))
return 0
;;
*)
;;
esac
fi
if [ $COMP_CWORD == 2 ]
then
case "$prev" in
"init")
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
"up")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -d $vagrant_state_file ]]
then
vm_list=$(find $vagrant_state_file/machines -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
fi
local up_commands="--no-provision"
COMPREPLY=($(compgen -W "${up_commands} ${vm_list}" -- ${cur}))
return 0
;;
"ssh"|"provision"|"reload"|"halt"|"suspend"|"resume"|"ssh-config")
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -f $vagrant_state_file ]]
then
running_vm_list=$(grep 'active' "$vagrant_state_file" | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
else
running_vm_list=$(find "$vagrant_state_file" -type f -name "id" | awk -F"/" '{print $(NF-2)}')
fi
COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur}))
return 0
;;
"box")
box_commands="add help list remove repackage"
COMPREPLY=($(compgen -W "${box_commands}" -- ${cur}))
return 0
;;
"plugin")
plugin_commands="install license list uninstall update"
COMPREPLY=($(compgen -W "${plugin_commands}" -- ${cur}))
return 0
;;
"help")
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
;;
"snapshot")
snapshot_commands="back delete go list take"
COMPREPLY=($(compgen -W "${snapshot_commands}" -- ${cur}))
return 0
;;
*)
;;
esac
fi
if [ $COMP_CWORD == 3 ]
then
action="${COMP_WORDS[COMP_CWORD-2]}"
case "$action" in
"up")
if [ "$prev" == "--no-provision" ]; then
COMPREPLY=($(compgen -W "${vm_list}" -- ${cur}))
return 0
fi
;;
"box")
case "$prev" in
"remove"|"repackage")
local box_list=$(find "$HOME/.vagrant.d/boxes" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;|sed -e 's/-VAGRANTSLASH-/\//')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
*)
esac
;;
"snapshot")
if [ "$prev" == "go" ]; then
local snapshot_list=$(vagrant snapshot list | awk '/Name:/ { print $2 }')
COMPREPLY=($(compgen -W "${snapshot_list}" -- ${cur}))
return 0
fi
;;
if ((COMP_CWORD == 3)); then
action=${COMP_WORDS[COMP_CWORD-2]}
case $action in
"up")
if [[ $prev == --no-provision ]]; 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
fi
;;
"box")
case $prev in
"remove"|"repackage")
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"))
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
;;
*)
;;
esac
fi
;;
"snapshot")
case $prev in
"restore"|"delete")
local snapshot_list=$(vagrant snapshot list)
COMPREPLY=($(compgen -W "$snapshot_list" -- "$cur"))
return 0
;;
esac
;;
*)
;;
esac
fi
}
complete -F _vagrant vagrant

View File

@ -7,7 +7,7 @@
# see https://github.com/iljaweis/vault-bash-completion
# ---------------------------------------------------------------------------
function _vault_mounts() {
function _vault_mounts {
(
set -euo pipefail
if ! vault mounts 2> /dev/null | awk 'NR > 1 {print $1}'; then
@ -16,13 +16,12 @@ function _vault_mounts() {
)
}
function _vault() {
function _vault {
local VAULT_COMMANDS=$(vault 2>&1 | command grep -E '^ +' | awk '{print $1}')
local cur
local prev
local cur prev
if [ $COMP_CWORD -gt 0 ]; then
if ((COMP_CWORD > 0)); then
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
fi
@ -32,15 +31,15 @@ function _vault() {
if [[ $prev =~ ^(policies|policy-write|policy-delete) ]]; then
local policies=$(vault policies 2> /dev/null)
COMPREPLY=($(compgen -W "$policies" -- $cur))
elif [ "$(echo "$line" | wc -w)" -le 2 ]; then
if [[ "$line" =~ ^vault\ (read|write|delete|list)\ $ ]]; then
elif (($(echo "$line" | wc -w) <= 2)); then
if [[ $line =~ ^vault\ (read|write|delete|list)\ $ ]]; then
COMPREPLY=($(compgen -W "$(_vault_mounts)" -- ''))
else
COMPREPLY=($(compgen -W "$VAULT_COMMANDS" -- $cur))
fi
elif [[ "$line" =~ ^vault\ (read|write|delete|list)\ (.*)$ ]]; then
elif [[ $line =~ ^vault\ (read|write|delete|list)\ (.*)$ ]]; then
path=${BASH_REMATCH[2]}
if [[ "$path" =~ ^([^ ]+)/([^ /]*)$ ]]; then
if [[ $path =~ ^([^ ]+)/([^ /]*)$ ]]; then
list=$(vault list -format=yaml ${BASH_REMATCH[1]} 2> /dev/null | awk '{ print $2 }')
COMPREPLY=($(compgen -W "$list" -P "${BASH_REMATCH[1]}/" -- ${BASH_REMATCH[2]}))
else

View File

@ -1,87 +1,228 @@
#! bash oh-my-bash.module
#
# This completion setting seems to originate from the following repository:
# https://github.com/tfmalt/bash-completion-virtualbox
#
# The license is unspecified. The upstream is not active for nine years (as of
# 2024-08), so we would adjust the codes by ourselves.
#
# Change history
#
# * 2017-10-10 This file was added to Oh My Bash. This is probably taken from
# the following version:
# https://github.com/tfmalt/bash-completion-virtualbox/blob/fb9739cfe9d2a6d0076c5423dc25393bcf6a77dd/vboxmanage_completion.bash
# * 2024-08-13 The file cotnent is update to the latest upstream version based on:
# https://github.com/tfmalt/bash-completion-virtualbox/blob/02df30e0b8e399b8011d95aa917caf0aafe01d27/vboxmanage_completion.bash
#
#------------------------------------------------------------------------------
#!/usr/bin/env bash
#
# Attempt at autocompletion script for vboxmanage. This scripts assumes an
# alias between VBoxManage and vboxmanaage.
#
# Copyright (c) 2012 Thomas Malt <thomas@malt.no>
#
#alias vboxmanage="VBoxManage"
complete -F _vboxmanage vboxmanage
# export VBOXMANAGE_NIC_TYPES
function _vboxmanage {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# echo "cur: |$cur|"
# echo "prev: |$prev|"
case $prev in
-v|--version)
return 0
;;
-l|--long)
opts=$(__vboxmanage_list "long")
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
--nic[1-8])
# This is part of modifyvm subcommand
opts=$(__vboxmanage_nic_types)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
;;
startvm|list)
opts=$(__vboxmanage_$prev)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
--type)
COMPREPLY=($(compgen -W "gui headless" -- ${cur}))
return 0
;;
gui|headless)
# Done. no more completion possible
return 0
;;
vboxmanage)
# In case current is complete command we return emmideatly.
case $cur in
startvm|list|controlvm|showvminfo|modifyvm)
COMPREPLY=($(compgen -W "$cur "))
return 0
;;
esac
# echo "Got vboxmanage"
opts=$(__vboxmanage_default)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
-q|--nologo)
opts=$(__vboxmanage_default)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
controlvm|showvminfo|modifyvm)
opts=$(__vboxmanage_list_vms)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
vrde|setlinkstate*)
# vrde is a complete subcommand of controlvm
opts="on off"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
for VM in $(__vboxmanage_list_vms); do
if [ "$VM" == "$prev" ]; then
pprev=${COMP_WORDS[COMP_CWORD-2]}
# echo "previous: $pprev"
case $pprev in
startvm)
opts="--type"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
controlvm)
opts=$(__vboxmanage_controlvm $VM)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0;
;;
showvminfo)
opts="--details --machinereadable --log"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0;
;;
modifyvm)
opts=$(__vboxmanage_modifyvm)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
fi
done
# echo "Got to end withoug completion"
}
function _vboxmanage_realopts {
echo $(vboxmanage|grep -i vboxmanage|cut -d' ' -f2|grep '\['|tr -s '[\[\|\]\n' ' ')
echo " "
echo $(vboxmanage | grep -Eo "^\s{2}[a-z]+")
echo " "
}
function __vboxmanage_nic_types {
echo $(vboxmanage |
grep ' nic<' |
sed 's/.*nic<1-N> \([a-z\|]*\).*/\1/' | tr '|' ' ')
}
function __vboxmanage_startvm {
RUNNING=$(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"')
TOTAL=$(vboxmanage list vms | cut -d' ' -f1 | tr -d '"')
RUNNING=$(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"')
TOTAL=$(vboxmanage list vms | cut -d' ' -f1 | tr -d '"')
AVAILABLE=""
for VM in $TOTAL; do
MATCH=0;
for RUN in $RUNNING "x"; do
if [ "$VM" == "$RUN" ]; then
MATCH=1
fi
done
(( $MATCH == 0 )) && AVAILABLE="$AVAILABLE $VM "
AVAILABLE=""
for VM in $TOTAL; do
MATCH=0;
for RUN in $RUNNING "x"; do
if [ "$VM" == "$RUN" ]; then
MATCH=1
fi
done
echo $AVAILABLE
(( $MATCH == 0 )) && AVAILABLE="$AVAILABLE $VM "
done
echo $AVAILABLE
}
function __vboxmanage_list {
INPUT=$(vboxmanage list | tr -s '[\[\]\|\n]' ' ' | cut -d' ' -f4-)
INPUT=$(vboxmanage list | tr -s '[\[\]\|\n]' ' ' | cut -d' ' -f4-)
PRUNED=""
if [ "$1" == "long" ]; then
for WORD in $INPUT; do
[ "$WORD" == "-l" ] && continue;
[ "$WORD" == "--long" ] && continue;
PRUNED=""
if [ "$1" == "long" ]; then
for WORD in $INPUT; do
[ "$WORD" == "-l" ] && continue;
[ "$WORD" == "--long" ] && continue;
PRUNED="$PRUNED $WORD"
done
else
PRUNED=$INPUT
fi
PRUNED="$PRUNED $WORD"
done
else
PRUNED=$INPUT
fi
echo $PRUNED
echo $PRUNED
}
function __vboxmanage_list_vms {
VMS=""
if [ "x$1" == "x" ]; then
SEPARATOR=" "
else
SEPARATOR=$1
fi
VMS=""
if [ "x$1" == "x" ]; then
SEPARATOR=" "
else
SEPARATOR=$1
fi
for VM in $(vboxmanage list vms | cut -d' ' -f1 | tr -d '"'); do
[ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}"
VMS="${VMS}${VM}"
done
for VM in $(vboxmanage list vms | cut -d' ' -f1 | tr -d '"'); do
[ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}"
VMS="${VMS}${VM}"
done
echo $VMS
echo $VMS
}
function __vboxmanage_list_runningvms {
VMS=""
if [ "$1" == "" ]; then
SEPARATOR=" "
else
SEPARATOR=$1
fi
VMS=""
if [ "$1" == "" ]; then
SEPARATOR=" "
else
SEPARATOR=$1
fi
for VM in $(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"'); do
[ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}"
VMS="${VMS}${VM}"
done
echo $VMS
for VM in $(vboxmanage list runningvms | cut -d' ' -f1 | tr -d '"'); do
[ "$VMS" != "" ] && VMS="${VMS}${SEPARATOR}"
VMS="${VMS}${VM}"
done
echo $VMS
}
function __vboxmanage_controlvm {
echo "pause resume reset poweroff savestate acpipowerbutton"
echo "acpisleepbutton keyboardputscancode guestmemoryballoon"
echo "gueststatisticsinterval usbattach usbdetach vrde vrdeport"
echo "vrdeproperty vrdevideochannelquality setvideomodehint"
echo "screenshotpng setcredentials teleport plugcpu unplugcpu"
echo "cpuexecutioncap"
echo "pause resume reset poweroff savestate acpipowerbutton"
echo "acpisleepbutton keyboardputscancode guestmemoryballoon"
echo "gueststatisticsinterval usbattach usbdetach vrde vrdeport"
echo "vrdeproperty vrdevideochannelquality setvideomodehint"
echo "screenshotpng setcredentials teleport plugcpu unplugcpu"
echo "cpuexecutioncap"
# setlinkstate<1-N>
activenics=$(__vboxmanage_showvminfo_active_nics $1)
for nic in $(echo "${activenics}" | tr -d 'nic'); do
echo "setlinkstate${nic}"
done
# setlinkstate<1-N>
# nic<1-N> null|nat|bridged|intnet|hostonly|generic
# [<devicename>] |
# nictrace<1-N> on|off
@ -90,133 +231,72 @@ function __vboxmanage_controlvm {
# natpf<1-N> [<rulename>],tcp|udp,[<hostip>],
# <hostport>,[<guestip>],<guestport>
# natpf<1-N> delete <rulename>
}
function __vboxmanage_modifyvm {
options=$(vboxmanage modifyvm | grep '\[--' | grep -v '\[--nic<' |
sed 's/ *\[--\([a-z]*\).*/--\1/')
# Exceptions
for i in {1..8}; do
options="$options --nic${i}"
done
echo $options
}
function __vboxmanage_showvminfo_active_nics {
nics=$(vboxmanage showvminfo $1 --machinereadable |
awk '/^nic/ && ! /none/' |
awk '{ split($1, names, "="); print names[1] }')
echo $nics
}
function __vboxmanage_default {
realopts=$(_vboxmanage_realopts)
opts=$realopts$(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep -v '\[' | sort | uniq)
pruned=""
realopts=$(_vboxmanage_realopts)
opts=$realopts$(vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | grep -v '\[' | sort | uniq)
pruned=""
# echo ""
# echo "DEBUG: cur: $cur, prev: $prev"
# echo "DEBUG: default: |$p1|$p2|$p3|$p4|"
case ${cur} in
-*)
echo $opts
# COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac;
for WORD in $opts; do
MATCH=0
for OPT in ${COMP_WORDS[@]}; do
# opts=$(echo ${opts} | grep -v $OPT);
if [ "$OPT" == "$WORD" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "-v" ] && [ "$WORD" == "--version" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "--version" ] && [ "$WORD" == "-v" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "-q" ] && [ "$WORD" == "--nologo" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "--nologo" ] && [ "$WORD" == "-q" ]; then
MATCH=1
break;
fi
done
(( $MATCH == 1 )) && continue;
pruned="$pruned $WORD"
done
# COMPREPLY=($(compgen -W "${pruned}" -- ${cur}))
echo $pruned
# echo ""
# echo "DEBUG: cur: $cur, prev: $prev"
# echo "DEBUG: default: |$p1|$p2|$p3|$p4|"
case ${cur} in
-*)
echo $opts
# COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
}
;;
esac;
function _vboxmanage {
# vboxmanage | grep -i vboxmanage | cut -d' ' -f2 | sort | uniq
local cur p1 p2 p3 p4 opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# echo "cur: |$cur|"
# echo "prev: |$prev|"
# In case current is complete command
case $cur in
startvm|list|controlvm)
COMPREPLY=($(compgen -W "$cur "))
return 0
;;
esac
case $prev in
-v|--version)
return 0
;;
-l|--long)
opts=$(__vboxmanage_list "long")
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
startvm|list)
opts=$(__vboxmanage_$prev)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
--type)
COMPREPLY=($(compgen -W "gui headless" -- ${cur}))
return 0
;;
gui|headless)
# Done. no more completion possible
return 0
;;
vboxmanage|-q|--nologo)
# echo "Got vboxmanage"
opts=$(__vboxmanage_default)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
controlvm)
opts=$(__vboxmanage_list_vms)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
esac
for VM in $(__vboxmanage_list_vms); do
if [ "$VM" == "$prev" ]; then
pprev=${COMP_WORDS[COMP_CWORD-2]}
# echo "previous: $pprev"
case $pprev in
startvm)
opts="--type"
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
;;
controlvm)
opts=$(__vboxmanage_controlvm)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0;
;;
esac
fi
for WORD in $opts; do
MATCH=0
for OPT in ${COMP_WORDS[@]}; do
# opts=$(echo ${opts} | grep -v $OPT);
if [ "$OPT" == "$WORD" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "-v" ] && [ "$WORD" == "--version" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "--version" ] && [ "$WORD" == "-v" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "-q" ] && [ "$WORD" == "--nologo" ]; then
MATCH=1
break;
fi
if [ "$OPT" == "--nologo" ] && [ "$WORD" == "-q" ]; then
MATCH=1
break;
fi
done
(( $MATCH == 1 )) && continue;
pruned="$pruned $WORD"
# echo "Got to end withoug completion"
done
# COMPREPLY=($(compgen -W "${pruned}" -- ${cur}))
echo $pruned
return 0
}
complete -F _vboxmanage vboxmanage