Updated Branches:
  refs/heads/cassandra-1.1 751e58d1e -> 5551d9c39
  refs/heads/trunk aa8989d9b -> a26eb3ef6


cqlsh: combine multiline statements into single line history
Patch by Matthew Horsfall, reviewed by brandonwilliams for
CASSANDRA-4666


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a26eb3ef
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a26eb3ef
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a26eb3ef

Branch: refs/heads/trunk
Commit: a26eb3ef66ab7370d5187fd1e0e5a0d088bdaaa1
Parents: aa8989d
Author: Brandon Williams <[email protected]>
Authored: Thu Sep 13 15:47:26 2012 -0500
Committer: Brandon Williams <[email protected]>
Committed: Thu Sep 13 15:48:43 2012 -0500

----------------------------------------------------------------------
 bin/cqlsh |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a26eb3ef/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 9e06b2b..f60cfe9 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -408,6 +408,7 @@ class Shell(cmd.Cmd):
     show_line_nums = False
     debug = False
     stop = False
+    last_hist = None
     shunted_query_out = None
     csv_dialect_defaults = dict(delimiter=',', doublequote=False,
                                 escapechar='\\', quotechar='"')
@@ -797,6 +798,16 @@ class Shell(cmd.Cmd):
         self.do_exit()
 
     def handle_statement(self, tokens, srcstr):
+        # Concat multi-line statements and insert into history
+        if readline is not None:
+            nl_count = srcstr.count("\n")
+
+            new_hist = srcstr.replace("\n", " ").rstrip()
+
+            if nl_count > 1 and self.last_hist != new_hist:
+                readline.add_history(new_hist)
+
+            self.last_hist = new_hist
         cmdword = tokens[0][1]
         if cmdword == '?':
             cmdword = 'help'

Reply via email to