1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
# cme(1) completion -*- shell-script -*-
#
#
# This file is part of App::Cmd::Cme
#
# This software is Copyright (c) 2011, 2014 by Dominique Dumont
#
# This is free software, licensed under:
#
# The GNU Lesser General Public License, Version 2.1, February 1999
#
global_options='--force-load --create --trace --quiet --file --verbose --canonical'
# New style of Debian bash completion use load on demand of
# files. Unfortunately, cme plugins come with bash completions
# snippets that are not loaded with this mechanism. Hence, these lines
# circumvent delayed for the bash completions of cme plugins
for file in /usr/share/bash-completion/completions/cme[-_]*
do
. $file
done
_cme_models()
{
MODELS=$(perl -MConfig::Model::Lister -e'print Config::Model::Lister::models;')
COMPREPLY=( $( compgen -W "$MODELS" -- $cur ) )
}
_cme_appli()
{
MODELS=$(perl -MConfig::Model::Lister -e'print Config::Model::Lister::applications;')
COMPREPLY=( $( compgen -W "$MODELS" -- $cur ) )
}
_cme_commands()
{
# use perl so that plugged in subcommand (like meta) are listed
SUBCMDS=$(perl -MApp::Cme -e'print join("\n", grep {not /-/} App::Cme->new->command_names);')
COMPREPLY=( $( compgen -W "$SUBCMDS" -- $cur ) )
}
_cme_cmd_run()
{
vendor_scripts=$(perl -MConfig::Model::Lister -E 'my $p = $INC{"Config/Model/Lister.pm"}; $p =~ s/Lister.pm/scripts/; say $p')
if [[ $COMP_CWORD -eq 2 ]] ; then
scripts=$(find ~/.cme/scripts/ /etc/cme/scripts $vendor_scripts -type f ! -name '*~' -printf '%f\n' 2>/dev/null)
COMPREPLY=( $( compgen -W "-list $scripts" -- $cur ) )
elif [[ $prev == '-arg' ]]; then
script=$(find ~/.cme/scripts/ /etc/cme/scripts $vendor_scripts -type f -name ${COMP_WORDS[2]})
var=$( perl -E 'my @v; while(<>) { push @v, /\$(\w+)/g }; my %map = map { ($_ => 1)} @v; print map { "$_= " } sort keys %map;' $script);
COMPREPLY=( $( compgen -W "$var" -- $cur ) )
elif [[ $prev != '-list' ]]; then
COMPREPLY=( $( compgen -W "--arg --doc --commit --no-commit --cat $global_options" -- $cur ) )
fi
}
_cme_handle_app_arg()
{
[[ $COMP_CWORD -eq 3 ]] && _cme_${COMP_WORDS[2]} 2> /dev/null ;
}
_cme_handle_cmd_arg()
{
[[ $COMP_CWORD -ge 2 ]] && _cme_cmd_${COMP_WORDS[1]} 2> /dev/null ;
}
_cme()
{
local cur
COMPREPLY=()
_get_comp_words_by_ref -n : cur prev
if [[ $COMP_CWORD -eq 1 ]] ; then
_cme_commands
elif _cme_handle_cmd_arg; then
TRASH=1; # bash does not support empty then/elif
elif [[ $COMP_CWORD -eq 2 ]] ; then
_cme_appli
elif ! _cme_handle_app_arg; then
case $prev in
--ui)
COMPREPLY=( $( compgen -W 'tk curses shell' -- $cur ) )
;;
--dumptype)
COMPREPLY=( $( compgen -W 'full preset custom' -- $cur ) )
;;
--format)
COMPREPLY=( $( compgen -W 'yaml json perl cml' -- $cur ) )
;;
--model-dir|-root-dir|-fuse-dir)
_filedir -d
;;
--file)
_filedir
;;
*)
case ${COMP_WORDS[1]} in
check)
COMPREPLY=( $( compgen -W "$global_options --strict" -- $cur ) )
;;
dump)
COMPREPLY=( $( compgen -W "$global_options --dumptype --format" -- $cur ) )
;;
edit)
COMPREPLY=( $( compgen -W "$global_options --ui --open-item" -- $cur ) )
;;
fix)
COMPREPLY=( $( compgen -W "$global_options --from --filter" -- $cur ) )
;;
fusefs)
COMPREPLY=( $( compgen -W "$global_options --fuse-dir --dfuse --dir-char" -- $cur ) )
;;
migrate)
COMPREPLY=( $( compgen -W "$global_options" -- $cur ) )
;;
update)
COMPREPLY=( $( compgen -W "$global_options" -- $cur ) )
;;
# modify completion could be much more elaborate...
modify)
COMPREPLY=( $( compgen -W "$global_options --save --backup --format" -- $cur ) )
;;
run)
COMPREPLY=( $( compgen -W "$global_options --doc --cat --no-commit" -- $cur ) )
;;
search)
COMPREPLY=( $( compgen -W "$global_options --search --narrow-search" -- $cur ) )
;;
esac
esac
fi
}
complete -F _cme cme
|