karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [3/3] karaf git commit: [KARAF-397] Allow completion of non Karaf based osgi commands [KARAF-2454] Portable way to make custom shell commands
Date Wed, 19 Oct 2016 09:28:19 GMT
[KARAF-397] Allow completion of non Karaf based osgi commands
[KARAF-2454] Portable way to make custom shell commands

Leverage more of the gogo-jline bundle, such as builtin commands, completion mechanism.
Remove duplicate commands from Karaf (which has the benefit of making sure all builtin commands are available when the session is created, so when the initialization script runs).

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

Branch: refs/heads/master
Commit: f1dd4a94c8d3cd05ca35513256e9e787dffc42c9
Parents: 42ef364
Author: Guillaume Nodet <gnodet@apache.org>
Authored: Wed Oct 12 11:14:43 2016 +0200
Committer: Guillaume Nodet <gnodet@apache.org>
Committed: Wed Oct 19 11:05:32 2016 +0200

----------------------------------------------------------------------
 .../etc/org.apache.karaf.command.acl.shell.cfg  |   2 +-
 .../etc/scripts/shell.completion.script         | 238 +++++++++++
 .../resources/resources/etc/shell.init.script   |  19 +
 .../resources/resources/etc/system.properties   |   8 +-
 .../karaf/itests/ShellCommandSecurityTest.java  |   6 +-
 pom.xml                                         |   6 +-
 .../karaf/shell/commands/impl/AliasAction.java  |  42 --
 .../karaf/shell/commands/impl/CatAction.java    | 125 ------
 .../karaf/shell/commands/impl/ClearAction.java  |  39 --
 .../karaf/shell/commands/impl/DateAction.java   | 132 ------
 .../karaf/shell/commands/impl/EachAction.java   |  53 ---
 .../karaf/shell/commands/impl/EchoAction.java   |  57 ---
 .../karaf/shell/commands/impl/EditAction.java   |  55 ---
 .../karaf/shell/commands/impl/EnvAction.java    |  52 ---
 .../karaf/shell/commands/impl/GrepAction.java   | 260 ------------
 .../karaf/shell/commands/impl/HeadAction.java   | 108 -----
 .../shell/commands/impl/HistoryAction.java      |  56 ---
 .../karaf/shell/commands/impl/IfAction.java     |  75 ----
 .../karaf/shell/commands/impl/LessAction.java   | 104 -----
 .../karaf/shell/commands/impl/MoreAction.java   | 144 -------
 .../karaf/shell/commands/impl/NewAction.java    | 379 -----------------
 .../karaf/shell/commands/impl/SleepAction.java  |  58 ---
 .../karaf/shell/commands/impl/SortAction.java   | 404 -------------------
 .../karaf/shell/commands/impl/TacAction.java    |  77 ----
 .../karaf/shell/commands/impl/TailAction.java   | 136 -------
 .../karaf/shell/commands/impl/WcAction.java     | 218 ----------
 .../karaf/shell/commands/impl/WhileAction.java  |  73 ----
 .../services/org/apache/karaf/shell/commands    |  19 -
 .../apache/karaf/shell/commands/impl/grep.txt   |   1 -
 .../org/apache/karaf/shell/commands/impl/wc.txt |  35 --
 .../karaf/shell/commands/impl/GrepTest.java     | 312 --------------
 .../karaf/shell/commands/impl/SortTest.java     |  91 -----
 shell/console/pom.xml                           |   7 +-
 .../karaf/shell/compat/CommandTracker.java      | 101 +----
 .../impl/SecuredCommandProcessorImpl.java       |   9 +-
 shell/core/pom.xml                              |   3 +-
 .../shell/impl/console/CommandWrapper.java      |   7 +-
 .../shell/impl/console/ConsoleSessionImpl.java  | 118 ++++--
 .../shell/impl/console/HistoryWrapper.java      |   2 +-
 .../shell/impl/console/SessionFactoryImpl.java  | 100 ++---
 .../shell/impl/console/osgi/Activator.java      |   6 +
 .../shell/impl/console/osgi/CommandTracker.java | 118 ++++++
 .../impl/console/osgi/EventAdminListener.java   |   2 +-
 .../osgi/LoggingCommandSessionListener.java     |   2 +-
 .../console/osgi/secured/SecuredCommand.java    |  28 +-
 45 files changed, 560 insertions(+), 3327 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/assemblies/features/base/src/main/resources/resources/etc/org.apache.karaf.command.acl.shell.cfg
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/etc/org.apache.karaf.command.acl.shell.cfg b/assemblies/features/base/src/main/resources/resources/etc/org.apache.karaf.command.acl.shell.cfg
index 28880b6..2afc19b 100644
--- a/assemblies/features/base/src/main/resources/resources/etc/org.apache.karaf.command.acl.shell.cfg
+++ b/assemblies/features/base/src/main/resources/resources/etc/org.apache.karaf.command.acl.shell.cfg
@@ -23,7 +23,7 @@
 # For an explanation of the syntax of this file, see the file:
 #   org.apache.karaf.command.acl.system.cfg
 #
