Skip to content

Commit

Permalink
history method: add currentDir parameter and pattern match uses
Browse files Browse the repository at this point in the history
option Pattern.DOTALL
  • Loading branch information
mattirn committed Jul 9, 2019
1 parent a1f2c93 commit 49e646d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static void less(Terminal terminal, InputStream in, PrintStream out, Prin
less.run(sources);
}

public static void history(LineReader reader, PrintStream out, PrintStream err,
public static void history(LineReader reader, PrintStream out, PrintStream err, Path currentDir,
String[] argv) throws Exception {
final String[] usage = {
"history - list history of commands",
Expand Down Expand Up @@ -205,13 +205,13 @@ public static void history(LineReader reader, PrintStream out, PrintStream err,
} else if (opt.isSet("save")) {
history.save();
} else if (opt.isSet("A")) {
Path file = opt.args().size() > 0 ? Paths.get(opt.args().get(0)) : null;
Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null;
history.append(file, increment);
} else if (opt.isSet("R")) {
Path file = opt.args().size() > 0 ? Paths.get(opt.args().get(0)) : null;
Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null;
history.read(file, increment);
} else if (opt.isSet("W")) {
Path file = opt.args().size() > 0 ? Paths.get(opt.args().get(0)) : null;
Path file = opt.args().size() > 0 ? currentDir.resolve(opt.args().get(0)) : null;
history.write(file, increment);
} else {
done = false;
Expand All @@ -231,7 +231,7 @@ public static void history(LineReader reader, PrintStream out, PrintStream err,
sb.append(c);
prev = c;
}
pattern = Pattern.compile(sb.toString());
pattern = Pattern.compile(sb.toString(), Pattern.DOTALL);
}
int firstId = opt.args().size() > argId ? retrieveHistoryId(history, opt.args().get(argId++)) : -17;
int lastId = opt.args().size() > argId ? retrieveHistoryId(history, opt.args().get(argId++)) : -1;
Expand Down
3 changes: 2 additions & 1 deletion builtins/src/test/java/org/jline/builtins/CommandsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -57,7 +58,7 @@ public void testHistoryForFileWithMoreHistoryRecordsThanAtHistoryFileSize() {
lineReader.setVariable(LineReader.HISTORY_FILE_SIZE, maxLines);
lineReader.getHistory().save();
PrintStream out = new PrintStream(os, false);
Commands.history(lineReader, out, out, new String[] {"-d"});
Commands.history(lineReader, out, out, Paths.get(""), new String[] {"-d"});
assertEquals(maxLines + 1,
os.toString("UTF8").split("\\s+\\d{2}:\\d{2}:\\d{2}\\s+").length);
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion builtins/src/test/java/org/jline/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ else if ("less".equals(pl.word())) {
argv);
}
else if ("history".equals(pl.word())) {
Commands.history(reader, System.out, System.err, argv);
Commands.history(reader, System.out, System.err, Paths.get(""),argv);
}
else if ("complete".equals(pl.word())) {
Commands.complete(reader, System.out, System.err,
Expand Down

0 comments on commit 49e646d

Please sign in to comment.