🐱 cat alternative written in Go.

  • By Koki Sato
  • Last update: Apr 12, 2023
  • Comments: 12

gat

GitHub release (latest by date) GitHub Workflow Status Maintainability Go Report Card LICENSE

cat alternative written in Go.

demo

Installation

Homebrew

$ brew install gat

go install

$ go install github.com/koki-develop/[email protected]

Releases

Download the binary from the releases page.

Usage

$ gat --help
cat alternative written in Go.

Usage:
  gat [file]... [flags]

Flags:
  -c, --force-color     force colored output
  -f, --format string   output format (default "terminal256")
  -h, --help            help for gat
  -l, --lang string     language for syntax highlighting
      --list-formats    print a list of supported output formats
      --list-langs      print a list of supported languages for syntax highlighting
      --list-themes     print a list of supported themes with preview
  -p, --pretty          whether to format a content pretty
  -t, --theme string    highlight theme (default "monokai")
  -v, --version         version for gat

-l, --lang

Explicitly set the language for syntax highlighting.
See languages.md for valid languages.

-f, --format

Set the output format ( default: terminal256 ).
See formats.md for valid formats.

-t, --theme

Set the highlight theme ( default: monokai ).
See themes.md for valid thtmes.

-p, --pretty

Format a content pretty.
For unsupported languages, this flag is ignored.

-c, --force-color

gat disables colored output when piped to another program.
Settings the --force-color forces colored output to be enabled.
This is useful, for example, when used in combination with the less -R command.

It is also useful to declare the following function to allow gat to be used with a pager.

function gess() {
  gat --force-color "$@" | less -R
}

LICENSE

MIT

Download

gat.zip

