Mercurial > hg-stable
changeset 2039:0c438fd25e6e
bash_completion: small optimization
Right now we always call "hg help $cmd" to get the canonical name of $cmd
(i.e. to go from "co" to "update").
This patch optimistically assumes that $cmd is already the canonical form
and tries to generate completions for it. If that fails, it falls back
to canonicalizing $cmd and trying again.
This means that:
- if a command or alias is explicitly handled by the
_hg_command_specific function, things get somewhat faster
- as long as the canonical $cmd is handled by _hg_command_specific, all
its aliases and abbreviations are also handled.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sun, 02 Apr 2006 18:20:52 +0200 |
parents | 5c4496ed152d |
children | cd7711268774 |
files | contrib/bash_completion |
diffstat | 1 files changed, 33 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/bash_completion Sun Apr 02 18:16:06 2006 +0200 +++ b/contrib/bash_completion Sun Apr 02 18:20:52 2006 +0200 @@ -99,13 +99,38 @@ return fi - # canonicalize command name - cmd=$("$hg" -q help "$cmd" 2>/dev/null | sed -e 's/^hg //; s/ .*//; 1q') + # try to generate completion candidates for whatever command the user typed + local help + local canonical=0 + if _hg_command_specific; then + return + fi - if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then - _hg_tags + # canonicalize the command name and try again + help=$("$hg" help "$cmd" 2>/dev/null) + if [ $? -ne 0 ]; then + # Probably either the command doesn't exist or it's ambiguous return fi + cmd=${help#hg } + cmd=${cmd%%[$' \n']*} + canonical=1 + _hg_command_specific +} + +_hg_command_specific() +{ + if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then + if [ $canonical = 1 ]; then + _hg_tags + return 0 + elif [[ status != "$cmd"* ]]; then + _hg_tags + return 0 + else + return 1 + fi + fi case "$cmd" in help) @@ -152,8 +177,12 @@ debugdata) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) ;; + *) + return 1 + ;; esac + return 0 } complete -o bashdefault -o default -F _hg hg 2>/dev/null \