You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ja...@apache.org on 2013/10/30 16:12:15 UTC

svn commit: r1537126 - in /karaf/trunk: assemblies/features/framework/src/main/resources/resources/etc/ instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/ shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/

Author: janstey
Date: Wed Oct 30 15:12:14 2013
New Revision: 1537126

URL: http://svn.apache.org/r1537126
Log:
KARAF-2503 - add option to limit the number of entries the history remembers

Modified:
    karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties
    karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
    karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/ConsoleImpl.java

Modified: karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties?rev=1537126&r1=1537125&r2=1537126&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties (original)
+++ karaf/trunk/assemblies/features/framework/src/main/resources/resources/etc/system.properties Wed Oct 30 15:12:14 2013
@@ -50,6 +50,12 @@ karaf.default.repository=system
 karaf.shell.init.script=${karaf.home}/etc/shell.init.script
 
 #
+# Sets the maximum size of the shell command history. If not set,
+# defaults to 500 entries. Setting to 0 will disable history.
+#
+# karaf.shell.history.maxSize=0
+
+#
 # Deletes the entire karaf.data directory at every start
 #
 karaf.clean.all=false

Modified: karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties
URL: http://svn.apache.org/viewvc/karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties?rev=1537126&r1=1537125&r2=1537126&view=diff
==============================================================================
--- karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties (original)
+++ karaf/trunk/instance/core/src/main/resources/org/apache/karaf/instance/resources/etc/system.properties Wed Oct 30 15:12:14 2013
@@ -50,6 +50,12 @@ karaf.default.repository=system
 karaf.shell.init.script=${karaf.home}/etc/shell.init.script
 
 #
+# Sets the maximum size of the shell command history. If not set,
+# defaults to 500 entries. Setting to 0 will disable history.
+#
+# karaf.shell.history.maxSize=0
+
+#
 # Deletes the entire karaf.data directory at every start
 #
 karaf.clean.all=false

Modified: karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/ConsoleImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/ConsoleImpl.java?rev=1537126&r1=1537125&r2=1537126&view=diff
==============================================================================
--- karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/ConsoleImpl.java (original)
+++ karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/ConsoleImpl.java Wed Oct 30 15:12:14 2013
@@ -38,6 +38,7 @@ import java.util.regex.Pattern;
 import jline.Terminal;
 import jline.UnsupportedTerminal;
 import jline.console.ConsoleReader;
+import jline.console.history.MemoryHistory;
 import jline.console.history.PersistentHistory;
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
@@ -57,6 +58,7 @@ import org.slf4j.LoggerFactory;
 public class ConsoleImpl implements Console {
 
     public static final String SHELL_INIT_SCRIPT = "karaf.shell.init.script";
+    public static final String SHELL_HISTORY_MAXSIZE = "karaf.shell.history.maxSize";
     public static final String PROMPT = "PROMPT";
     public static final String DEFAULT_PROMPT = "\u001B[1m${USER}\u001B[0m@${APPLICATION}(${SUBSHELL})> ";
 
@@ -117,6 +119,14 @@ public class ConsoleImpl implements Cons
         } catch (Exception e) {
             LOGGER.error("Can not read history from file " + file + ". Using in memory history", e);
         }
+        
+        if (reader != null && reader.getHistory() instanceof MemoryHistory) {
+            String maxSizeStr = System.getProperty(SHELL_HISTORY_MAXSIZE);
+            if (maxSizeStr != null) {
+                ((MemoryHistory)reader.getHistory()).setMaxSize(Integer.parseInt(maxSizeStr));   
+            }
+        }
+        
         session.put(".jline.reader", reader);
         session.put(".jline.history", reader.getHistory());
         Completer completer = createCompleter();