2541
2541
print branch.nick
2544
class cmd_alias(Command):
2545
"""Set/unset and display aliases.
2548
Show the current aliases::
2552
Show the alias specified for 'll'::
2556
Set an alias for 'll'::
2558
bzr alias ll="log --line -r-10..-1"
2560
To remove an alias for 'll'::
2562
bzr alias --remove ll
2565
takes_args = ['name?']
2567
Option('remove', help='Remove the alias.'),
2570
def run(self, name=None, remove=False):
2572
self.remove_alias(name)
2574
self.print_aliases()
2576
equal_pos = name.find('=')
2578
self.print_alias(name)
2580
self.set_alias(name[:equal_pos], name[equal_pos+1:])
2582
def remove_alias(self, alias_name):
2583
if alias_name is None:
2584
raise errors.BzrCommandError(
2585
'bzr alias --remove expects an alias to remove.')
2586
# If alias is not found, print something like:
2587
# unalias: foo: not found
2588
c = config.GlobalConfig()
2589
c.unset_alias(alias_name)
2592
def print_aliases(self):
2593
"""Print out the defined aliases in a similar format to bash."""
2594
aliases = config.GlobalConfig().get_aliases()
2595
for key, value in sorted(aliases.iteritems()):
2596
self.outf.write('bzr alias %s="%s"\n' % (key, value))
2599
def print_alias(self, alias_name):
2600
from bzrlib.commands import get_alias
2601
alias = get_alias(alias_name)
2603
self.outf.write("bzr alias: %s: not found\n" % alias_name)
2606
'bzr alias %s="%s"\n' % (alias_name, ' '.join(alias)))
2608
def set_alias(self, alias_name, alias_command):
2609
"""Save the alias in the global config."""
2610
c = config.GlobalConfig()
2611
c.set_alias(alias_name, alias_command)
2544
2614
class cmd_selftest(Command):
2545
2615
"""Run internal test suite.