Mercurial > hg
comparison hgext/show.py @ 33137:99ce2f586cd4
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 25 Jun 2017 22:20:37 -0700 |
parents | 11f768258dcc |
children | c5a07a3abe7d |
comparison
equal
deleted
inserted
replaced
33136:59c135bb31bc | 33137:99ce2f586cd4 |
---|---|
8 """unified command to show various repository information (EXPERIMENTAL) | 8 """unified command to show various repository information (EXPERIMENTAL) |
9 | 9 |
10 This extension provides the :hg:`show` command, which provides a central | 10 This extension provides the :hg:`show` command, which provides a central |
11 command for displaying commonly-accessed repository data and views of that | 11 command for displaying commonly-accessed repository data and views of that |
12 data. | 12 data. |
13 | |
14 The following config options can influence operation. | |
15 | |
16 ``commands`` | |
17 ------------ | |
18 | |
19 ``show.aliasprefix`` | |
20 List of strings that will register aliases for views. e.g. ``s`` will | |
21 effectively set config options ``alias.s<view> = show <view>`` for all | |
22 views. i.e. `hg swork` would execute `hg show work`. | |
23 | |
24 Aliases that would conflict with existing registrations will not be | |
25 performed. | |
13 """ | 26 """ |
14 | 27 |
15 from __future__ import absolute_import | 28 from __future__ import absolute_import |
16 | 29 |
17 from mercurial.i18n import _ | 30 from mercurial.i18n import _ |
18 from mercurial.node import nullrev | 31 from mercurial.node import nullrev |
19 from mercurial import ( | 32 from mercurial import ( |
20 cmdutil, | 33 cmdutil, |
34 commands, | |
21 error, | 35 error, |
22 formatter, | 36 formatter, |
23 graphmod, | 37 graphmod, |
24 pycompat, | 38 pycompat, |
25 registrar, | 39 registrar, |
216 revdag = graphmod.dagwalker(repo, revs) | 230 revdag = graphmod.dagwalker(repo, revs) |
217 | 231 |
218 ui.setconfig('experimental', 'graphshorten', True) | 232 ui.setconfig('experimental', 'graphshorten', True) |
219 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) | 233 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) |
220 | 234 |
235 def extsetup(ui): | |
236 # Alias `hg <prefix><view>` to `hg show <view>`. | |
237 for prefix in ui.configlist('commands', 'show.aliasprefix'): | |
238 for view in showview._table: | |
239 name = '%s%s' % (prefix, view) | |
240 | |
241 choice, allcommands = cmdutil.findpossible(name, commands.table, | |
242 strict=True) | |
243 | |
244 # This alias is already a command name. Don't set it. | |
245 if name in choice: | |
246 continue | |
247 | |
248 # Same for aliases. | |
249 if ui.config('alias', name): | |
250 continue | |
251 | |
252 ui.setconfig('alias', name, 'show %s' % view, source='show') | |
253 | |
221 # Adjust the docstring of the show command so it shows all registered views. | 254 # Adjust the docstring of the show command so it shows all registered views. |
222 # This is a bit hacky because it runs at the end of module load. When moved | 255 # This is a bit hacky because it runs at the end of module load. When moved |
223 # into core or when another extension wants to provide a view, we'll need | 256 # into core or when another extension wants to provide a view, we'll need |
224 # to do this more robustly. | 257 # to do this more robustly. |
225 # TODO make this more robust. | 258 # TODO make this more robust. |