diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-07-27 14:09:10 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-07-27 14:09:10 +0200 |
commit | edb2abe085f47b35c9379ee6deccf9223cb95d21 (patch) | |
tree | b768ee0bf86a52b8aba395713dd9457639f80d3f | |
parent | a6f21a1f4e70a1db354c9927c4b3938759faf033 (diff) | |
download | lr-edb2abe085f47b35c9379ee6deccf9223cb95d21.tar.gz lr-edb2abe085f47b35c9379ee6deccf9223cb95d21.tar.xz lr-edb2abe085f47b35c9379ee6deccf9223cb95d21.zip |
lr: add action "color <num>" to override colors
-rw-r--r-- | NEWS.md | 1 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | lr.1 | 1 | ||||
-rw-r--r-- | lr.c | 16 |
4 files changed, 25 insertions, 0 deletions
diff --git a/NEWS.md b/NEWS.md index b07959f..40c5c1b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ * Feature: lr now respects the locale, which mainly influences date format. * Feature: new option `-C` to change the color of files. +* Feature: new action `color <num>` to change the color of files. * Feature: new argument `@file` to read file names from a file. * Bug: lr now reports errors and sets exit code when toplevel arguments can not be stat'ed. diff --git a/README.md b/README.md index d423dcd..b9d3d1a 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ Default: `n`. | <modetest> | prune -- do not traverse into subdirectories | print -- always true value + | color <num> -- always true value, override 256-color <timeprop> ::= atime | ctime | mtime @@ -292,6 +293,12 @@ List directory total sizes, indented: 0 .git/refs/tags ``` +List all files, but print them in red if they match "havoc": + +``` +% lr -G -t 'name =~ "havoc" && color 160 || print' +``` + ## Installation Use `make all` to build, `make install` to install relative to `PREFIX` diff --git a/lr.1 b/lr.1 index 67af994..b175b34 100644 --- a/lr.1 +++ b/lr.1 @@ -280,6 +280,7 @@ tests are given by the following EBNF: | <modetest> | prune -- do not traverse into subdirectories | print -- always true value + | color <num> -- always true value, override 256-color <timeprop> ::= atime | ctime | mtime diff --git a/lr.c b/lr.c index d26e963..a92dcb8 100644 --- a/lr.c +++ b/lr.c @@ -165,6 +165,7 @@ enum op { EXPR_REGEXI, EXPR_PRUNE, EXPR_PRINT, + EXPR_COLOR, EXPR_TYPE, EXPR_ALLSET, EXPR_ANYSET, @@ -397,6 +398,16 @@ parse_inner() } else if (token("print")) { struct expr *e = mkexpr(EXPR_PRINT); return e; + } else if (token("color")) { + struct expr *e = mkexpr(EXPR_COLOR); + int64_t n; + if (parse_num(&n) && n >= 0 && n <= 255) { + e->a.num = n; + return e; + } else { + parse_error("invalid 256-color at '%.15s'", pos); + return 0; + } } else if (token("!")) { struct expr *e = parse_cmp(); struct expr *not = mkexpr(EXPR_NOT); @@ -1140,6 +1151,9 @@ eval(struct expr *e, struct fileinfo *fi) return 1; case EXPR_PRINT: return 1; + case EXPR_COLOR: + fi->color = e->a.num; + return 1; case EXPR_LT: case EXPR_LE: case EXPR_EQ: @@ -1217,6 +1231,8 @@ eval(struct expr *e, struct fileinfo *fi) case EXPR_REGEXI: return regexec(e->b.regex, s, 0, 0, 0) == 0; } } + default: + parse_error("invalid operation %d, please file a bug.", e->op); } return 0; |