From 0cb6a5c81271a61e930505f3315b1d67bdf22724 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 16 Jul 2023 22:46:06 +0200 Subject: Renamed all the notes files to include date --- .../2023-05-29-grep-to-less-maintain-colors.md | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 content/notes/2023-05-29-grep-to-less-maintain-colors.md (limited to 'content/notes/2023-05-29-grep-to-less-maintain-colors.md') diff --git a/content/notes/2023-05-29-grep-to-less-maintain-colors.md b/content/notes/2023-05-29-grep-to-less-maintain-colors.md new file mode 100644 index 0000000..6fc40a1 --- /dev/null +++ b/content/notes/2023-05-29-grep-to-less-maintain-colors.md @@ -0,0 +1,25 @@ +--- +title: "Grep to Less that maintain colors" +url: grep-to-less-maintain-colors.html +date: 2023-05-29T21:27:07+02:00 +type: note +draft: false +tags: [bash] +--- + +I often use `grep` to search for todo's in my code and other people's code and +then pipe them in `less` and I missed having colors that grep outputs in `less`. + +- Grep's `--color=always` use markers to highlight the matching strings. +- Less's `-R` option outputs "raw" control characters. + +You could use `alias grep='grep --color=always'` and `alias less='less -R'` or +create todo function in your `.bashrc` that accepts first argument as search +string. + +```sh +# This is where the magic happens. +grep --color=always -rni "TODO:" | less -R +``` + +![Less and grep](/notes/grep-less.png) -- cgit v1.2.3