Giter Site home page Giter Site logo

blush's Introduction

Blush

PkgGoDev GitHub go.mod Go version Build Status License: MIT Coverage Status Go Report Card

With Blush, you can highlight matches with any colours of your choice.

1

  1. Install
  2. Usage
  3. Arguments
  4. Colour Groups
  5. Colours
  6. Complex Grep
  7. Suggestions
  8. License

Install

You can grab a binary from releases page. If you prefer to install it manually you can get the code and install it with the following command:

$ go install github.com/arsham/blush@latest

Make sure you have go>=1.18 installed.

Usage

Blush can read from a file or a pipe:

$ cat FILENAME | blush -b "print in blue" -g "in green" -g "another green"
$ cat FILENAME | blush "some text"
$ blush -b "print in blue" -g "in green" -g "another green" FILENAME
$ blush "some text" FILENAME

Note

Although this program has a good performance, but performance is not the main concern. There are other tools you should use if you are searching in large files. Two examples:

Normal Mode

This method shows matches with the given input:

$ blush -b "first search" -g "second one" -g "and another one" files/paths

Any occurrence of first search will be in blue, second one and and another one are in green.

2

Dropping Unmatched

By default, unmatched lines are not dropped. But you can use the -d flag to drop them:

3

Arguments

Argument Shortcut Notes
N/A -i Case insensitive matching.
N/A -R Recursive matching.
--no-filename -h Suppress the prefixing of file names on output.
--drop -d Drop unmatched lines

File names or paths are matched from the end. Any argument that doesn't match any files or paths are considered as regular expression. If regular expressions are not followed by colouring arguments are coloured based on previously provided colour:

$ blush -b match1 match2 FILENAME

4

Notes

  • If no colour is provided, blush will choose blue.
  • If you only provide file/path, it will print them out without colouring.
  • If the matcher contains only alphabets and numbers, a non-regular expression is applied to search.

Colour Groups

You can provide a number for a colour argument to create a colour group:

$ blush -r1 match1 -r2 match2 -r1 match3 FILENAME

5

All matches will be shown as blue. But match1 and match3 will have a different background colour than match2. This means the numbers will create colour groups.

You also can provide a colour with a series of match requests:

$ blush -r match1 match3 -g match2 FILENAME

Colours

You can choose a pre-defined colour, or pass it your own colour with a hash:

Argument Shortcut
--red -r
--green -g
--blue -b
--white -w
--black -bl
--yellow -yl
--magenta -mg
--cyan -cy

You can also pass an RGB colour. It can be in short form (--#1b2, -#1b2), or long format (--#11bb22, -#11bb22).

6

Complex Grep

You must put your complex grep into quotations:

$ blush -b "^age: [0-9]+" FILENAME

7

Suggestions

This tool is made to make your experience in terminal a more pleasant. Please feel free to make any suggestions or request features by creating an issue.

License

Use of this source code is governed by the MIT License. License file can be found in the LICENSE file.

blush's People

Contributors

arsham avatar juneezee 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

blush's Issues

Rewrite WriteTo and Read functions of Blush

At the moment, WriteTo() function uses bufio.Scanner() with a custom buffer and a large token size in order to read from readers line by line, which is not ideal. On the other hand, Read() uses a bytes.Buffer instance and reads everything on first call. Both of these methods require refactoring.

WriteTo (1)

This method should request the next available line or more if required (2), and call Find() methods of all finders, keeping the results in a buffer. Then it should write up to length of given io.Writer, while keeping the rest of the buffer for the next try, until it processes everything.

Read

This method shares most of WriteTo()'s logic.

Notes

  • (1) io.Copy() uses WriteTo if available, then Read() method.
  • (2) Next available line(s) should be enough to fill the provided Writer or byte slice.
  • There is a single reader in Blush struct, which is either os.Stdin or reader.MultiReader and when its Read() method is called, it automatically closes previously processed reader and opens the next one. Therefore there is no action required here.
  • Reads can be split in the middle of colouring. This means the terminal's codes for colouring could span between read calls. Therefore it should unformat if there's been an interruption in between, otherwise it could mess up the terminal's colours.
  • In case of reader.MultiReader usage, if any filed isn't ended with a new line and readers rotate, it should account for a new line in between operations.

Help flag

No help flag available from the CLI. Can't expect people to continually reference the github docs.
Any reason not to do this? If not I'll look at it and put in a PR this weekend.

Could you explain how to install/run?

Could you explain how to install/run?
I've already installed golang... what then, I'm on ubuntu, but i suppose it's quite similar for everyones go installation.

doesn't compile on Debian9 with go1.7.4 / go minimum version

I have Debian 9 Stretch and go get doesn't work

$ go version
go version go1.7.4 linux/amd64

$ go get github.com/arsham/blush
# github.com/arsham/blush/cmd
opt/go/src/github.com/arsham/blush/cmd/args.go:78: undefined: sort.SliceStable
opt/go/src/github.com/arsham/blush/cmd/args.go:118: undefined: sort.SliceStable
opt/go/src/github.com/arsham/blush/cmd/args.go:122: undefined: sort.SliceStable

SliceStable seems to be introduced with 1.8, https://golang.org/doc/go1.8 ? So maybe the readme needs an update?

Not really an issue...

Just a suggestion but you might want to switch to a simpler prompt for your screenshots. The one you're using is cool and everything but a little distracting when we really just want to see how the results are getting colored.

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.