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.
add a new command debugcomplete, it lists all the possible
completion for the specified command.
make the bash_completion script uses it instead of the awk code
TK Soh noticed that the awk that ships with Solaris doesn't allow you
to define new functions. According to
http://www.shelldorado.com/articles/awkcompat.html
it looks like it also doesn't have some other stuff that we were using,
like deletion of an array element and gsub.
Rewrite the parsing of hg --debug help to work around that. This
version doesn't filter aliases that are simple abbreviations for debug
commands (not a big problem, since there are none right now).
- use awk to parse the output of hg help.
- print one completion candidate per line
- print the debug commands after regular commands
(this eases the shell side of the parsing)
- don't print aliases that are simple abbreviations
(e.g. up/update, id/identify)
- Use "hg status -n" option instead of cut command.
- Sort status flags accoring to "hg status --help"
- Show deleted files instead of "hg remove"d for "hg remove"
The current bash completion script is quite painful in conjuntion with
deep directory trees because it adds a space after each successful
directory completion. Eg. "hg clone /ho<tab>" is completed to "hg clone
/home " when what you really want is "hg clone /home/" (assuming the
complete path to the repository looks like /home/foo/hg...).
That's because the 'complete' command does not know about the type of
completion it receives from the _hg shell function. When only a single
completion is returned, it assumes completion is complete and tells
readline to add a trailing space. This behaviour is usually wanted, but
not in the case of directory completion.
I've attached a patch that circumvents this problem by only returning
successful completions for directories that contain a .hg subdirectory.
If no repositories are found, no completions are returned either, and
bash falls back to ordinary (filename) completion. I find this behaviour
a lot less annoying than the current one.
Alternative: Use option nospace for the 'complete' command and let _hg
itself take care of adding a trailing space where appropriate. That's a
far more intrusive change, though.
Use hg status to determine which files are interesting for various commands.
Thus, hg add [tab] finds unknown files, and hg commit [tab] finds added, modified, or removed files.
Contributed by "Alexis S. L. Carvalho" <alexis@cecm.usp.br>
Attached is a file that implements bash completion for hg. Just
reading it from your .bashrc should be enough to use it - I think: I'm
using the /etc/bash_completion from debian and I'm not sure whether it
sets some important option.
It gets the list of commands, aliases and options from the output of hg
help and then adds some specific stuff - e.g. completing update with
tags; pull and push with path aliases and directories, etc.