Comments(12)

  • 1

    Possible Performance Issues when it comes to large files

    At Printer.go we should change io.ReadAll to io.Copy or io.CopyBuffer and to avoid allocation from src := string(b)

    func (p *Printer) Print(ipt *PrintInput) error {
    	// read source
    	b, err := io.ReadAll(ipt.In)
    	if err != nil {
    		return err
    	}
    	src := string(b)
    
    

    To

    // For > Go 1.20 
    func b2s(bytes []byte) string {
           return unsafe.String(unsafe.SliceData(bytes), len(bytes))
    }
    
    // For < Go 1.20
    func b2s(bytes []byte) string {
           return *(*string)(unsafe.Pointer(&bytes))
    }
    
    
    
    func (p *Printer) Print(ipt *Printlnput) error {
            // read source 
            var buf buffer.Buffer
            _, err := io.Copy(buf, ipt.In)
            if err != nil {
                   return err
            } 
            src := b2s(buf.Bytes())
    
    
    
    
  • 2

    Update module github.com/alecthomas/chroma to v2

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/alecthomas/chroma | require | major | v0.10.0 -> v2.5.0 |


    Release Notes

    alecthomas/chroma

    v2.5.0

    Compare Source

    Changelog

    • 4bfa1bb Rust: Add initial support for string interpolation
    • f5f48e2 Rust: Generalize declaritive and function-like macros (#​742)
    • 55b0e59 Rust: Attempt to lex constant idents (#​741)
    • 87869f8 Fix rust byte char capture (#​740)
    • 0ea6503 Rust: Include starting apostrophe in lifetime / loop label token (#​739)
    • 633f8e0 Removes 'tabindex="0"' from `
      ' elements
    • 3d1bc51 add missing type suffixes for nim
    • d5b3291 Add default diff support (#​732)
    • db073d8 deps: Bump modules for cmd/chromad
    • 4553686 deps: Bump go modules for cmd/chroma
    • 366b9db deps: Bump go modules
    • 482cb62 [Rust] Fix string whitespace skip
    • 4aaf294 Update issue template to reference playground shareable links
    • 5ca7345 fix: inconsistent YAML multiline parsing (#​475)
    • d330b76 feat: support sharing in playground
    • 0e2db44 Add -webkit-user-select: none; to support Safari
    • 45e3bfb Convert bashsessions lexer to XML

    v2.4.0

    Compare Source

    Changelog

    v2.3.0

    Compare Source

    Changelog

    • 6138519 Add properties to supported languages (#​674)
    • a238967 Improve properties file lexer (#​671)
    • a531e40 Add lexer for properties files (#​670)
    • dbb09a5 Add Colour.ClampBrightness and StyleBuilder.Transform.
    • e1a35d4 transact-sql: added functions string_agg and concat_ws to lexer
    • 3f86ac7 Add Gruvbox light theme
    • d55b06c Bump testify, repr to the latest version (#​665)
    • 4fa270a Update GAS lexer (#​661)
    • cde3818 Update mcfunction lexer to support newer spec of commands
    • 6538430 cfengine3: Removed rule attempting to highlight variable names
    • 111921a Add cjs to Javascript lexer
    • c13ff14 fix(styles/github-dark): update definitions, reformat
    • 96fe58e Add BSDmakefile to make lexer (#​654)
    • c714e84 add(styles/github-dark): github's dark colorscheme for chroma (#​653)
    • 3b326be Add Dockerfile.* to docker lexer
    • 5ce1d5d lexers: Add BIND DNS Zone lexer
    • f941d46 Add Chapel Lexer
    • 298b727 Revise fortran fixed format lexer to recognize comments using the "!" mark in columns 1-5 and columns > 6. Remove incorrect "0" label being a comment.
    • 9a038fb Revise fortran lexer to be consistent with the current version in pygments

    v2.2.0

    Compare Source

    Changelog

    • d18e8a4 Add InlineCode option for inline code blocks

    v2.1.0

    Compare Source

    Changelog

    • 530c45d Don't append semicolon to styleEntry if there is no other style
    • 5397b48 Append semicolon to tabWidthStyle.
    • c78b8a6 Fix extra semicolon in tabWidthStyle
    • 806ca29 Add V lexer (#​640)

    v2.0.1

    Compare Source

    Changelog

    • 4dfc2ca refactor: run go mod tidy on chromad

    v2.0.0

    Compare Source

    Changelog

    • d13d611 Add value keyword for Kotlin
    • dea6a13 Add CSS style inheritance to WithCustomCSS option
    • 7d77940 [html formatter] Add option to let users provide custom CSS styles
    • 7cc13cf Add support for F# package reference + Fix CommentPreproc detection (#​631)
    • 073a30b Add Whiley Lexer (#​628)
    • 44d1d23 fix: revert line change from pygments converter
    • d070b1c Fix for C# identifiers with leading underscores
    • f7d2bb0 fix: pin to Go 1.17 for now
    • f7893bc add an average rgb scheme
    • 7bfe2f4 fix: add Dart required keyword

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 3

    Update module golang.org/x/term to v0.7.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | golang.org/x/term | require | minor | v0.6.0 -> v0.7.0 |


    Release Notes

    golang/term

    v0.7.0

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 4

    Update module github.com/google/yamlfmt to v0.9.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/google/yamlfmt | require | minor | v0.8.0 -> v0.9.0 |


    Release Notes

    google/yamlfmt

    v0.9.0

    Compare Source

    The Content Analyzer Release

    Biggest release in a long time! Had lots of spare time to fix some stuff that has been requested for a while, as well as some stuff that came up during the work on this release.

    Features

    Downgrade to Go 1.18

    This is the most disruptive change, although I hope it won't affect anyone too much. Previously, yamlfmt was using Go 1.19 and then Go 1.20. I wasn't actually using any features from Go 1.19, and only errors.Join from Go 1.20. Since I now support installing as a pre-commit hook, and some folks still go through go install to install yamlfmt, I figured it would be in everyone's best interest to support a lower minimum version. I still make use of generics and would like to continue to, so I went with Go 1.18 as the minimum required version.

    Better Docs

    The docs have been cleaned up quite a bit and should be easier to navigate. I'm still considering moving over to using the GitHub Wiki feature, but right now it's really convenient to have the docs living with the code and there's a chance I might opt for a documentation site instead. I'll keep thinking about this!

    Content Analyzer

    A new construct has been added in this release, the ContentAnalyzer. This is an interface designed for performing actions based on the contents of the discovered yaml files. In this release, the only action currently possible is excluding yaml files based on their content instead of just exclude patterns. I added two ways to do this.

    Metadata

    In the yamlfmt library a new construct has been added called Metadata. See the Metadata docs for more information. This was created in this release to support the first type of Metadata, ignore:

    
    ### !yamlfmt!:ignore
    

    If this metadata is detected in the document, yamlfmt will exclude it from formatting.

    Exclude files by content regex (#​101)

    The other way is through a new command configuration called regex_exclude. Using Golang regexes, you can now provide a regex for yamlfmt to match with each files contents. For example, if you generate yaml files with a header comment:

    
    ### generated by: my awesome tool
    

    You can provide the following regex_exclude:

    regex_exclude:
    - ".*generated by.*"
    

    This will cause any file with that header comment to be excluded from formatting.

    Configure yamlfmt through the CLI (#​88)

    This one has been requested for a while and I've wanted to do it for a while but never could think of a nice way to do it based on how I'd chosen to implement configuration. I've settled on an implementation that I think will work pretty well, and doesn't rock the boat too much. This should be easier for folks using yamlfmt directly in CI, removing the need for a .yamlfmt file if you'd like not to.

    Drop Merge Tags (#​102)

    yamlfmt used to always add a !!merge tag explicitly:

    a: &a
    b:
     !!merge <<: *a
    

    This release adds a formatter configuration option called drop_merge_tag, that when true will ensure this tag is excluded:

    a: &a
    b:
     <<: *a
    

    Pad Line Comments (#​104)

    By default, yamlfmt will put one space between line contents and the comment on that line. The new formatter configuration option called pad_line_comments will allow you to configure the number of spaces that the yaml library uses to pad line comments. i.e. with pad_line_comments: 1

    a: 1 # comment
    

    And with pad_line_comments: 2

    a: 1  # comment
    

    Bug Fixes

    Absolute paths in doublestar exclude patterns (#​97)

    Providing an absolute system path in your exclude patterns would previously not match in most scenarios. This has been fixed, and absolute paths like /home/user/**/ignore_this_file.yaml should work now.

    Contributors

    Thank you @​badouralix for all the new suggestions this release, as well as contributing a bugfix in CLI configuration (#​100 which I'm glad was found before release), and the pad_line_comments feature!


    This ended up being a large release because I had some free time to really catch up on the features I've wanted to include for a while. Now that I've settled up some of these feature gaps, I'm going to spend my time mainly on improving the testing in this repo. I plan on setting up some end-to-end tests to improve my verification of release (which right now is just me running the command a bunch of different ways). I also want to finally properly godoc all the types at least in the main yamlfmt library section. I will still be addressing bugfixes, but feature work may get put on hold unless there's really low-hanging fruit or someone else is willing to contribute them. Thanks as always for using the tool and providing your feedback!


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 5

    Update module github.com/spf13/cobra to v1.7.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/spf13/cobra | require | minor | v1.6.1 -> v1.7.0 |


    Release Notes

    spf13/cobra

    v1.7.0

    Compare Source

    ✨ Features
    🐛 Bug fixes
    🧪 Testing & CI/CD
    🔧 Maintenance
    ✏️ Documentation

    This release contains several long running fixes, improvements to powershell completions, and further optimizations for completions.

    Thank you everyone who contributed to this release and all your hard work! Cobra and this community would never be possible without all of you! 🐍

    Full changelog: https://github.com/spf13/cobra/compare/v1.6.1...v1.7.0


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 6

    Update module github.com/alecthomas/chroma/v2 to v2.7.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/alecthomas/chroma/v2 | require | minor | v2.6.0 -> v2.7.0 |


    Release Notes

    alecthomas/chroma

    v2.7.0

    Compare Source

    Changelog


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 7

    Update module github.com/alecthomas/chroma/v2 to v2.6.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/alecthomas/chroma/v2 | require | minor | v2.5.0 -> v2.6.0 |


    Release Notes

    alecthomas/chroma

    v2.6.0

    Compare Source

    Changelog


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 8

    Update actions/setup-go action to v4

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | actions/setup-go | action | major | v3 -> v4 |


    Release Notes

    actions/setup-go

    v4

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 9

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • .github/workflows/build.yml (github-actions)
    • .github/workflows/release.yml (github-actions)
    • go.mod (gomod)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation.
    • If Renovate detects semantic commits, it will use semantic commit type fix for dependencies and chore for all others.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Automatically detect the best rangeStrategy to use.
    • Rate limit PR creation to a maximum of two per hour.
    • Limit to maximum 10 open PRs at any time.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • A collection of workarounds for known problems with packages.

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 1 Pull Request:

    Update module github.com/alecthomas/chroma to v2
    • Schedule: ["at any time"]
    • Branch name: renovate/github.com-alecthomas-chroma-2.x
    • Merge into: main
    • Upgrade github.com/alecthomas/chroma to v2.5.0

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

  • 10

    Update peter-evans/create-pull-request action to v5

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | peter-evans/create-pull-request | action | major | v4 -> v5 |


    Release Notes

    peter-evans/create-pull-request

    v5

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

  • 11

    Fails to be a `cat` alternative

    tail -f some_log_file | cat works, tail -f some_log_file | gat doesn't.

    yes | cat works, yes | gat doesn't.

    cat a_file_70_GB_in_size works, gat a_file_70_GB_in_size isn't even worth trying (as you're reading the whole file into memory before processing).

    Call it what it is: a console pretty-printer. It is in no way a cat alternative, not the same ballpark, not the same league, hardly even the same sport!

  • 12

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    Open

    These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

    Detected dependencies

    github-actions
    .github/workflows/ci.yml
    • actions/checkout v3
    • actions/setup-go v4
    • actions/checkout v3
    • actions/setup-go v4
    • golangci/golangci-lint-action v3
    .github/workflows/release.yml
    • actions/checkout v3
    • actions/setup-go v4
    • goreleaser/goreleaser-action v4
    .github/workflows/update-demo.yml
    • actions/checkout v3
    • actions/setup-go v4
    • charmbracelet/vhs-action v1
    • charmbracelet/vhs-action v1
    • peter-evans/create-pull-request v4
    .github/workflows/update-docs.yml
    • actions/checkout v3
    • actions/setup-go v4
    gomod
    go.mod
    • go 1.20
    • github.com/alecthomas/chroma/v2 v2.7.0
    • github.com/client9/csstool v0.2.2
    • github.com/google/yamlfmt v0.9.0
    • github.com/spf13/cobra v1.7.0
    • github.com/tdewolff/minify/v2 v2.12.5
    • github.com/yosssi/gohtml [email protected]
    • golang.org/x/term v0.7.0

    • [ ] Check this box to trigger a request for Renovate to run again on this repository