Æsh provide two different ways of doing completions depending on which API you’re using. First we will cover the completion API provided when using AeshConsole and then the more low level API when using Console.


When using AeshConsole the completion is specified for each Option thats defined in a Command. Here is an example of a simple command:
@CommandDefinition(name="color", description = "set a color")
public static class ColorCommand implements Command {
    private Color color;

    public CommandResult execute(AeshConsole console) throws IOException {
        if(color != null)
          console.getShell().out().println("We got color: "+color);
        return CommandResult.SUCCESS;

    public static class ColorCompleter implements OptionCompleter {
      public void complete(CompleterInvocation completerInvocation) {
        if("red".startsWith( completerInvocation.getGivenCompleterValue())

This command is supposed to let the user autocomplete the specified color. Note that the completer example is very simplified and not complete.


For Console Æsh provide a simple API to connect commands to its tab-completion list. The only thing thats needed is to implement the Completion interface and attach it to Console with the method

addCompletions(List<Completion> completionList)

A simple Example:
import org.jboss.aesh.complete.*;
import org.jboss.aesh.console.*;

public class Example {
  public static void main(String[] args) throws {
    Console console = new Console(new SettingsBuilder().create());

    Completion completer = new Completion() {
      public void complete(CompleteOperation co) {
        // very simple completor
        // if <tab> is pressed when the buffer is 'fo' or 'foo' it will
        // be completed to 'foobar'
        if(co.getBuffer().equals("fo") || co.getBuffer().equals("foo"))

    final ConsoleCallback consoleCallback = new ConsoleCallback() {
      public int readConsoleOutput(ConsoleOperation operation) throws IOException {
        console.out().println("======>\"" + operation.getBuffer());
        if (operation.getBuffer().equalsIgnoreCase("quit") ||
            operation.getBuffer().equalsIgnoreCase("exit") ||
            operation.getBuffer().equalsIgnoreCase("reset")) {


The object that is sent with every registered Completion object is CompletionOperation : * buffer: is the current line when the user pressed tab * cursor: the position of the cursor * completionCandidates: added by the programmer if the buffer match this completion. * offset: set by the programmer if Æsh should chop off some of the completionCandidate when doing completion. Set it to the same value as cursor to keep the buffer unchanged.

back to top