Skip to content

Commit

Permalink
Merge branch 'wildcard-files' of https://github.com/mattirn/jline3 in…
Browse files Browse the repository at this point in the history
…to mattirn-wildcard-files
  • Loading branch information
mattirn committed Jul 23, 2019
2 parents 032ef69 + cff84a9 commit cd355cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand Down Expand Up @@ -157,13 +161,27 @@ public static void less(Terminal terminal, InputStream in, PrintStream out, Prin
for (String arg : opt.args()) {
if ("-".equals(arg)) {
sources.add(new StdInSource(in));
} else if (arg.contains("*") || arg.contains("?")) {
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:"+arg);
Files.find(currentDir, Integer.MAX_VALUE, (path, f) -> pathMatcher.matches(path))
.forEach(p -> sources.add(doUrlSource(currentDir, p)));
} else {
sources.add(new URLSource(currentDir.resolve(arg).toUri().toURL(), arg));
}
}
less.run(sources);
}

private static Source doUrlSource(Path currentDir, Path file) {
Source out = null;
try {
out = new URLSource(currentDir.resolve(file).toUri().toURL(), file.toString());
} catch (MalformedURLException exp) {
throw new IllegalArgumentException(exp.getMessage());
}
return out;
}

public static void history(LineReader reader, PrintStream out, PrintStream err, Path currentDir,
String[] argv) throws Exception {
final String[] usage = {
Expand Down
10 changes: 9 additions & 1 deletion builtins/src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
Expand Down Expand Up @@ -965,7 +967,13 @@ public void open(String... files) throws IOException {

public void open(List<String> files) throws IOException {
for (String file : files) {
buffers.add(new Buffer(file));
if (file.contains("*") || file.contains("?")) {
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:"+file);
Files.find(root, Integer.MAX_VALUE, (path, f) -> pathMatcher.matches(path))
.forEach(p -> buffers.add(new Buffer(p.toString())));
} else {
buffers.add(new Buffer(file));
}
}
}

Expand Down

0 comments on commit cd355cf

Please sign in to comment.