[PATCH] show: config option to register aliases for views

Gregory Szorc gregory.szorc at gmail.com
Sun Jul 2 03:12:42 UTC 2017


On Wed, Jun 28, 2017 at 8:33 AM, Yuya Nishihara <yuya at tcha.org> wrote:

> On Sun, 25 Jun 2017 22:26:52 -0700, Gregory Szorc wrote:
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc at gmail.com>
> > # Date 1498454437 25200
> > #      Sun Jun 25 22:20:37 2017 -0700
> > # Node ID 6546ab6d7a9aaa4266d1decf3da1501153be796b
> > # Parent  ef46d432e2e4cfecafb1faa4765254bf0650d4ef
> > show: config option to register aliases for views
> >
> > As part of using `hg show` in my daily workflow, I've found it slightly
> > annoying to have to type full view names, complete with a space. I've
> > locally registered an alias for "swork = show work."
> >
> > I think others will have this same complaint and could benefit from
> > some automation to streamline the creation of aliases. So, this
> > commit introduces a config option that allows `hg show` views to be
> > automatically aliased using a given prefix. e.g. a value of "s"
> > will automatically register "swork" and "sbookmarks." Multiple
> > values can be given for ultimate flexibility. This arguably isn't
> > needed now. But since we don't register aliases if there will be
> > a collision and we're bound to have a collision, it makes sense to
> > allow multiple prefixes so specific views can avoid collisions by
> > using different prefixes.
>
> I think this change is okay. (I don't queue it now just because it's late.)
>
> Somewhat related to this, I've lost why we decided to make "hg show <cmd>"
> at the cost of managing sub-sub commands. If we want a shorter command
> name,
> I think "hg work" is even better.
>

A big reason is that `hg help show` can be a gateway to all available
views, thus fostering understanding. Also, `hg show` is guaranteed to be
read-only, so any command under it is safe to run. That means we shouldn't
scare people away from running `hg show` like other commands would.


>
> > +def extsetup(ui):
> > +    # Alias `hg <prefix><view>` to `hg show <view>`.
> > +    for prefix in ui.configlist('commands', 'show.aliasprefix'):
> > +        for view in showview._table:
> > +            name = '%s%s' % (prefix, view)
> > +
> > +            choice, allcommands = cmdutil.findpossible(name,
> commands.table,
> > +                                                       strict=True)
> > +
> > +            # This alias is already a command name. Don't set it.
> > +            if name in choice:
> > +                continue
> > +
> > +            # Same for aliases.
> > +            if ui.config('alias', name):
> > +                continue
> > +
> > +            ui.setconfig('alias', name, 'show %s' % view, source='show')
>
> Setting config in ui/extsetup() doesn't work in general, but we're lucky
> that
> addaliases() takes lui not ui.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170701/eb3c9f4d/attachment.html>


More information about the Mercurial-devel mailing list