https://github.com/cdepillabout/highlight
command line tool for highlighting parts of files that match a regex
https://github.com/cdepillabout/highlight
cli grep hacktoberfest haskell highlight highlighting hrep regex
Last synced: 6 months ago
JSON representation
command line tool for highlighting parts of files that match a regex
- Host: GitHub
- URL: https://github.com/cdepillabout/highlight
- Owner: cdepillabout
- License: bsd-3-clause
- Created: 2017-06-05T08:40:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-05-26T05:49:49.000Z (over 3 years ago)
- Last Synced: 2025-06-13T01:39:24.678Z (8 months ago)
- Topics: cli, grep, hacktoberfest, haskell, highlight, highlighting, hrep, regex
- Language: Haskell
- Homepage: http://hackage.haskell.org/package/highlight
- Size: 307 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Highlight
=========
[](https://github.com/cdepillabout/highlight/actions)
[](https://hackage.haskell.org/package/highlight)
[](http://stackage.org/lts/package/highlight)
[](http://stackage.org/nightly/package/highlight)

`highlight` is a command line program for highlighting parts of a file matching
a regex.
For example, take a look at the following file:

`highlight` can be used to highlight the regex `cat`:

**Table of Contents**
- [Highlight](#highlight)
- [Uses](#uses)
- [`highlight`](#highlight)
- [highlight output from `grep`](#highlight-output-from-grep)
- [`hrep`](#hrep)
- [Installation](#installation)
- [Other ways to highlight parts of files](#other-ways-to-highlight-parts-of-files)
- [Contributions](#contributions)
- [Additional flags](#additional-flags)
- [Development](#development)
- [Build](#build)
- [Test](#test)
## Uses
This package installs two binaries, `highlight` and `hrep`. The following
section explains the main uses of `highlight` and `hrep`.
### `highlight`
`highlight` is used to highlight a given regex in a file, while printing out
all lines of the file.
The short example above show how to use `highlight` to highlight a regex in a
single file. It is also possible to use `highlight` on multiple files at once:

`highlight` will color and stripe the filenames to make it easier to see which
line came from which file. This also shows an example of the `--ignore-case`
option, which is similar to `grep`'s `--ignore-case` option.
### highlight output from `grep`
`highlight` has a special option for highlighting output from `grep`:

This `--from-grep` option will color and stripe filenames, similar to the
previous example.
### `hrep`
With the previous `--from-grep` option to `highlight`, one unfortunate point is
that the regex has to be specified twice, once to `grep` and once to
`highlight`.
The `hrep` command can solve this for us. It is just like the `grep` command,
but it will color and stripe filenames:

## Installation
`highlight` and `hrep` can be installed with
[`stack`](https://docs.haskellstack.org/en/stable/README/):
```sh
$ stack --resolver nightly-2017-07-03 install highlight
```
By default, `stack` will install binaries into `~/.local/bin/`.
It should also be possible to use `cabal` to install this package.
## Other ways to highlight parts of files
It is possible to highlight lines matching a given regex with `grep` two
different ways.
1. Use a special regex that will match any line, but only highlight the part
desired. It would look like this:
```sh
$ grep 'about|$' file-cats file-dogs file-goats
```
2. Give a large `--context` flag:
```sh
$ grep --context 9999 'about' file-cats file-dogs file-goats
```
However, neither of these will color and stripe filenames.
## Contributions
Feel free to open an
[issue](https://github.com/cdepillabout/pretty-simple/issues) or
[PR](https://github.com/cdepillabout/pretty-simple/pulls) for any
bugs/problems/suggestions/improvements.
### Additional flags
`highlight` and `hrep` do not currently support all flags and options that
`grep` does. Ideally, `highlight` and `hrep` would be drop-in replacements for
`grep`, supporting all the same flags and options as `grep`.
If there is a flag or option you frequently use and want supported with
`highlight` or `hrep`, please feel free to open an issue or PR. Some
flags/options will be relatively easy to support, while some may require quite
a large amount of additional code.
## Development
### Build
`highlight` and `hrep` can be built will the following command. See the
[Installation](#installation) section above for information about `stack`.
```sh
$ stack build
```
### Test
The tests can be run with the following command:
```sh
$ stack test
```