-edit = admin
+nano = admin
 exec = admin
 new = admin
 java = admin

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/assemblies/features/base/src/main/resources/resources/etc/scripts/shell.completion.script
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/etc/scripts/shell.completion.script b/assemblies/features/base/src/main/resources/resources/etc/scripts/shell.completion.script
new file mode 100644
index 0000000..e8595e5
--- /dev/null
+++ b/assemblies/features/base/src/main/resources/resources/etc/scripts/shell.completion.script
@@ -0,0 +1,238 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// This script is run each time a shell is created.
+// You can define here closures or variables that will be available
+// in each session.
+//
+
+__option_not_present = {
+  res = true
+  opts = $argv
+  each $opts {
+      arg = $it
+      each ($.commandLine words) {
+          if { ($it toString) equals ($arg toString) } {
+              res = false
+          }
+      }
+  }
+  $res
+}
+
+__set_unset_arguments = {
+  is_setopt = (($.commandLine words) get 0) equals "setopt"
+  enums = ((__load_class 'org.jline.reader.LineReader$Option') enumConstants)
+  candidates = new ArrayList
+  each $enums {
+      name = ${(GL)it/_/-}
+      is_set = ($.reader isSet $it)
+      neg = %(( if(is_setopt, is_set, not(is_set)) ))
+      if { $neg } {
+          name = "no-${name}"
+      }
+      if { not  { (($.commandLine words) subList 1 ($.commandLine wordIndex)) contains $name } } {
+          $candidates add (new org.jline.reader.Candidate $name $name (if { $neg } { "unset" } { "set" }) null null null true)
+      }
+  }
+  $candidates
+}
+
+
+complete -c shell:complete -e
+complete -c shell:complete -d "Edit command specific completions"
+complete -c shell:complete -s c -l command --description "Command to add completion to" -n '__option_not_present -c --command' -a '$.commands'
+complete -c shell:complete -s s -l short-option --description "Posix-style option to complete" -n '__option_not_present -s --short-option'
+complete -c shell:complete -s l -l long-option --description "GNU-style option to complete" -n '__option_not_present -l --long-option'
+complete -c shell:complete -s a -l arguments --description "A list of possible arguments" -n '__option_not_present -a --argument'
+complete -c shell:complete -s d -l description --description "Description of this completions" -n '__option_not_present -d --description'
+complete -c shell:complete -s h -l help --description "Display help and exit" -n '__option_not_present -h --help'
+complete -c shell:complete -s n -l condition --description "The completion should only be used if the specified command has a zero exit status"  -n '__option_not_present -n --condition'
+complete -c shell:complete -s e -l erase --description "Remove completion"  -n '__option_not_present -e --erase'
+
+complete -c shell:history -e
+complete -c shell:history -d "Show and manipulate command history"
+complete -c shell:history -l clear --description "Clear history" -n '__option_not_present --clear'
+complete -c shell:history -l save --description "Save history" -n '__option_not_present --save'
+
+complete -c shell:setopt -e
+complete -c shell:setopt -d "Set or view set shell options"
+complete -c shell:setopt -a '__set_unset_arguments'
+
+complete -c shell:unsetopt -e
+complete -c shell:unsetopt -d "Unset or view unset shell options"
+complete -c shell:unsetopt -a '__set_unset_arguments'
+
+complete -c shell:cat -e
+complete -c shell:cat -d "Concatenate and print files"
+complete -c shell:cat -s n "Number the output lines, starting at 1"
+complete -c shell:cat -a '__files'
+
+complete -c shell:pwd -e
+complete -c shell:pwd -d "Get current directory"
+
+complete -c shell:ls -e
+complete -c shell:ls -d "List files"
+
+complete -c shell:cd -e
+complete -c shell:cd -d "Change current directory"
+complete -c shell:cd -a '__directories'
+
+complete -c shell:sleep -e
+complete -c shell:sleep -d "Pause execution for the specified amount of time"
+
+complete -c shell:echo -e
+complete -c shell:echo -d "Write arguments to the standard output"
+complete -c shell:echo -s n -d "No trailing new line"
+
+complete -c shell:grep -e
+complete -c shell:grep -d "File pattern searcher"
+# TODO
+
+complete -c shell:sort -e
+complete -c shell:sort -d "Sort lines of text files"
+# TODO
+
+complete -c shell:gosh -e
+complete -c shell:gosh -d "Execute script with arguments in a new session"
+# TODO
+
+complete -c shell:sh -e
+complete -c shell:sh -d "Execute script with arguments in a new session"
+# TODO
+
+complete -c shell:source -e
+complete -c shell:source -d "Execute script with arguments"
+# TODO
+
+# TODO: format getopt new set tac type addcommand removeCommand eval
+
+complete -c shell:break -e
+complete -c shell:break -d "Break from a loop"
+
+complete -c shell:continue -e
+complete -c shell:continue -d "Continue to next iteration in a loop"
+
+complete -c shell:each -e
+complete -c shell:each -d "Loop and execute script on the specified elements"
+
+complete -c shell:if -e
+complete -c shell:if -d "Conditionaly execute a script"
+
+complete -c shell:new -e
+complete -c shell:new -d "Creates new instance of the given java class"
+
+complete -c shell:not -e
+complete -c shell:not -d "Negates the result of a script"
+
+complete -c shell:throw -e
+complete -c shell:throw -d "Throws an exception"
+
+complete -c shell:try -e
+complete -c shell:try -d "Try executing a script and catch any exception"
+
+complete -c shell:until -e
+complete -c shell:until -d "Loop and execute script until a condition is satisfied"
+
+complete -c shell:while -e
+complete -c shell:while -d "Loop and execute script while a condition is satisfied"
+
+complete -c shell:less -e
+complete -c shell:less -d "File pager"
+complete -c shell:less -s e -l quit-at-eof --description "Exit on second EOF"
+complete -c shell:less -s E -l QUIT-AT-EOF --description "Exit on EOF"
+complete -c shell:less -s q -l quiet -l silent --description "Silent mode"
+complete -c shell:less -s Q -l QUIET -l SILENT --description "Completely  silent"
+complete -c shell:less -s S -l chop-long-lines --description "Do not fold long lines"
+complete -c shell:less -s i -l ignore-case --description "Search ignores lowercase case"
+complete -c shell:less -s I -l IGNORE-CASE --description "Search ignores all case"
+complete -c shell:less -s x -l tabs --description "Set tab stops"
+complete -c shell:less -s N -l LINE-NUMBERS --description "Display line number for each line"
+complete -c shell:less -a '__files'
+
+complete -c shell:nano -e
+complete -c shell:nano -d "File editor"
+complete -c shell:nano -a '__files'
+
+complete -c shell:keymap -e
+complete -c shell:keymap -d "Manipulate keymaps"
+complete -c shell:keymap -s N --description "Create a new keymap" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s d --description "Delete existing keymaps and reset to default state" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s D --description "Delete named keymaps" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s l --description "List existing keymap names" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s r --description "Unbind specified in-strings" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s s --description "Bind each in-string to each out-string" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s A --description "Create alias to keymap" -n '__option_not_present -N -d -D -l -r -s -A'
+complete -c shell:keymap -s e --description "Select emacs keymap and bind it to main" -n '__option_not_present -e -a -v -M'
+complete -c shell:keymap -s v --description "Select viins keymap and bind it to main" -n '__option_not_present -e -a -v -M'
+complete -c shell:keymap -s a --description "Select vicmd keymap" -n '__option_not_present -e -a -v -M'
+complete -c shell:keymap -s M --description "Specify keymap to select" -n '__option_not_present -e -a -v -M' -a '(keymap -l | tac) split " "'
+complete -c shell:keymap -s R --description "Interpret in-strings as ranges"
+complete -c shell:keymap -s p --description "List bindings which have given key sequence as a a prefix"
+complete -c shell:keymap -s L --description "Output in form of keymap commands"
+
+complete -c shell:widget -e
+complete -c shell:widget -d "Manipulate widgets"
+complete -c shell:widget -s N --description "Create a new widget" -n '__option_not_present -N -A -D -U -l'
+complete -c shell:widget -s A --description "Create alias to widget" -n '__option_not_present -N -A -D -U -l'
+complete -c shell:widget -s D --description "Delete widgets" -n '__option_not_present -N -A -D -U -l'
+complete -c shell:widget -s U --description "Push characters to the stack" -n '__option_not_present -N -A -D -U -l'
+complete -c shell:widget -s l --description "List user-defined widgets" -n '__option_not_present -N -A -D -U -l'
+complete -c shell:widget -s a --description "With -l, list all widgets" -n '__option_not_present -l'
+
+complete -c shell:bg -e
+complete -c shell:bg -d "Put job in background"
+
+complete -c shell:fg -e
+complete -c shell:fg -d "Put job in foreground"
+
+complete -c shell:jobs -e
+complete -c shell:jobs -d "List jobs"
+
+complete -c shell:clear -e
+complete -c shell:clear -d "Clear screen"
+
+complete -c shell:head -e
+complete -c shell:head -d "Displays first lines of file"
+complete -c shell:head -s n -l lines --description "Print line counts"
+complete -c shell:head -s c -l bytes --description "Print byte counts"
+complete -c shell:head -a '__files'
+
+complete -c shell:tail -e
+complete -c shell:tail -d "Displays last lines of file"
+complete -c shell:tail -s q -l quiet --description "Suppress headers when printing multiple sources"
+complete -c shell:tail -s f -l follow --description "Do not stop at end of file"
+complete -c shell:tail -s F -l FOLLOW --description "Follow and check for file renaming or rotation"
+complete -c shell:tail -s n -l lines --description "Number of lines to print"
+complete -c shell:tail -s c -l bytes --description "Number of bytes to print"
+complete -c shell:tail -a '__files'
+
+complete -c shell:date -e
+complete -c shell:date -d "Display date and time"
+complete -c shell:date -s u --description "Use UTC"
+complete -c shell:date -s r --description "Print the date represented by 'seconds' since January 1, 1970"
+complete -c shell:date -s v --description "Adjust date"
+complete -c shell:date -s f --description "Use 'input_fmt' to parse 'new_date'"
+
+complete -c shell:wc -e
+complete -c shell:wc -d "Word, line, character, and byte count"
+complete -c shell:wc -s n -l lines --description "Print line count"
+complete -c shell:wc -s c -l bytes --description "Print byte count"
+complete -c shell:wc -s m -l chars --description "Print character count"
+complete -c shell:wc -s w -l words --description "Print word count"
+complete -c shell:wc -a '__files'

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/assemblies/features/base/src/main/resources/resources/etc/shell.init.script
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/etc/shell.init.script b/assemblies/features/base/src/main/resources/resources/etc/shell.init.script
index 5977a44..382c759 100644
--- a/assemblies/features/base/src/main/resources/resources/etc/shell.init.script
+++ b/assemblies/features/base/src/main/resources/resources/etc/shell.init.script
@@ -30,3 +30,22 @@ help = { *:help $args | more } ;
 man = { help $args } ;
 log:list = { log:get ALL } ;
 service:get = { $.context getService ($.context getServiceReference $args) };
