mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
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.
This commit is contained in:
parent
a402f37fa4
commit
bb83bf89db
@ -99,14 +99,39 @@ _hg()
|
||||
return
|
||||
fi
|
||||
|
||||
# canonicalize command name
|
||||
cmd=$("$hg" -q help "$cmd" 2>/dev/null | sed -e 's/^hg //; s/ .*//; 1q')
|
||||
|
||||
if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then
|
||||
_hg_tags
|
||||
# try to generate completion candidates for whatever command the user typed
|
||||
local help
|
||||
local canonical=0
|
||||
if _hg_command_specific; then
|
||||
return
|
||||
fi
|
||||
|
||||
# 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)
|
||||
_hg_commands
|
||||
@ -152,8 +177,12 @@ _hg()
|
||||
debugdata)
|
||||
COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -o bashdefault -o default -F _hg hg 2>/dev/null \
|
||||
|
Loading…
Reference in New Issue
Block a user