owenthereal / ccat Goto Github PK
View Code? Open in Web Editor NEWColorizing `cat`
Home Page: https://github.com/owenthereal/ccat
License: MIT License
Colorizing `cat`
Home Page: https://github.com/owenthereal/ccat
License: MIT License
Really like ccat
so far. Enjoy the speed bump over pygmentize
. However, I do want to point out that ccat
's syntax recognition capabilities are sort of lacking. Is it possible to customize colors on a more granular semantic level, i.e. create different color flags for variables, functions? Most lines in a Python file fall under Plaintext
. Whole comment lines ignore the Comment
flag and output as if it were a normal line.
Warning: Calling Formula.sha1 is deprecated!
Use Formula.sha256 instead.
/usr/local/Library/Taps/jingweno/homebrew-ccat/ccat.rb:6:in `<class:Ccat>'
Please report this to the jingweno/ccat tap!
Warning: Calling SoftwareSpec#sha1 is deprecated!
Use SoftwareSpec#sha256 instead.
/usr/local/Library/Taps/jingweno/homebrew-ccat/ccat.rb:6:in `<class:Ccat>'
Please report this to the jingweno/ccat tap!
Warning: Calling Resource#sha1 is deprecated!
Use Resource#sha256 instead.
/usr/local/Library/Taps/jingweno/homebrew-ccat/ccat.rb:6:in `<class:Ccat>'
Please report this to the jingweno/ccat tap!
This tool is installable via brew. In order to make maintenance of brew easier and also support go 1.17 could the maintainers please look at adding go module support.
I love ccat, and I'm wondering what the consequences of setting an alias in my shell for cat
-> ccat
would be? Would the performance hit be significant? Might I run into encoding issues? Is this just a terrible idea?
alias ccat="pygmentize -O style=monokai -f console256 -g"
Could such a feature be considered for adding? Something like
ccat test.json --pretty
To make minified code more readable? Or is this out of scope for what you intend with ccat?
let's pretend the following file existed... it would be cool if ccat made minus (-) lines in red and plus (+) lines in green.
diff --git i/roles/splunk-shcluster/tasks/main.yml w/roles/splunk-shcluster/tasks/main.yml
index ecc8e75..494a30c 100644
--- i/roles/splunk-shcluster/tasks/main.yml
+++ w/roles/splunk-shcluster/tasks/main.yml
@@ -15,12 +15,8 @@
assert: { that: "splunk_infra.splunk_master_uri is defined" }
- name: get list of splunk sh cluster urls
- set_fact: sh_cluster_member="https://{{ item }}:{{ splunk_mgmtHostPort }}"
+ set_fact: sh_cluster_servers_list="https://{{ item }}:{{ splunk_mgmtHostPort }},{{ sh_cluster_servers_list | default('') | regex_replace(',$', '') }}"
with_items: "{{ play_hosts }}"
- register: sh_cluster_members_result
-
-- name: turn sh_cluster_members values into new list
- set_fact: sh_cluster_members_list="{{ sh_cluster_members_result.results | map(attribute='ansible_facts.sh_cluster_member') | list | join(",") }}"
- splunk_facts:
sudo: True
What is the recommended way to page through the output of ccat? ccat README.md | less -R
for example does not work (no colors) even though it works for cat my.patch | colordiff | less -R
.
Or would it make more sense to integrate pager into ccat (ccat -p README.md
)?
I think its sort of standard to avoid colour while the output is passed to a pipe. It helps in further processing of the data. I understand it may be handy while piping to less
or so. But most of the time, its better to be avoided.
Perhaps provide a flag and disable in by default.
would be cool if we ubuntu users can apt-get install it too
Hi,
I want to install ccat on my new Debian Jessie 8.10 VM (using Vagrant), but there's an error :
$ go get -u github.com/jingweno/ccat
# cd .; git clone https://github.com/jingweno/ccat /home/vagrant/go/src/github.com/jingweno/ccat
Clonage dans '/home/vagrant/go/src/github.com/jingweno/ccat'...
fatal: unable to access 'https://github.com/jingweno/ccat/': gnutls_handshake() failed: Public key signature verification has failed.
package github.com/jingweno/ccat: exit status 128
Go version :
$ go version
go version go1.11.5 linux/amd64
So, have you an idea to help me please ? :)
F.
I use dark terminal. It is a pain to write every time --bg "dark"
.
It should be simple to read some environment variable (or any other type of global configuration file, e.g. ~/.ccat file) and define it globally. Then command line argument can just overwrite the global configuration, if present.
P.S. I want to add that light scheme looks ok on dark terminal, but i use dark terminal with transparency and only then it is unreadable. As it is unreadable for small portion of users, i do not think it is critical.
Seems to happen the most on long "jsonl" files. That is a file with JSON that has a new JSON document on each line.
Here's an example stack trace:
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x23bc300fde44 pc=0x27209]
runtime stack:
runtime.throw(0x21cd00, 0x2a)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.(*gcWork).put(0xc820022720, 0xc8204bc000)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mgcwork.go:87 +0x49
runtime.greyobject(0xc8204bc000, 0x0, 0x0, 0xc81ffda1ff, 0x0, 0x66fe40, 0xc820022720)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mgcmark.go:956 +0x2f1
runtime.shade(0xc8204bc024)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mgcmark.go:894 +0x9a
runtime.gcmarkwb_m(0xc8204bc000, 0xc8204bc024)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mbarrier.go:91 +0xc1
runtime.writebarrierptr_nostore1.func1()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mbarrier.go:117 +0x134
runtime.systemstack(0xc820021500)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:262 +0x79
runtime.mstart()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/proc1.go:674
goroutine 1 [running]:
runtime.systemstack_switch()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:216 fp=0xc820055288 sp=0xc820055280
runtime.writebarrierptr_nostore1(0xc8204bc000, 0xc8204bc024)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mbarrier.go:118 +0x71 fp=0xc8200552c0 sp=0xc820055288
runtime.writebarrierptr(0xc8204bc000, 0xc8204bc024)
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/mbarrier.go:137 +0x4b fp=0xc8200552f0 sp=0xc8200552c0
bytes.(*Buffer).grow(0xc8204bc000, 0x5, 0xe160ebb)
/usr/local/Cellar/go/1.5.1/libexec/src/bytes/buffer.go:106 +0x151 fp=0xc820055398 sp=0xc8200552f0
bytes.(*Buffer).WriteString(0xc8204bc000, 0xc82006a710, 0x5, 0x5, 0x0, 0x0)
/usr/local/Cellar/go/1.5.1/libexec/src/bytes/buffer.go:140 +0x4b fp=0xc820055400 sp=0xc820055398
main.Colorize(0x1ddb00, 0x5, 0xc8204ba000, 0xd, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/color.go:111 +0xcc6 fp=0xc820055728 sp=0xc820055400
main.Printer.Print(0xc82006c600, 0x6641c0, 0xc82008c008, 0x1, 0xc8204ba000, 0xd, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/printer.go:140 +0x7c fp=0xc820055778 sp=0xc820055728
github.com/jingweno/ccat/Godeps/_workspace/src/github.com/sourcegraph/syntaxhighlight.Print(0xc8200a8b00, 0x6641c0, 0xc82008c008, 0x664550, 0xc82006c600, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/.gopath/src/github.com/jingweno/ccat/Godeps/_workspace/src/github.com/sourcegraph/syntaxhighlight/highlight.go:162 +0xd1 fp=0xc8200557e8 sp=0xc820055778
main.CPrint(0x664528, 0xc82008c020, 0x6641c0, 0xc82008c008, 0xc82006c600, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/printer.go:130 +0xa3 fp=0xc820055848 sp=0xc8200557e8
main.ColorPrinter.Print(0xc82006c600, 0x664528, 0xc82008c020, 0x6641c0, 0xc82008c008, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/ccat.go:34 +0x55 fp=0xc820055888 sp=0xc820055848
main.AutoColorPrinter.Print(0xc82006c600, 0x664528, 0xc82008c020, 0x6641c0, 0xc82008c008, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/ccat.go:23 +0x7a fp=0xc8200558d0 sp=0xc820055888
main.CCat(0x7ffeefbff755, 0xa, 0x664500, 0xc82006c600, 0x6641c0, 0xc82008c008, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/ccat.go:75 +0x1fc fp=0xc8200559a8 sp=0xc8200558d0
main.(*ccatCmd).Run(0xc82006c6f0, 0xc820070b60, 0xc82006aac0, 0x1, 0x1)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/main.go:81 +0x7af fp=0xc820055c48 sp=0xc8200559a8
main.(*ccatCmd).Run-fm(0xc820070b60, 0xc82006aac0, 0x1, 0x1)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/main.go:102 +0x48 fp=0xc820055c78 sp=0xc820055c48
github.com/jingweno/ccat/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).execute(0xc820070b60, 0xc820090010, 0x1, 0x1, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/.gopath/src/github.com/jingweno/ccat/Godeps/_workspace/src/github.com/spf13/cobra/command.go:495 +0x6e3 fp=0xc820055d88 sp=0xc820055c78
github.com/jingweno/ccat/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).Execute(0xc820070b60, 0x0, 0x0)
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/.gopath/src/github.com/jingweno/ccat/Godeps/_workspace/src/github.com/spf13/cobra/command.go:560 +0x180 fp=0xc820055e88 sp=0xc820055d88
main.main()
/private/tmp/ccat20151130-62599-1v7ai72/ccat-1.1.0/main.go:127 +0x4f4 fp=0xc820055f50 sp=0xc820055e88
runtime.main()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/proc.go:111 +0x2b0 fp=0xc820055fa0 sp=0xc820055f50
runtime.goexit()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1 fp=0xc820055fa8 sp=0xc820055fa0
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1
Is there any chance of adding colorizing to the other commands, like tail/head/more/less
, etc?
As an option, you can forward all arguments to the command(let's take tail
as an example).
Assuming this command was passed to the console - ctail -20 ~/Folder1/folder2/.file
It can be transformed into something like tail -20 ~/Folder1/folder2/.file | ccat
As for now, we can manually add support for this. Just add
ctail() {
tail "$@" | ccat
}
to your bash config file(and same for all other functions, if needed). But it would be great to have those functions as built-in, without the need of transforming your bash config file.
Hi,
I recently got the following error from a script that I run regularly
Error: unknown shorthand flag: 't' in -t
Run 'ccat help' for usage.
From man cat
-t Display non-printing characters (see the -v option), and display tab characters as `^I'.
Could ccat at least ignore that switch to be compatible with the cat
command on macOS?
Kind regards,
David
I find default theme of ccat is pretty nice when display color of .go files.
Is there a way to import it to use as a colorscheme for golang in vim? maybe a go.vim?
Rainbow colors are nice to have like: lolcat
Lolcat's deficit is handling utf8, which Golang handles gracefully. This would be great to have in ccat
so I can move all my monitoring/uptime scripts from lolcat
to ccat
.
would it be possible to restrict ccat
to a particular set of extensions (ie .js
, .json
, etc), otherwise defaulting to regular cat
?
> brew tap jingweno/ccat
==> Tapping jingweno/ccat
Cloning into '/usr/local/Library/Taps/jingweno/homebrew-ccat'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
Checking connectivity... done.
Tapped 1 formula (26 files, 108K)
> brew install ccat
==> Installing ccat from jingweno/homebrew-ccat
==> Downloading https://github.com/jingweno/ccat/archive/v0.0.1.tar.gz
######################################################################## 100.0%
==> go build -o ccat
/usr/local/Cellar/go/1.4.2/libexec/src/github.com/codegangsta/cli (from $GOROOT)
/Users/m/dev/goPlay/src/github.com/codegangsta/cli (from $GOPATH)
printer.go:7:2: cannot find package "github.com/sourcegraph/syntaxhighlight" in any of:
/usr/local/Cellar/go/1.4.2/libexec/src/github.com/sourcegraph/syntaxhighlight (from $GOROOT)
/Users/m/dev/goPlay/src/github.com/sourcegraph/syntaxhighlight (from $GOPATH)
READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
https://github.com/jingweno/homebrew-ccat/issues
Is it possible to pipe the file output's to some other command before colorizing?
E.g. ccat file --pipe-to="grep 'pattern'"
EDIT: I found out know it's possible to do it like this:
cmd file | [commands] | ccat
Reading from stdin instead, so I guess it solves it for me.
i am a phper ,this tool is such cool,but i found that it does not support php,so sad :(
FROM base:1.0.0
RUN rm -rf /path/to/wildcard/*
RUN stuff && things
FROM base:1.0.0
RUN rm -rf /path/to/something
RUN stuff && things
In the first case everything from /*
onwards is not highlighted.
thank u.
I started getting this error today. I think you need to release a new version.
Use Formula.sha256 instead.
/usr/local/Homebrew/Library/Taps/jingweno/homebrew-ccat/ccat.rb:6:in `<class:Ccat>'
Please report this to the jingweno/ccat tap!
I saw the original cat has the switch -n that would prefix line numbers , might be useful ?
Is it possible to use ccat to colorize infinite stream?
My use case is to use it with tail -f
like this:
tail -f /some/log/file.log | ccat
Currently it is not displaying anything.
cat -> ccat
less -> cless ?
it would be really nice.
$ env | grep GO
GOROOT=/usr/local/go
GOPATH=/home/rpinson/go
$ go install github.com/jingweno/ccat
../go/src/github.com/gogo/protobuf/proto/text.go:44:2: cannot find package "encoding" in any of:
/usr/local/go/src/pkg/encoding (from $GOROOT)
/home/rpinson/go/src/encoding (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/defs.go:10:2: cannot find package "sourcegraph.com/sourcegraph/go-nnz/nnz" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/go-nnz/nnz (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/go-nnz/nnz (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/repositories.go:9:2: cannot find package "sourcegraph.com/sourcegraph/go-vcs/vcs" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/go-vcs/vcs (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/go-vcs/vcs (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/build_data.go:8:2: cannot find package "sourcegraph.com/sourcegraph/rwvfs" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/rwvfs (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/rwvfs (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/defs.go:13:2: cannot find package "sourcegraph.com/sourcegraph/srclib/graph" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/srclib/graph (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/srclib/graph (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/defs.go:14:2: cannot find package "sourcegraph.com/sourcegraph/srclib/store" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/srclib/store (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/srclib/store (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/defs.go:15:2: cannot find package "sourcegraph.com/sourcegraph/srclib/unit" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/srclib/unit (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/srclib/unit (from $GOPATH)
../go/src/sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph/query_tokens.go:11:2: cannot find package "sourcegraph.com/sourcegraph/vcsstore/vcsclient" in any of:
/usr/local/go/src/pkg/sourcegraph.com/sourcegraph/vcsstore/vcsclient (from $GOROOT)
/home/rpinson/go/src/sourcegraph.com/sourcegraph/vcsstore/vcsclient (from $GOPATH)
$ go get github.com/jingweno/ccat
package encoding: unrecognized import path "encoding"
munmap of stack space failed: errno 22
Aborted
goroutine 1 [select]:
main.$nested27
/build/buildd/gccgo-go-1.2.1/src/cmd/go/http.go:57
main.httpsOrHTTP
/build/buildd/gccgo-go-1.2.1/src/cmd/go/http.go:65
main.repoRootForImportDynamic
/build/buildd/gccgo-go-1.2.1/src/cmd/go/vcs.go:468
main.repoRootForImportPath
/build/buildd/gccgo-go-1.2.1/src/cmd/go/vcs.go:362
main.downloadPackage
/build/buildd/gccgo-go-1.2.1/src/cmd/go/get.go:269
main.download
/build/buildd/gccgo-go-1.2.1/src/cmd/go/get.go:166
main.download
/build/buildd/gccgo-go-1.2.1/src/cmd/go/get.go:232
main.download
/build/buildd/gccgo-go-1.2.1/src/cmd/go/get.go:232
main.runGet
/build/buildd/gccgo-go-1.2.1/src/cmd/go/get.go:72
main.main
/build/buildd/gccgo-go-1.2.1/src/cmd/go/main.go:161
goroutine 3 [syscall]:
goroutine in C code; stack unavailable
Am I doing something wrong here?
$ ccat foo
2017/05/12 09:51:26 open foo: no such file or directory
I think it's go's default log package causing this. The timestamp here doesn't make much sense.
seems formula have been added upstream: Homebrew/legacy-homebrew@f8e10bb
> brew update; brew upgrade
Warning: Could not create link for jingweno/ccat/ccat, as it
conflicts with Homebrew/homebrew/ccat. You will need to use the
fully-qualified name when referring this formula, e.g.
brew install jingweno/ccat/ccat
Updated Homebrew from 84dd2e2f to d956958c.
==> New Formulae
ccat
...
one solution is to remove this tap:
brew untap jingweno/ccat
It would be awesome to have PHP7 included in the alternatives. Let me know if I can help.
ccat /directory/name
does not warn that the target is a directory – it simply returns with exit code 0 and nothing printed to screen. While not a serious issue, considering the user will likely discover their error, it does have potential to cause unnecessary confusion.
cat
returns the following: cat: /directory/name: Is a directory
with exit code 1
OS X 10.11.5 / ccat v1.1.0
Let us pass in a 3 digit number such as
ccat -G String="248" FILE
Then we could significantly customize the colors to our preferences.
Reference:
https://misc.flogisoft.com/bash/tip_colors_and_formatting
Title is pretty self explanatory but if you ccat file.go | less
the scrollable text is not colored. Not entirely sure if you can color something and then pipe it but if you can it would be a nice feature to run through long files using less to scroll
like monakai
Hi,
If I just :
#ccat ~/.tcshrc
I can see that the comments are not displayed in lightgrey.
It could be useful to be able to define what a comment is and to automatically set it depending on the kind of file.
shell script, .bashrc, .tcshrc, ... => #
text file => none or user-defined
verilog => //
...
Either ccat could recognize the file type or the user could define the comment with a -comment = ... argument.
multi-line arguments will be more tricky but lets start with a simple stuff.
Regards.
Xuo.
Would be nice to provide a way to colorise output of CSV files like the raindow csv IDE plugins.
so we can track the status of this
When I type like ccat pack' and hit [TAB] in the hope to have it autocomplete to
ccat package.json`, nothing happens.
Guess it does not get on well with my current zprezto config. Or am I missing something?
Will it be easy to implement such an option?
When ccat
is called with this option, it will add a linebreak at end of file, if the file itself does not end with a linebreak. (This is not an option from the original cat
)
Example:
user@host~$ ccat my_number.txt
13189057482user@host~$
vs
user@host~$ ccat -l my_number.txt
13189057482
user@host~$
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.