Merge lp:~benoit.pierre/bzrtools/shell_improvements into lp:bzrtools

Proposed by Benoit Pierre
Status: Rejected
Rejected by: Aaron Bentley
Proposed branch: lp:~benoit.pierre/bzrtools/shell_improvements
Merge into: lp:bzrtools
Diff against target: None lines
To merge this branch: bzr merge lp:~benoit.pierre/bzrtools/shell_improvements
Reviewer Review Type Date Requested Status
Aaron Bentley Needs Resubmitting
Review via email: mp+9547@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Benoit Pierre (benoit.pierre) wrote :

Various improvements for the shell command:

- allow killing the current command line and start with a new one with ^C like
  most shells do (which also helps avoiding killing the shell by mistake when
  one's timing is off when trying to interrupt a command in progress), ^D can
  be used to exit when on an empty line

- catch shlex.split ValueError exceptions: the erroneous command can be edited
  again by using <up> to navigate the readline history

  (fix https://bugs.launchpad.net/bzrtools/+bug/231020)

- add global config aliases to the list of possible commands when completing

- fix shell handling of alias so for example "s|grep pattern" correctly works
  if s is an alias

- add wrapper for reconfigure/switch command so prompt gets updated to reflect
  the new tree

  (fix https://bugs.launchpad.net/bzrtools/+bug/231110)

Revision history for this message
Aaron Bentley (abentley) wrote :
Download full text (5.5 KiB)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Benoit,

Thanks for your patch. I'm sorry about the delay responding.

In general, please submit changes separately. It wasn't easy for me to
review initially, which contributed to the delay.

 review resubmit

Benoit PIERRE wrote:
> Benoit PIERRE has proposed merging lp:~benoit.pierre/bzrtools/shell_improvements into lp:bzrtools.
>
> Requested reviews:
> Aaron Bentley (abentley)
>
> Various improvements for the shell command:
>
> - allow killing the current command line and start with a new one with ^C like
> most shells do (which also helps avoiding killing the shell by mistake when
> one's timing is off when trying to interrupt a command in progress), ^D can
> be used to exit when on an empty line

I think what you mean is that ^C no longer kills the shell permanently.
  Is that right? I don't see anything that specifically enables killing
commands.

> - catch shlex.split ValueError exceptions: the erroneous command can be edited
> again by using <up> to navigate the readline history

What can cause a ValueError?

> (fix https://bugs.launchpad.net/bzrtools/+bug/231020)

Btw, don't be shy to link your branch to the bugs it fixes. This will
show up in the merge proposal.

>
> - add global config aliases to the list of possible commands when completing
>
> - fix shell handling of alias so for example "s|grep pattern" correctly works
> if s is an alias
>
> - add wrapper for reconfigure/switch command so prompt gets updated to reflect
> the new tree
>
> (fix https://bugs.launchpad.net/bzrtools/+bug/231110)
>
>
>

> === modified file 'shell.py'
> --- shell.py 2008-02-13 04:58:32 +0000
> +++ shell.py 2009-08-02 13:35:17 +0000
> @@ -26,7 +26,7 @@
>
> from bzrlib import osutils
> from bzrlib.branch import Branch
> -from bzrlib.config import config_dir, ensure_config_dir_exists
> +from bzrlib.config import config_dir, ensure_config_dir_exists, GlobalConfig
> from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
> from bzrlib.errors import BzrError
> from bzrlib.workingtree import WorkingTree
> @@ -36,6 +36,7 @@
>
> SHELL_BLACKLIST = set(['rm', 'ls'])
> COMPLETION_BLACKLIST = set(['shell'])
> +COMPLEX_COMMAND_CHARS = ('|', '<', '>', '&', '*', '?')

I thought using a string was cute, but if we're going to use the correct
container type, we should use a set.

>
>
> class BlackListedCommand(BzrError):
> @@ -167,18 +168,37 @@
> def do_help(self, line):
> self.default("help "+line)
>
> + def exec_and_update_tree(self, line):
> + result = self.default(line)
> + try:
> + self.tree = WorkingTree.open_containing(".")[0]
> + except:
> + self.tree = None
> + return result
> +
> + def do_switch(self, line):
> + return self.exec_and_update_tree('switch ' + line)

This is okay, but I think it would be better to just put 'switch' and
'reconfigure' in a set like the COMPLETION_BLACKLIST, and then update
the tree when commands in that set are encountered.

> + def do_reconfigure(self, line):
> + return self.exec_and_update_tree('reconfigure ' + line)
> +
> def def...

Read more...

review: Needs Resubmitting
Revision history for this message
Benoit Pierre (benoit.pierre) wrote :

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Benoit,
>
> Thanks for your patch. I'm sorry about the delay responding.
>
> In general, please submit changes separately. It wasn't easy for me to
> review initially, which contributed to the delay.
>
> review resubmit
>
> Benoit PIERRE wrote:
> > Benoit PIERRE has proposed merging
> lp:~benoit.pierre/bzrtools/shell_improvements into lp:bzrtools.
> >
> > Requested reviews:
> > Aaron Bentley (abentley)
> >
> > Various improvements for the shell command:
> >
> > - allow killing the current command line and start with a new one with ^C like
> > most shells do (which also helps avoiding killing the shell by mistake when
> > one's timing is off when trying to interrupt a command in progress), ^D can
> > be used to exit when on an empty line
>
> I think what you mean is that ^C no longer kills the shell permanently.
> Is that right?

Yes, separate merge proposal: https://code.launchpad.net/~benoit.pierre/bzrtools/shell_improvement_kbd_interrupt/+merge/12187

>
> > - catch shlex.split ValueError exceptions: the erroneous command can be edited
> > again by using <up> to navigate the readline history
>
> What can cause a ValueError?

From the shlex code: missing closing '/" or EOF after a \.

Separate merge proposal: https://code.launchpad.net/~benoit.pierre/bzrtools/shell_improvement_parse_errors/+merge/12188

Separate merge proposal for the rest will follow when I have time.

Unmerged revisions

692. By Benoit Pierre

Catch shlex.split ValueError exceptions.

691. By Benoit Pierre

Merge with upstream.

690. By Benoit Pierre

Add global config aliases to the list of possible commands when
completing in the shell.

689. By Benoit Pierre

Fix shell handling of alias so for example "s|grep pattern" correctly
works if s is an alias.

688. By Benoit Pierre

Factorize code in shell to use the same set of chars to detect complex
command line.

687. By Benoit Pierre

In shell, always update the prompt after a switch/reconfigure, even if
the result of the command is non 0 because in case of a complex command
we may actually not be testing the result of the switch/reconfigure
command itself, like for example: switch ../trunk | false.

686. By Benoit Pierre

Merge with upstream.

685. By Benoit Pierre

Factorize code and add wrapper for reconfigure command so prompt gets
updated to reflect the new tree.

684. By Benoit Pierre

Add shell switch builtin which is used to wrap the call to the bzr switch
command so we can update the shell prompt accordingly.

683. By Benoit Pierre

Allows killing the current command line and start with a new one with ^C
like most shells do (which also helps avoiding to kill the shell by
mistake when one's timing is off when trying to interrupt a command in
progress).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'shell.py'
2--- shell.py 2008-02-13 04:58:32 +0000
3+++ shell.py 2009-08-02 13:35:17 +0000
4@@ -26,7 +26,7 @@
5
6 from bzrlib import osutils
7 from bzrlib.branch import Branch
8-from bzrlib.config import config_dir, ensure_config_dir_exists
9+from bzrlib.config import config_dir, ensure_config_dir_exists, GlobalConfig
10 from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
11 from bzrlib.errors import BzrError
12 from bzrlib.workingtree import WorkingTree
13@@ -36,6 +36,7 @@
14
15 SHELL_BLACKLIST = set(['rm', 'ls'])
16 COMPLETION_BLACKLIST = set(['shell'])
17+COMPLEX_COMMAND_CHARS = ('|', '<', '>', '&', '*', '?')
18
19
20 class BlackListedCommand(BzrError):
21@@ -167,18 +168,37 @@
22 def do_help(self, line):
23 self.default("help "+line)
24
25+ def exec_and_update_tree(self, line):
26+ result = self.default(line)
27+ try:
28+ self.tree = WorkingTree.open_containing(".")[0]
29+ except:
30+ self.tree = None
31+ return result
32+
33+ def do_switch(self, line):
34+ return self.exec_and_update_tree('switch ' + line)
35+
36+ def do_reconfigure(self, line):
37+ return self.exec_and_update_tree('reconfigure ' + line)
38+
39 def default(self, line):
40- args = shlex.split(line)
41- alias_args = get_alias(args[0])
42- if alias_args is not None:
43- args[0] = alias_args.pop(0)
44+ try:
45+ args = shlex.split(line)
46+ except ValueError, e:
47+ print 'ValueError:', e
48+ return
49+ alias_args = None
50
51 commandname = args.pop(0)
52- for char in ('|', '<', '>'):
53+ for char in COMPLEX_COMMAND_CHARS:
54 commandname = commandname.split(char)[0]
55- if commandname[-1] in ('|', '<', '>'):
56+ if commandname[-1] in COMPLEX_COMMAND_CHARS:
57 commandname = commandname[:-1]
58 try:
59+ alias_args = get_alias(commandname)
60+ if alias_args is not None:
61+ commandname = alias_args.pop(0)
62 if commandname in SHELL_BLACKLIST:
63 raise BlackListedCommand(commandname)
64 cmd_obj = get_cmd_object(commandname)
65@@ -223,10 +243,13 @@
66 def run_shell():
67 try:
68 prompt = PromptCmd()
69- try:
70- prompt.cmdloop()
71- finally:
72- prompt.write_history()
73+ while True:
74+ try:
75+ prompt.cmdloop()
76+ except KeyboardInterrupt:
77+ print
78+ finally:
79+ prompt.write_history()
80 except StopIteration:
81 pass
82
83@@ -280,6 +303,8 @@
84
85
86 def iter_command_names(hidden=False):
87+ for alias in GlobalConfig().get_aliases().keys():
88+ yield alias
89 for real_cmd_name, cmd_class in get_all_cmds():
90 if not hidden and cmd_class.hidden:
91 continue
92@@ -312,7 +337,7 @@
93
94
95 def too_complicated(line):
96- for char in '|<>*?':
97+ for char in COMPLEX_COMMAND_CHARS:
98 if char in line:
99 return True
100 return False

Subscribers

People subscribed via source and target branches