3
from bzrlib import plugin
4
from bzrlib import commands
1
7
# Programmable completion for the Bazaar-NG bzr command under bash. Source
2
8
# this file (or on some systems add it to ~/.bash_completion and start a new
3
9
# shell) and bash's completion mechanism will know all about bzr's options!
35
42
case ${COMP_WORDS[1]} in
37
cmdOpts="--all --show-ids"
40
cmdOpts="-r --revision --diff-options"
43
cmdOpts="-r --message -F --file -v --verbose"
49
cmdOpts="-v --verbose"
52
cmdOpts="--forward --timezone -v --verbose --show-ids -r --revision"
64
cmdOpts="$cmds $qOpts"
70
cmdOpts="$cmdOpts --help -h"
72
51
# take out options already given
73
52
for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do
81
60
cmdOpts=" $cmdOpts "
82
61
cmdOpts=${cmdOpts/ ${optBase} / }
84
# take out alternatives
63
# take out some alternatives
86
-v) cmdOpts=${cmdOpts/ --verbose / } ;;
87
--verbose) cmdOpts=${cmdOpts/ -v / } ;;
88
-h) cmdOpts=${cmdOpts/ --help / } ;;
89
--help) cmdOpts=${cmdOpts/ -h / } ;;
90
-r) cmdOpts=${cmdOpts/ --revision / } ;;
91
--revision) cmdOpts=${cmdOpts/ -r / } ;;
94
68
# skip next option if this one requires a parameter
104
78
complete -F _bzr -o default bzr
81
def bash_completion_function(out):
86
for name in sorted(commands.all_command_names()):
87
cmd = commands.get_cmd_object(name)
90
for alias in cmd.aliases:
94
plugin = cmd.plugin_name()
95
if plugin is not None:
96
cases += "\t\t# plugin \"%s\"\n" % plugin
99
for optname in sorted(cmd.options()):
102
for (name, short_name, optname, help) in opt.iter_switches():
103
if short_name is not None:
104
optset.add("-" + short_name)
106
optset.add("--" + name)
107
for optname in optset:
108
if optname not in optaliases:
109
optaliases[optname] = optset
111
optaliases[optname] &= optset
112
optnames.extend(sorted(optset))
113
cases += "\t\tcmdOpts='" + " ".join(optnames) + "'\n\t\t;;\n"
115
for opt1 in sorted(optaliases):
116
optset = optaliases[opt1]
119
optalt += "\t\t" + opt1 + ")\n"
120
for opt2 in sorted(optset):
122
optalt += "\t\t\tcmdOpts=${cmdOpts/ " + opt2 + " / }\n"
123
optalt += "\t\t\t;;\n"
124
out.write(template % {"cmds": " ".join(aliases),
128
if __name__ == '__main__':
133
locale.setlocale(locale.LC_ALL, '')
134
plugin.load_plugins()
135
commands.install_bzr_command_hooks()
136
bash_completion_function(sys.stdout)