aboutsummaryrefslogtreecommitdiff
path: root/content/notes/2023-05-29-grep-to-less-maintain-colors.md
blob: 718dda81f7ecf992b7d022d34209d06d41f42d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---
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
---

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](/assets/notes/grep-less.png)