+
+env = { shell:set $args }
+edit = { shell:nano $args }
+more = { shell:less $args }
+
+prompt = "${USER}@${APPLICATION}(${SUBSHELL})> "
+
+__load_class = {
+  (($.reader class) classLoader) loadClass $1
+}
+__rprompt_formatter = (((__load_class java.text.SimpleDateFormat) getConstructor (__load_class java.lang.String)) newInstance \'$'\u001B\[90m'\'HH:mm:ss)
+__date_class = (__load_class java.util.Date)
+\#rprompt = { $__rprompt_formatter format ($__date_class newInstance) }
+
+setopt group
+keymap "^[OA" up-line-or-search
+keymap "^[OB" down-line-or-search
+
+

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/assemblies/features/base/src/main/resources/resources/etc/system.properties
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/etc/system.properties b/assemblies/features/base/src/main/resources/resources/etc/system.properties
index 264dbea..6c4525c 100644
--- a/assemblies/features/base/src/main/resources/resources/etc/system.properties
+++ b/assemblies/features/base/src/main/resources/resources/etc/system.properties
@@ -47,7 +47,7 @@ karaf.default.repository = system
 # session.  This script can be used to create aliases and define
 # additional commands.
 #
-karaf.shell.init.script = ${karaf.etc}/shell.init.script
+karaf.shell.init.script = ${karaf.etc}/shell.init.script,${karaf.etc}/scripts/*.script
 
 #
 # Sets the maximum size of the shell command history. If not set,
@@ -88,12 +88,6 @@ karaf.local.roles = admin,manager,viewer,systembundles
 xml.catalog.files =
 
 #
-# Suppress the bell in the console when hitting backspace too many times
-# for example
-#
-jline.nobell = true
-
-#
 # ServiceMix specs options
 #
 org.apache.servicemix.specs.debug = false

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/itests/src/test/java/org/apache/karaf/itests/ShellCommandSecurityTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ShellCommandSecurityTest.java b/itests/src/test/java/org/apache/karaf/itests/ShellCommandSecurityTest.java
index a5e9ce1..0aed5d3 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ShellCommandSecurityTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ShellCommandSecurityTest.java
@@ -19,6 +19,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import static org.jline.keymap.KeyMap.ctrl;
+
 /**
  * This test exercises the Shell Command ACL for the shell scope commands as defined in
  * /framework/src/main/resources/resources/etc/org.apache.karaf.command.acl.shell.cfg
@@ -35,13 +37,13 @@ public class ShellCommandSecurityTest extends SshCommandTestBase {
         addViewer(vieweruser);
 
         assertCommand(vieweruser, "shell:date", Result.OK);
-        assertCommand(vieweruser, "shell:edit", Result.NOT_FOUND);
+        assertCommand(vieweruser, "shell:nano", Result.NOT_FOUND);
         assertCommand(vieweruser, "shell:exec", Result.NOT_FOUND);
         assertCommand(vieweruser, "shell:new", Result.NOT_FOUND);
         assertCommand(vieweruser, "shell:java", Result.NOT_FOUND);
 
         assertCommand("karaf", "shell:date", Result.OK);
-        assertCommand("karaf", "shell:edit", Result.OK);
+        assertCommand("karaf", "shell:nano\n" + ctrl('X'), Result.OK);
         assertCommand("karaf", "shell:exec", Result.OK);
         assertCommand("karaf", "shell:new", Result.OK);
         assertCommand("karaf", "shell:java", Result.OK);

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b03ae9d..a3e2758 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,8 +187,8 @@
         <felix.fileinstall.version>3.5.6</felix.fileinstall.version>
         <felix.framework.version>5.6.0</felix.framework.version>
         <felix.framework.security.version>2.4.0</felix.framework.security.version>
-        <felix.gogo.runtime.version>0.17.0-SNAPSHOT</felix.gogo.runtime.version>
-        <felix.gogo.jline.version>0.1.0-SNAPSHOT</felix.gogo.jline.version>
+        <felix.gogo.runtime.version>1.0.0</felix.gogo.runtime.version>
+        <felix.gogo.jline.version>1.0.0</felix.gogo.jline.version>
         <felix.inventory.version>1.0.4</felix.inventory.version>
         <felix.plugin.version>3.0.1</felix.plugin.version>
         <felix.utils.version>1.8.2</felix.utils.version>
@@ -252,7 +252,7 @@
         <hibernate.validator.version>5.3.0.Final</hibernate.validator.version>
         <jansi.version>1.14</jansi.version>
         <javassist.version>3.9.0.GA</javassist.version>
-        <jline.version>3.0.0.M2</jline.version>
+        <jline.version>3.0.0</jline.version>
         <jsw.version>3.2.3</jsw.version>
         <log4j.version>1.2.17</log4j.version>
         <maven.version>2.0.9</maven.version>

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/AliasAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/AliasAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/AliasAction.java
deleted file mode 100644
index 21db405..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/AliasAction.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-@Command(scope = "shell", name = "alias", description = "Create an alias to a command")
-@Service
-public class AliasAction implements Action {
-
-    @Argument(index = 0, name = "command", description = "The command to alias, e.g. 'ldn = { log:display -n $args }'", required = true, multiValued = false)
-    private String alias;
-
-    @Reference
-    private Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        session.execute(alias);
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/CatAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/CatAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/CatAction.java
deleted file mode 100644
index 0471c56..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/CatAction.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.File;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Completion;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.completers.FileOrUriCompleter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Concatenate and print files and/or URLs.
- */
-@Command(scope = "shell", name = "cat", description = "Displays the content of a file or URL.")
-@Service
-public class CatAction implements Action {
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    @Option(name = "-n", aliases = {}, description = "Number the output lines, starting at 1.", required = false, multiValued = false)
-    private boolean displayLineNumbers;
-
-    @Option(name = "-", description = "Use stdin")
-    private boolean stdin;
-
-    @Argument(index = 0, name = "paths or urls", description = "A list of file paths or urls to display separated by whitespace (use - for STDIN)", required = false, multiValued = true)
-    @Completion(FileOrUriCompleter.class)
-    private List<String> paths;
-
-    @Override
-    public Object execute() throws Exception {
-        if (stdin) {
-            paths = Collections.singletonList("-");
-        }
-
-        if (paths == null) {
-            throw new RuntimeException("Need to supply a path");
-        }
-
-        for (String filename : paths) {
-            BufferedReader reader = new BufferedReader(createReader(filename));
-            try {
-                cat(reader);
-            } finally {
-                closeReader(reader);
-            }
-        }
-
-        return null;
-    }
-
-    private void closeReader(BufferedReader reader) {
-        try {
-            reader.close();
-        } catch (IOException e) {
-            // Ignore
-        }
-    }
-
-    /**
-     * Create a reader for a url orfor a file
-     * 
-     * @param urlOrfileName
-     * @return
-     * @throws IOException
-     * @throws FileNotFoundException
-     */
-    private Reader createReader(String urlOrfileName) throws IOException, FileNotFoundException {
-        if ("-".equals(urlOrfileName)) {
-            log.debug("Printing STDIN");
-            return new InputStreamReader(System.in);
-        }
-        try {
-            URL url = new URL(urlOrfileName);
-            log.debug("Printing URL: " + url);
-            return new InputStreamReader(url.openStream());
-        } catch (MalformedURLException ignore) {
-            File file = new File(urlOrfileName);
-            log.debug("Printing file: " + file);
-            return new FileReader(file);
-        }
-    }
-
-    private void cat(final BufferedReader reader) throws IOException {
-        String line;
-        int lineno = 1;
-
-        while ((line = reader.readLine()) != null) {
-            if (displayLineNumbers) {
-                System.out.print(String.format("%6d  ", lineno++));
-            }
-            System.out.println(line);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ClearAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ClearAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ClearAction.java
deleted file mode 100644
index 805ec25..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/ClearAction.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-/**
- * A command to clear the console buffer
- */
-@Command(scope = "shell", name = "clear", description = "Clears the console buffer.")
-@Service
-public class ClearAction implements Action {
-
-    @Override
-    public Object execute() throws Exception {
-		System.out.print("\33[2J");
-		System.out.flush();
-		System.out.print("\33[1;1H");
-		System.out.flush();
-        return null;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/DateAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/DateAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/DateAction.java
deleted file mode 100644
index 880ae43..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/DateAction.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-@Command(scope = "shell", name = "date", description = "Display the current time in the given FORMAT")
-@Service
-public class DateAction implements Action {
-
-    @Option(name = "-d", aliases = { "--date" }, description = "Display time described, not now", multiValued = false, required = false)
-    private String date;
-
-    @Argument(index = 0, name = "format", description = "Output format", multiValued = false, required = false)
-    private String format;
-
-    @Override
-    public Object execute() throws Exception {
-        Date d;
-        if (date == null || date.equalsIgnoreCase("now")) {
-            d = new Date();
-        } else {
-            if (date.startsWith("@")) {
-                d = new Date(Long.parseLong(date.substring(1)));
-            } else {
-                d = new Date(date);
-            }
-        }
-        if (format == null) {
-            format = "%+";
-        }
-        // transform Unix format to Java SimpleDateFormat (if required)
-        StringBuilder sb = new StringBuilder();
-        boolean quote = false;
-        for (int i = 0; i < format.length(); i++) {
-            char c = format.charAt(i);
-            if (c == '%') {
-                if (i + 1 < format.length()) {
-                    if (quote) {
-                        sb.append('\'');
-                        quote = false;
-                    }
-                    c = format.charAt(++i);
-                    switch (c) {
-                        case '+':
-                        case 'A': sb.append("MMM EEE d HH:mm:ss yyyy"); break;
-                        case 'a': sb.append("EEE"); break;
-                        case 'B': sb.append("MMMMMMM"); break;
-                        case 'b': sb.append("MMM"); break;
-                        case 'C': sb.append("yy"); break;
-                        case 'c': sb.append("MMM EEE d HH:mm:ss yyyy"); break;
-                        case 'D': sb.append("MM/dd/yy"); break;
-                        case 'd': sb.append("dd"); break;
-                        case 'e': sb.append("dd"); break;
-                        case 'F': sb.append("yyyy-MM-dd"); break;
-                        case 'G': sb.append("YYYY"); break;
-                        case 'g': sb.append("YY"); break;
-                        case 'H': sb.append("HH"); break;
-                        case 'h': sb.append("MMM"); break;
-                        case 'I': sb.append("hh"); break;
-                        case 'j': sb.append("DDD"); break;
-                        case 'k': sb.append("HH"); break;
-                        case 'l': sb.append("hh"); break;
-                        case 'M': sb.append("mm"); break;
-                        case 'm': sb.append("MM"); break;
-                        case 'N': sb.append("S"); break;
-                        case 'n': sb.append("\n"); break;
-                        case 'P': sb.append("aa"); break;
-                        case 'p': sb.append("aa"); break;
-                        case 'r': sb.append("hh:mm:ss aa"); break;
-                        case 'R': sb.append("HH:mm"); break;
-                        case 'S': sb.append("ss"); break;
-                        case 's': sb.append("S"); break;
-                        case 'T': sb.append("HH:mm:ss"); break;
-                        case 't': sb.append("\t"); break;
-                        case 'U': sb.append("w"); break;
-                        case 'u': sb.append("u"); break;
-                        case 'V': sb.append("W"); break;
-                        case 'v': sb.append("dd-MMM-yyyy"); break;
-                        case 'W': sb.append("w"); break;
-                        case 'w': sb.append("u"); break;
-                        case 'X': sb.append("HH:mm:ss"); break;
-                        case 'x': sb.append("MM/dd/yy"); break;
-                        case 'Y': sb.append("yyyy"); break;
-                        case 'y': sb.append("yy"); break;
-                        case 'Z': sb.append("z"); break;
-                        case 'z': sb.append("X"); break;
-                        case '%': sb.append("%"); break;
-                    }
-                } else {
-                    if (!quote) {
-                        sb.append('\'');
-                    }
-                    sb.append(c);
-                    sb.append('\'');
-                }
-            } else {
-                if ((c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') && !quote) {
-                    sb.append('\'');
-                    quote = true;
-                }
-                sb.append(c);
-            }
-        }
-        DateFormat df = new SimpleDateFormat(sb.toString());
-        System.out.println(df.format(d));
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EachAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EachAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EachAction.java
deleted file mode 100644
index 0de344e..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EachAction.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Function;
-import org.apache.karaf.shell.api.console.Session;
-
-/**
- * Execute a closure on a list of arguments.
- */
-@Command(scope = "shell", name = "each", description = "Execute a closure on a list of arguments.")
-@Service
-public class EachAction implements Action {
-
-    @Argument(name = "values", index = 0, multiValued = false, required = true, description = "The collection of arguments to iterate on")
-    Collection<Object> values;
-
-    @Argument(name = "function", index = 1, multiValued = false, required = true, description = "The function to execute")
-    Function function;
-
-    @Reference
-    Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        for (Object v : values) {
-            function.execute(session, Collections.singletonList(v));
-        }
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EchoAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EchoAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EchoAction.java
deleted file mode 100644
index 433e2a9..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EchoAction.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-
-@Command(scope = "shell", name = "echo", description="Echoes or prints arguments to STDOUT.")
-@Service
-public class EchoAction implements Action
-{
-    @Option(name = "-n", aliases = {}, description = "Do not print the trailing newline character", required = false, multiValued = false)
-    private boolean noTrailingNewline = false;
-
-    @Argument(index = 0, name = "arguments", description="Arguments to display separated by whitespaces", required = false, multiValued = true)
-    private List<String> args;
-
-    @Override
-    public Object execute() throws Exception {
-        if (args != null) {
-            boolean first = true;
-            for (String arg : args) {
-                if (first) {
-                    first = false;
-                } else {
-                    System.out.print(" ");
-                }
-                System.out.print(arg);
-            }
-        }
-
-        if (!noTrailingNewline) {
-            System.out.println();
-        }
-
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EditAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EditAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EditAction.java
deleted file mode 100644
index 84feb70..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EditAction.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.api.console.Terminal;
-
-@Command(scope = "shell", name = "edit", description = "Calls a text editor.")
-@Service
-public class EditAction implements Action {
-
-    private final Pattern URL_PATTERN = Pattern.compile("[^: ]+:[^ ]+");
-
-    @Argument(index = 0, name = "url", description = "The url of the resource to edit.", required = true, multiValued = true)
-    private List<String> urls;
-
-    @Reference
-    Session session;
-
-    @Reference
-    Terminal terminal;
-
-    @Override
-    public Object execute() throws Exception {
-        org.jline.terminal.Terminal terminal = (org.jline.terminal.Terminal) session.get(".jline.terminal");
-        Path pwd = Paths.get(System.getProperty("karaf.home"));
-        org.jline.builtins.Commands.nano(terminal, System.out, System.err, pwd,
-                urls.toArray(new String[urls.size()]));
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java
deleted file mode 100644
index 2bd0755..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Session;
-
-/**
- * Command to get/set the value of a session variable.
- */
-@Command(scope = "shell", name = "env", description = "Get/set the value of a console session variable.")
-@Service
-public class EnvAction implements Action {
-
-    @Argument(index = 0, name = "variable", description = "The name of the console session variable.", required = true, multiValued = false)
-    String variable;
-
-    @Argument(index = 1, name = "value", description = "The new value of the console session variable.", required = false, multiValued = false)
-    String value;
-
-    @Reference
-    Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        if (value == null) {
-            System.out.println(session.get(variable));
-        } else {
-            session.put(variable, value);
-        }
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
deleted file mode 100644
index 6dcb054..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/GrepAction.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.felix.gogo.api.Process;
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Completion;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.support.completers.FileOrUriCompleter;
-import org.jline.builtins.Source;
-import org.jline.builtins.Source.StdInSource;
-import org.jline.builtins.Source.URLSource;
-import org.jline.terminal.Terminal;
-import org.jline.utils.AttributedString;
-import org.jline.utils.AttributedStringBuilder;
-import org.jline.utils.AttributedStyle;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-@Command(scope = "shell", name="grep", description="Prints lines matching the given pattern.", detailedDescription="classpath:grep.txt")
-@Service
-public class GrepAction implements Action {
-
-    public static enum ColorOption {
-        never,
-        always,
-        auto
-    }
-
-    @Argument(index = 0, name = "pattern", description = "Regular expression", required = true, multiValued = false)
-    private String regex;
-
-    @Argument(index = 1, multiValued = true)
-    @Completion(FileOrUriCompleter.class)
-    List<String> files;
-
-    @Option(name = "-n", aliases = { "--line-number" }, description = "Prefixes each line of output with the line number within its input file.", required = false, multiValued = false)
-    private boolean lineNumber;
-
-    @Option(name = "-v", aliases = { "--invert-match" }, description = "Inverts the sense of matching, to select non-matching lines.", required = false, multiValued = false)
-    private boolean invertMatch;
-
-    @Option(name = "-w", aliases = { "--word-regexp" }, description = "Selects only those lines containing matches that form whole " +
-                                                                      "words.  The test is that the matching substring must either be " +
-                                                                      "at  the beginning of the line, or preceded by a non-word constituent " +
-                                                                      "character.  Similarly, it must be either at the end of " +
-                                                                      "the line or followed by a non-word constituent character.  " +
-                                                                      "Word-constituent characters are letters, digits, and the underscore.", required = false, multiValued = false)
-    private boolean wordRegexp;
-
-    @Option(name = "-x", aliases = { "--line-regexp" }, description = "Selects only those matches that exactly match the whole line.", required = false, multiValued = false)
-    private boolean lineRegexp;
-
-    @Option(name = "-i", aliases = { "--ignore-case" }, description = "Ignores case distinctions in both the PATTERN and the input files.", required = false, multiValued = false)
-    private boolean ignoreCase;
-
-    @Option(name = "-c", aliases = { "--count" }, description = "only print a count of matching lines per FILE", required = false, multiValued = false)
-    private boolean count;
-
-    @Option(name = "--color", aliases = { "--colour" }, description = "use markers to distinguish the matching string. WHEN may be `always', `never' or `auto'", required = false, multiValued = false)
-    private ColorOption color = ColorOption.auto;
-
-    @Option(name = "-B", aliases = { "--before-context" }, description = "Print NUM lines of leading context before matching lines.  Places a line containing -- between contiguous groups of matches.", required = false, multiValued = false)
-    private int before = -1;
-
-    @Option(name = "-A", aliases = { "--after-context" }, description = "Print NUM lines of trailing context after matching lines.  Places a line containing -- between contiguous groups of matches.", required = false, multiValued = false)
-    private int after = -1;
-
-    @Option(name = "-C", aliases = { "--context" }, description = "Print NUM lines of output context.  Places a line containing -- between contiguous groups of matches.", required = false, multiValued = false)
-    private int context = 0;
-
-    @Option(name = "-o", aliases = { "--only-matching"}, description = "Print only the matching section of a line", required = false, multiValued = false)
-    private boolean onlyMatching;
-
-    @Reference
-    Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        if (color == ColorOption.auto && (Process.current() == null || !Process.current().isTty(1))) {
-            color = ColorOption.never;
-        }
-        if (after < 0) {
-            after = context;
-        }
-        if (before < 0) {
-            before = context;
-        }
-
-        String regexp = regex;
-        if (wordRegexp) {
-            regex = regexp = "\\b" + regexp + "\\b";
-        }
-        if (lineRegexp) {
-            regexp = "^" + regexp + "$";
-        } else {
-            regexp = ".*" + regexp + ".*";
-        }
-        Pattern p;
-        Pattern p2;
-        if (ignoreCase) {
-            p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
-            p2 = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
-        } else {
-            p = Pattern.compile(regexp);
-            p2 = Pattern.compile(regex);
-        }
-
-        List<Source> sources = new ArrayList<>();
-        if (files == null || files.isEmpty()) {
-            files = Collections.singletonList("-");
-        }
-        Path pwd = Paths.get(System.getProperty("karaf.home", System.getProperty("user.dir")));
-        for (String arg : files) {
-            if ("-".equals(arg)) {
-                sources.add(new StdInSource());
-            } else {
-                sources.add(new URLSource(pwd.toUri().resolve(arg).toURL(), arg));
-            }
-        }
-
-        Terminal terminal = session != null ? (Terminal) session.get(".jline.terminal") : null;
-        List<Object> output = new ArrayList<>();
-        for (Source source : sources) {
-            boolean firstPrint = true;
-            int nb = 0;
-            int lineno = 1;
-            String line;
-            int lineMatch = 0;
-            List<String> lines = new ArrayList<>();
-            try (BufferedReader r = new BufferedReader(new InputStreamReader(source.read()))) {
-                while ((line = r.readLine()) != null) {
-                    if (line.length() == 1 && line.charAt(0) == '\n') {
-                        break;
-                    }
-                    if (p.matcher(line).matches() ^ invertMatch) {
-                        AttributedStringBuilder sbl = new AttributedStringBuilder();
-                        if (color != ColorOption.never) {
-                            sbl.style(getSourceStyle());
-                        }
-                        if (!count && sources.size() > 1) {
-                            sbl.append(source.getName());
-                            sbl.append(":");
-                        }
-                        if (!count && lineNumber) {
-                            sbl.append(String.format("%6d  ", lineno));
-                        }
-                        sbl.style(AttributedStyle.DEFAULT);
-                        AttributedString aLine = AttributedString.fromAnsi(line);
-                        AttributedStyle style;
-                        Matcher matcher2 = p2.matcher(aLine.toString());
-                        if (!invertMatch && color != ColorOption.never) {
-                            style = getMatchingStyle();
-                        } else {
-                            style = AttributedStyle.DEFAULT;
-                        }
-                        if (invertMatch) {
-                            nb++;
-                            sbl.append(aLine);
-                        } else if (onlyMatching) {
-                            while (matcher2.find()) {
-                                int index = matcher2.start(0);
-                                int cur = matcher2.end();
-                                sbl.append(aLine.subSequence(index, cur), style);
-                                nb++;
-                            }
-                        } else {
-                            int cur = 0;
-                            while (matcher2.find()) {
-                                int index = matcher2.start(0);
-                                AttributedString prefix = aLine.subSequence(cur, index);
-                                sbl.append(prefix);
-                                cur = matcher2.end();
-                                sbl.append(aLine.subSequence(index, cur), style);
-                                nb++;
-                            }
-                            sbl.append(aLine.subSequence(cur, aLine.length()));
-                        }
-                        lines.add(sbl.toAnsi(terminal));
-                        lineMatch = lines.size();
-                    } else {
-                        if (lineMatch != 0 & lineMatch + after + before <= lines.size()) {
-                            if (!count) {
-                                if (!firstPrint && before + after > 0) {
-                                    output.add("--");
-                                } else {
-                                    firstPrint = false;
-                                }
-                                for (int i = 0; i < lineMatch + after; i++) {
-                                    output.add(lines.get(i));
-                                }
-                            }
-                            while (lines.size() > before) {
-                                lines.remove(0);
-                            }
-                            lineMatch = 0;
-                        }
-                        lines.add(line);
-                        while (lineMatch == 0 && lines.size() > before) {
-                            lines.remove(0);
-                        }
-                    }
-                    lineno++;
-                }
-                if (!count && lineMatch > 0) {
-                    if (!firstPrint && before + after > 0) {
-                        output.add("--");
-                    } else {
-                        firstPrint = false;
-                    }
-                    for (int i = 0; i < lineMatch + after && i < lines.size(); i++) {
-                        output.add(lines.get(i));
-                    }
-                }
-                if (count) {
-                    output.add(nb);
-                }
-            }
-        }
-        return output;
-    }
-
-    private AttributedStyle getSourceStyle() {
-        return AttributedStyle.DEFAULT.foreground(AttributedStyle.BLACK + AttributedStyle.BRIGHT);
-    }
-
-    private AttributedStyle getMatchingStyle() {
-        return AttributedStyle.DEFAULT.bold().foreground(AttributedStyle.RED);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HeadAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HeadAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HeadAction.java
deleted file mode 100644
index ad144d4..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HeadAction.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Command(scope = "shell", name = "head", description = "Displays the first lines of a file.")
-@Service
-public class HeadAction implements Action {
-
-    private static final int DEFAULT_NUMBER_OF_LINES = 10;
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    @Option(name = "-n", aliases = {}, description = "The number of lines to display, starting at 1.", required = false, multiValued = false)
-    private int numberOfLines;
-
-    @Argument(index = 0, name = "paths or urls", description = "A list of file paths or urls to display separated by whitespaces.", required = false, multiValued = true)
-    private List<String> paths;
-
-    @Override
-    public Object execute() throws Exception {
-        //If no paths provided assume standar input
-        if (paths == null || paths.size() == 0) {
-            if (log.isDebugEnabled()) {
-                log.debug("Heading STDIN");
-            }
-
-            head(new BufferedReader(new InputStreamReader(System.in)));
-        } else {
-            for (String filename : paths) {
-                BufferedReader reader;
-
-                // First try a URL
-                try {
-                    URL url = new URL(filename);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Heading URL: " + url);
-                    }
-                    reader = new BufferedReader(new InputStreamReader(url.openStream()));
-                }
-                catch (MalformedURLException ignore) {
-                    // They try a file
-                    File file = new File(filename);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Heading file: " + file);
-                    }
-                    reader = new BufferedReader(new FileReader(file));
-                }
-
-                try {
-                    head(reader);
-                }
-                finally {
-                    try {
-                        reader.close();
-                    } catch (IOException e) {
-                        // Ignore
-                    }
-                }
-            }
-        }
-        return null;
-    }
-
-    private void head(final BufferedReader reader) throws IOException {
-        String line;
-        int lineno = 1;
-
-        if (numberOfLines < 1) {
-            numberOfLines = DEFAULT_NUMBER_OF_LINES;
-        }
-
-        while ((line = reader.readLine()) != null && lineno <= numberOfLines) {
-            System.out.println(line);
-            lineno++;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HistoryAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HistoryAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HistoryAction.java
deleted file mode 100644
index f4b0157..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/HistoryAction.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.History;
-import org.apache.karaf.shell.support.ansi.SimpleAnsi;
-
-/**
- * History command
- */
-@Command(scope = "shell", name="history", description="Prints command history.")
-@Service
-public class HistoryAction implements Action {
-
-    @Option(name = "-c", aliases = { "--clear" }, description = "Clears the shell command history.", required = false, multiValued = false)
-    private boolean clear;
-
-    @Reference
-    History history;
-
-    @Override
-    public Object execute() throws Exception {
-        if (history != null) {
-            if (clear) {
-                history.clear();
-            } else {
-                for (int index = history.first(); index <= history.last(); index++) {
-                    System.out.println(
-                            "  " + SimpleAnsi.INTENSITY_BOLD + String.format("%3d", index) + SimpleAnsi.INTENSITY_NORMAL
-                                    + "  " + history.get(index));
-                }
-            }
-        }
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/IfAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/IfAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/IfAction.java
deleted file mode 100644
index 3c1362f..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/IfAction.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Function;
-import org.apache.karaf.shell.api.console.Session;
-
-/**
- * Execute a closure on a list of arguments.
- */
-@Command(scope = "shell", name = "if", description = "If/Then/Else block.")
-@Service
-public class IfAction implements Action {
-
-    @Argument(name = "condition", index = 0, multiValued = false, required = true, description = "The condition")
-    Function condition;
-
-    @Argument(name = "ifTrue", index = 1, multiValued = false, required = true, description = "The function to execute if the condition is true")
-    Function ifTrue;
-
-    @Argument(name = "ifFalse", index = 2, multiValued = false, required = false, description = "The function to execute if the condition is false")
-    Function ifFalse;
-
-    @Reference
-    Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        Object result = condition.execute(session, null);
-        if (isTrue(result)) {
-            return ifTrue.execute(session, null);
-        } else {
-            if (ifFalse != null) {
-                return ifFalse.execute(session, null);
-            }
-        }
-        return null;
-    }
-
-    private boolean isTrue(Object result) {
-        if (result == null) {
-            return false;
-        }
-        if (result instanceof String && ((String) result).equals("")) {
-            return false;
-        }
-        if (result instanceof Number) {
-            return ((Number) result).doubleValue() != 0.0d;
-        }
-        if (result instanceof Boolean) {
-            return (Boolean) result;
-        }
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/LessAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/LessAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/LessAction.java
deleted file mode 100644
index 0479ba8..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/LessAction.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Session;
-import org.jline.builtins.Less;
-import org.jline.builtins.Source;
-import org.jline.builtins.Source.StdInSource;
-import org.jline.builtins.Source.URLSource;
-import org.jline.terminal.Terminal;
-
-@Command(scope = "shell", name = "less", description = "File pager.")
-@Service
-public class LessAction implements Action {
-
-    @Option(name = "-e", aliases = "--quit-at-eof")
-    boolean quitAtSecondEof;
-
-    @Option(name = "-E", aliases = "--QUIT-AT-EOF")
-    boolean quitAtFirstEof;
-
-    @Option(name = "-N", aliases = "--LINE-NUMBERS")
-    boolean printLineNumbers;
-
-    @Option(name = "-q", aliases = {"--quiet", "--silent"})
-    boolean quiet;
-
-    @Option(name = "-Q", aliases = {"--QUIET", "--SILENT"})
-    boolean veryQuiet;
-
-    @Option(name = "-S", aliases = "--chop-long-lines")
-    boolean chopLongLines;
-
-    @Option(name = "-i", aliases = "--ignore-case")
-    boolean ignoreCaseCond;
-
-    @Option(name = "-I", aliases = "--IGNORE-CASE")
-    boolean ignoreCaseAlways;
-
-    @Option(name = "-x", aliases = "--tabs")
-    int tabs = 4;
-
-    @Argument(multiValued = true)
-    List<String> files;
-
-    @Reference
-    Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        Terminal terminal = (Terminal) session.get(".jline.terminal");
-        Less less = new Less(terminal);
-        less.quitAtFirstEof = quitAtFirstEof;
-        less.quitAtSecondEof = quitAtSecondEof;
-        less.quiet = quiet;
-        less.veryQuiet = veryQuiet;
-        less.chopLongLines = chopLongLines;
-        less.ignoreCaseAlways = ignoreCaseAlways;
-        less.ignoreCaseCond = ignoreCaseCond;
-        less.tabs = tabs;
-        less.printLineNumbers = printLineNumbers;
-        List<Source> sources = new ArrayList<>();
-        if (files == null || files.isEmpty()) {
-            files = Collections.singletonList("-");
-        }
-        Path pwd = Paths.get(System.getProperty("karaf.home", System.getProperty("user.dir")));
-        for (String arg : files) {
-            if ("-".equals(arg)) {
-                sources.add(new StdInSource());
-            } else {
-                sources.add(new URLSource(pwd.toUri().resolve(arg).toURL(), arg));
-            }
-        }
-        less.run(sources);
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f1dd4a94/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/MoreAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/MoreAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/MoreAction.java
deleted file mode 100644
index ef92105..0000000
--- a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/MoreAction.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.shell.commands.impl;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.lang.reflect.Method;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.api.console.Terminal;
-import org.apache.karaf.shell.support.ansi.AnsiSplitter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Command(scope = "shell", name = "more", description = "File pager.")
-@Service
-public class MoreAction implements Action {
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    @Option(name = "--lines", description = "stop after N lines")
-    int lines;
-
-    @Reference(optional = true)
-    Terminal terminal;
-
-    @Reference
-    Session session;
-
-    @Override
-    public Object execute() throws Exception {
-        if (terminal == null || !isTty(System.out)) {
-            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
-            String line;
-            while ((line = reader.readLine()) != null) {
-                System.out.println(line);
-                checkInterrupted();
-            }
-            return null;
-        } else {
-            boolean echo = terminal.isEchoEnabled();
-            terminal.setEchoEnabled(false);
-            try {
-                if (lines == 0) {
-                    lines = terminal.getHeight();
-                }
-                AnsiSplitter.AnsiBufferedReader reader = AnsiSplitter.splitter(System.in, terminal.getWidth(), 4);
-                int count = 0;
-                int c;
-                do {
-                    do {
-                        String line;
-                        if ((line = reader.readLine()) == null) {
-                            return null;
-                        }
-                        System.out.println(line);
-                        checkInterrupted();
-                    } while (++count < lines - 2);
-                    c = -1;
-                    while (c == -1) {
-                        System.out.flush();
-                        System.out.print("--More--");
-                        System.out.flush();
-                        c = session.getKeyboard().read();
-                        switch (c) {
-                            case 'q':
-                            case -1:
-                                c = 'q';
-                                break;
-                            case '\r':
-                            case '\n':
-                            case 14: // Down arrow
-                                count--;
-                                System.out.print("\r          \r");
-                                break;
-                            case ' ':
-                                count = 0;
-                                System.out.print("\r          \r");
-                                break;
-                            case 16: // Up arrow
-                                // fall through
-                            default:
-                                c = -1;
-                                System.out.print("\r          \r");
-                                break;
-                        }
-                        if (c == 'q') {
-                            break;
-                        }
-                    }
-                } while (c != 'q');
-            } catch (InterruptedException ie) {
-            	log.debug("Interrupted by user");
-            } finally {
-                terminal.setEchoEnabled(echo);
-            }
-        }
-        return null;
-    }
-
-    protected boolean isTty(OutputStream out) {
-        try {
-            Method mth = out.getClass().getDeclaredMethod("getCurrent");
-            mth.setAccessible(true);
-            Object current = mth.invoke(out);
-            return current == session.getConsole();
-        } catch (Throwable t) {
-            return false;
-        }
-    }
-
-    /**
-     * This is for long running commands to be interrupted by ctrl-c.
-     *
-     * @throws InterruptedException If the command is interrupted.
-     */
-    public static void checkInterrupted() throws InterruptedException {
-        Thread.yield();
-        if (Thread.currentThread().isInterrupted()) {
-            throw new InterruptedException();
-        }
-    }
-
-}


Mime
View raw message