zaje

package module
v0.21.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

README

ZAJE

CI GoDoc GoReportCard License

zaje is a syntax highlighter that aims to cover all your shell colouring needs. It can act as an ad hoc replacement for cat and, with a spot of one-line shell functions tail and other friends.

Sounds good? Skip ahead to the screencast section to see it in action.

Motivation

Highlighting output in the shell is hardly a novel idea and its effectiveness is generally agreed to be high:) There are other tools that provide similar functionality, for instance supercat and grc. However, with this project, I was looking to create a tool that can effectively replace cat, tail and other traditional utils with zero to very little effort.

Features
  • Supports over a 100 lexers for programming languages, configuration and log formats and UNIX commands (this is done using the highlight Go package)
  • Can accept input as an argument as well as from an STDIN stream
  • Can detect the lexer to use based on:
    • The file name (when acting in cat mode)
    • The first line of text (so it will usually work nicely when piping as well)
  • Supports explicit specification of the lexer to use via a command-line arg and an ENV var
  • Easily to deploy: since it's a Go CLI app, it's one, statically linked executable with no dynamic deps
  • Easily extendable: see Revising and adding new lexers for details
Installation

Because zaje depends on lexers from the gohighlight package and also provides some helper shell functions, I've created install_zaje.sh to handle its deployment.

This is a shell script and does not require Go to be installed. Simply download and invoke with no arguments:

$ curl https://raw.githubusercontent.com/jessp01/zaje/master/install_zaje.sh > install_zaje.sh
$ ./install_zaje.sh

If you run install_zaje.sh as a super user, you only need to start a new shell to get all the functionality. Otherwise, you'll need to source the functions file (see the script's output for instructions).

Being a Golang application, you can also build it yourself with go get or fetch a specific version. Fetching from the master branch using go:

$ go install github.com/jessp01/zaje/cmd@latest

If you take this route, you'll need to copy the highlight/syntax_files and utils/functions.rc manually.

Installing super-zaje

super-zaje does everything zaje does but provides the additional functionality of extracting text from an image. It's a separate binary because it depends on the gosseract which in turn depends on libtesseract and requires its SOs to be available on the machine.

First, install zaje using install_zaje.sh, and then...

Installing on Debian/Ubuntu
# install deps:
$ sudo apt-get install -y libtesseract-dev libleptonica-dev tesseract-ocr-eng golang-go

Most popular Linux distros include the libtesseract package but it may be named differently. If the official repos of your distro of choice do not have it, you can always compile it from source.

Installing on Darwin (what people mistakenly refer to as MacOS)
$ brew install tesseract

After installing tesseract, simply invoke the below to install super-zaje:

# install super-zaje
$ go install github.com/jessp01/zaje/cmd/super-zaje@latest

You can then use it thusly:

$ ~/go/bin/super-zaje -l sh </path/to/img/of/http/url>

For example, try:

$ ~/go/bin/super-zaje "https://github.com/jessp01/zaje/blob/master/testimg/go1.png?raw=true"

NOTE: zaje is capable of detecting the lexer to use based on the first line of text but with images, you'll often need to help it and specify a designated lexer by passing -l $NAME (e.g: zaje -l sh, zaje -l server-log, etc).

ASCIInema screencast (Not a video!)

You can copy all text (commands, outputs, etc) straight off the player:)

super-zaje - extract and highlight text right off a remote image

zaje - a colouriser to cover all your shell needs

zaje - a colouriser to cover all your shell needs

Adding and revising lexers

See Revising and adding new lexers.

Supported specifiers
statement: will colour the char group green
identifier: will colour the char group blue
special: will colour the char group red
constant.string | constant | constant.number: will colour the char group cyan
constant.specialChar: will colour the char group magenta
type: will colour the char group yellow
comment: high.green will colour the char group bright green
preproc: will colour the char group bright red

Specifying the colour names in the YML is also supported, see df.yaml for an example.

If your new lexer doesn't seem to work, run zaje with -d or --debug to get more info.

Synopsis
NAME:
   zaje - Syntax highlighter to cover all your shell needs

USAGE:
   zaje [global options] command [command options] [input-file || - ]
   
COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --syn-dir ZAJE_SYNDIR, -s ZAJE_SYNDIR  Path to lexer files. The ZAJE_SYNDIR ENV var is also honoured.
   If neither is set, ~/.config/zaje/syntax_files will be used. [$ZAJE_SYNDIR]

   --lexer value, -l value  config file to use when parsing input. 
   When none is passed, zaje will attempt to autodetect based on the file name or first line of input. 
   You can set the path to lexer files by exporting the ZAJE_SYNDIR ENV var. 
   If not exported, /etc/zaje/highlight will be used.

   --debug, -d  Run in debug mode.

   --help, -h  show help

   --print-version, -V  print only the version

   
EXAMPLES:
To use zaje as a cat replacement:
$ zaje /path/to/file

To replace tail -f:
$ tail -f /path/to/file | zaje -l server-log -
(- will make zaje read progressively from STDIN)

AUTHOR:
   Jesse Portnoy <[email protected]>
   
COPYRIGHT:
   (c) packman.io

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddLineNumbers bool

AddLineNumbers prefix output with line numbers

View Source
var Debug bool

Debug print debug info

View Source
var HighlightLexer string

HighlightLexer lexer to use

View Source
var RemoveLineNumbers bool

RemoveLineNumbers useful when working on an image input

View Source
var SynDir string

SynDir path to github.com/jessp01/gohighlight/syntax_files

Functions

func DownloadFile

func DownloadFile(url, fileName string) error

DownloadFile helper function to download image file (when input is a remote image)

func HandleData

func HandleData(filename string, data []byte)

HandleData process input

func NullifyDef added in v0.21.5

func NullifyDef()

NullifyDef this is only needed for the test in `zaje_test.go`

func ReadDataFromFile

func ReadDataFromFile(filename string) ([]byte, error)

ReadDataFromFile reads from local file or a remote HTTP(s) URL and returns data

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL