Giter Site home page Giter Site logo

hhighlighter's Introduction

hhighlighter (or just h)

A tiny utility to highlight multiple keywords with different colors

Description

h (hhighlighter is just a name to help search engines) is a really tiny helper script meant to highlight keywords in the output of another *nix command:

Requirements

h is just a tiny facade in front of ack so you need to install it first.

What is ack?

ack is a tool like grep, optimized for programmers

Designed for programmers with large heterogeneous trees of source code, ack is written purely in portable Perl 5 and takes advantage of the power of Perl’s regular expressions.

ack installation

ack is part of many major linux distributions so you should use your package manager to install it.

If you want to install ack in a portable way ( at the end ack is just a script ) you do it in this way:

curl https://beyondgrep.com/ack-2.16-single-file > ~/bin/ack && chmod 0755 !#:3

Installation Instructions

h is implemented as a function in bash.

You can install it in one of these ways:

  • copy and paste h() function in your ~/.bashrc

  • configure your ~/.bashrc to load the external script with . /path/to/h.sh

or using Shinichi Okada’s Awesome Package Manager - https://github.com/shinokada/awesome - awesome -i paoloantinori/hhighlighter h

Zsh with Oh-My-Zsh

Just run the following commands

cd $ZSH_CUSTOM/plugins
git clone [email protected]:paoloantinori/hhighlighter.git h
mv h/h.sh h/h.plugin.zsh

then add h to your plugins variable in your ~/.zshrc file.

plugins=(
  h
  ...
)

Platform Specifics

h has currently been tested only on bash and zsh on Linux and MacOSX.

Usage

h is meant to consume the output of another Linux command via pipe

$ h
usage: YOUR_COMMAND | h [-i] [-d] args...
	-i : ignore case
	-d : disable regexp
	-n : invert colors

Configuration

h supports overriding of its default colors via 2 environment variables: H_COLORS_FG and H_COLORS_BG.

These variables accepts a comma separated values set of Perl Term::ANSIColor configuration entries. For a table of RGB colors definition check this handy map:

RGB Colors Map
Figure 1: RGB Map, taken from https://github.com/jbnicolai/ansi-256-colors

Ex.

export H_COLORS_FG="bold black on_rgb520","bold red on_rgb025"
export H_COLORS_BG="underline bold rgb520","underline bold rgb025"
echo abcdefghi | h   a b c d

Examples

Default colors
echo "abcdefghijklmnopqrstuvxywz" | h   a b c d e f g h i j k l
Invert colors
echo "abcdefghijklmnopqrstuvxywz" | h -n   a b c d e f g h i j k l
Support for tail in follow mode
tail -F | h keyword1 keyword2
Case Insensitive
mvn clean install | h -i failure success
Disable regular expression
tail -F my.log | h -d org.apache.camel
Highlight multiple keys with the same color (using regexp syntax)
echo abcd | h 'b|d'

Screenshots

Rainbow

Tail

Maven

Custom Colors

Demos

Ascii Cinema Gif
Ascii Cinema GifAscii Cinema Gif
Ascii Cinema Demo
Ascii Cinema: Ascii Cinema

hhighlighter's People

Contributors

desyncr avatar iax7 avatar mperry2 avatar paoloantinori avatar timofeyb avatar tingham avatar twang817 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hhighlighter's Issues

Work with ack installed as ack-grep

I have ack installed on my Ubuntu Machine (14.04.2 LTS), but it is not installed as ack but as ack-grep. I think it is that way by default in Ubuntu to avoid a name collision with some other tool. Could h detect ack-grep and use that?

Regex support

I love this awesome utility, I appreciate your work 😃
I will try to implement it and contribute a PR.

my use case is to highlight all characters which are not in the unicode range U+0021-U+007A (which's a subset of the basic latin block)

No output

I installed it on Zsh using Zplugin:

zplg ice as"command" cp"h.sh -> h" pick"h"
zplg load paoloantinori/hhighlighter

But running the examples, also after the example export commands, yields empty output. I tried changing #!/bin/bash to #!/usr/local/bin/bash to use OS X Homebrew Bash 4.4, but no improvement. Maybe the command doesn't support OS X?

piping with less

First of all...very good tool!

This might be a known limitation, but when I do like this

cat LICENSE.txt | h copyright | less

It displays like that: (just color encodings shown instead of colors)

"Licensor" shall mean the ESC[4;1;31mcopyrightESC[0m owner or entity authorized byESC[0mESC[K
  the ESC[4;1;31mcopyrightESC[0m owner that is granting the License.ESC[0mESC[K

I'm just curious, supporting less would be quite a challenge or is it feasible?

Bash's 'nounset' yields 'ZSH_VERSION: unbound variable'

I put the latest code of s.sh into a file.

I created this:

#!/usr/bin/env bash
set -o nounset
source "/my/path/h.sh" # replace with a real path
echo "abcdefghijklmnopqrstuvxywz" | h a b c d e f g h i j k l

Result: h.sh: line 59: ZSH_VERSION: unbound variable,

local _i=0 in bash declares _i as string

Noticed that in bash, your code:
local _i=0
then later
_i=$i+1
ends up with:
_i=0+1+1+1
Intended code for bash should be (not tested on other shells):
local -i _i=0

How to change color, how to get a full list of colors

hello,
i am trying unsuccessfully to custum the colors, it is very painfull, sorry.

this is the error I have:
#############################
export H_COLORS_FG="bold black on_rgb520","bold red on_rgb025" (=> why is ther an on_ appearing there ?)

export H_COLORS_BG="underline bold rgb520","underline bold rgb025"

🕙 09:25:39 ❯ echo a | h a
Invalid attribute name on_rgb520,bold at /opt/homebrew/bin/ack line 993.
#############################

  • please, I would like a page, where I can see and simply copy paste the colors in your env variable, so it works easily and I know easily the colors I am using, because I want more than 12 colors. Is there one ?
  • or could ACK or another tool do the same job easier ? kind of highlight alternative in 2023 ?
  • do I need to setup your env variable before or after : source "$COSMOS_LIB/h/h.sh" ?
  • what is the recommended way to pipe hightlight colors if more than 12 colors needed ?
  • is that normal that sometimes, when opening, closing the bash,, I do not know why, it is like colors are not displaying in the same order, the red become green , on not background become background color... I did not succeed to identify the case where this happen ?

tks a lot

feature: option to disable --passthru

Example: I'm parsing a mail log and I just want to see when a message comes in and the line that prints the result of the spam filtering. For now, I have to insert a grep line into the pipeline before h. This is not all bad, though, since I can filter on one string and highlight another.

Does not work

No, seriously. I copied h.sh into ~/h.sh. I have installed ack via Homebrew on OSX 10.11.3 (note - that's a beta version of OSX), and it's working:

ack 2.14
Running under Perl 5.22.1 at /opt/local/bin/perl5.22

Copyright 2005-2014 Andy Lester.

This program is free software.  You may modify or distribute it
under the terms of the Artistic License v2.0.

Then I added the following line to my ~/.zshrc:

. ~/h.sh

Then I did this to test it out:

$ tail -f /var/log/system.log | h System

Which gave this:

usage: YOUR_COMMAND | h [-idn] args...
    -i : ignore case
    -d : disable regexp
    -n : invert colors

Incorrect ack install instructions

The readme has installation instructions that point to an old, outdated version of ack

curl http://beyondgrep.com/ack-2.08-single-file > ~/bin/ack && chmod 0755 !#:3

In fact, that version of ack has a security hole in it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.