MyNixOS website logo
Description

Command line tool for highlighting parts of files matching a regex.

Please see README.md.

Highlight

Build Status Hackage Stackage LTS Stackage Nightly BSD3 license

highlight is a command line program for highlighting parts of a file matching a regex.

For example, take a look at the following file:

non-highlighted file

highlight can be used to highlight the regex cat:

simple highlighted file

Table of Contents

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:

multiple highlighted files

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:

highlight 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:

hrep example

Installation

highlight and hrep can be installed with stack:

$ 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:

    $ grep 'about|$' file-cats file-dogs file-goats
    
  2. Give a large --context flag:

    $ 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 or PR 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 section above for information about stack.

$ stack build

Test

The tests can be run with the following command:

$ stack test
Metadata

Version

1.0.0.2

Executables (2)

  • bin/highlight
  • bin/hrep

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows