Skip to content

Commit

Permalink
history command: pattern argument improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed May 12, 2019
1 parent 6d2855e commit ea8b360
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,17 @@ public static void history(LineReader reader, PrintStream out, PrintStream err,
}
int argId = 0;
Pattern pattern = null;
if (opt.isSet("m")) {
if (opt.args().size() == 0) {
throw new IllegalArgumentException();
if (opt.isSet("m") && opt.args().size() > 0) {
StringBuilder sb = new StringBuilder();
char prev = '0';
for (char c: opt.args().get(argId++).toCharArray()) {
if (c == '*' && prev != '\\' && prev != '.') {
sb.append('.');
}
sb.append(c);
prev = c;
}
String sp = opt.args().get(argId++);
pattern = Pattern.compile(sp.toString());
pattern = Pattern.compile(sb.toString());
}
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

0 comments on commit ea8b360

Please sign in to comment.