Class Completers.FilesCompleter

java.lang.Object
org.jline.builtins.Completers.FileNameCompleter
org.jline.builtins.Completers.FilesCompleter
All Implemented Interfaces:
Completer
Enclosing class:
Completers

public static class Completers.FilesCompleter extends Completers.FileNameCompleter
A completer for file names.

This completer provides completion for file paths, with optional filtering by name pattern. It extends FileNameCompleter and overrides the accept method to filter files by pattern.

  • Field Details

    • currentDir

      private final Supplier<Path> currentDir
      The supplier for the current directory path
    • namePattern

      private final String namePattern
      The compiled pattern for filtering file names
  • Constructor Details

    • FilesCompleter

      public FilesCompleter(File currentDir)
      Creates a new FilesCompleter with the specified current directory.
      Parameters:
      currentDir - the current directory as a File
    • FilesCompleter

      public FilesCompleter(File currentDir, String namePattern)
      Creates a new FilesCompleter with the specified current directory and name pattern.
      Parameters:
      currentDir - the current directory as a File
      namePattern - the pattern to filter file names
    • FilesCompleter

      public FilesCompleter(Path currentDir)
      Creates a new FilesCompleter with the specified current directory.
      Parameters:
      currentDir - the current directory as a Path
    • FilesCompleter

      public FilesCompleter(Path currentDir, String namePattern)
      Creates a new FilesCompleter with the specified current directory and name pattern.
      Parameters:
      currentDir - the current directory as a Path
      namePattern - the pattern to filter file names
    • FilesCompleter

      public FilesCompleter(Supplier<Path> currentDir)
      Creates a new FilesCompleter with a supplier for the current directory.
      Parameters:
      currentDir - a supplier that provides the current directory path
    • FilesCompleter

      public FilesCompleter(Supplier<Path> currentDir, String namePattern)
      Creates a new FilesCompleter with a supplier for the current directory and name pattern.
      Parameters:
      currentDir - a supplier that provides the current directory path
      namePattern - the pattern to filter file names
  • Method Details

    • compilePattern

      private String compilePattern(String pattern)
      Compiles a file name pattern into a regular expression.

      Converts glob-like patterns to regular expressions by escaping dots, converting asterisks to .*, and handling backslash escapes.

      Parameters:
      pattern - the pattern to compile
      Returns:
      the compiled pattern as a regular expression, or null if the input pattern is null
    • getUserDir

      protected Path getUserDir()
      Gets the user's current directory.
      Overrides:
      getUserDir in class Completers.FileNameCompleter
      Returns:
      the current directory path
    • accept

      protected boolean accept(Path path)
      Determines if a path should be accepted for completion.

      Accepts directories unconditionally, and files that match the name pattern if one is specified.

      Overrides:
      accept in class Completers.FileNameCompleter
      Parameters:
      path - the path to check
      Returns:
      true if the path should be accepted, false otherwise