项目作者: foxfriends

项目描述 :
Syntax aware cat
高级语言: Rust
项目地址: git://github.com/foxfriends/syncat.git
创建时间: 2019-02-19T23:05:04Z
项目社区:https://github.com/foxfriends/syncat

开源协议:

下载


Syncat

Syntax aware cat utility. Provides syntax highlighting to files printed on the command line using
Tree-sitter to parse the files, and ANSI escape codes to colour them.

Features

Syncat aims to provide similar features to the standard cat and the similar Bat tool:

  1. Git integration (-g)
  2. Show line endings (-e)
  3. Line numbering (-n)
  4. Multiple levels of framing (-f or -ff)
  5. File concatenation
  6. Parses any file type accurately using Tree-sitter
  7. Customizable syntax colouring using stylesheets

In particular, the advantage of Syncat over the other options is that the parsing is done using
Tree-sitter instead of with regular expressions, which makes it

  • very fast;
  • robust enough to provide useful results even in the presence of syntax errors.

Syncat does not support automatic paging, but you can just use less -r to handle that.

Installation

Syncat can be installed from crates.io:

  1. cargo install syncat

Configuration

By default, Syncat comes bundled with the configuration files as seen in syncat/config,
providing an unverified list of tree-sitter grammars, and some quickly cobbled together
highlighting for a handful of known file types.

If this basic configuration does not suffice, you may choose to configure Syncat yourself.
Do so by copying the syncat/config folder and modifying them. You may also be interested
in instead copying my personal configuration of Syncat, which can be found in the syncat-themes
repository.

In either case, copy (or create new) those files in the appropriate configuration directory, depending on
your operating system, and then continuing to the following sections. The appropriate directories are:

  • Linux: $HOME/.config/syncat/ (more accurately, $XDG_CONFIG_HOME/syncat)
  • Mac: $HOME/Library/Preferences/com.cameldridge.syncat/
  • Windows: Not officially supported

Stylesheets

The official stylesheets (admittedly somewhat incomplete) are available here.

Stylesheets are placed in the configuration directory, under a subdirectory style. You can
get the official themes as below, or just create this directory yourself.

  1. cd ~/.config/syncat # or `cd ~/Library/Preferences/com.cameldridge.syncat` for Mac users
  2. git clone https://github.com/foxfriends/syncat-themes style

For full documentation on how these stylesheet customizations work, see the README in
the syncat-themes repository.

Languages

As Syncat uses Tree-sitter for parsing, you must download and compile Tree-sitter parsers for
Syncat to use. Fortunately, the downloading and compiling can be handled by Syncat, given you
specify what to download.

The language map is a simple TOML file named languages.toml, located in the root of the
configuration folder. A good start might be to try mine.

Each entry in this file describes one language, and is a table of 4
or 5 keys. The example entry below would install a highlighter for Syncat stylesheets.

  1. [syncat-stylesheet] # The name here is arbitrary
  2. # The URL of the Git repository where the language is defined
  3. source = "https://github.com/foxfriends/syncat"
  4. # Optional: The path within the repository to the tree-sitter package.
  5. # Leave this out if the language is defined in the root of the repository.
  6. path = "tree-sitter-syncat-stylesheet"
  7. # The name of the directory to clone the `source` repository into. Typically
  8. # this is the same name as the source repository, but you must specify it anyway.
  9. library = "syncat"
  10. # The name of this language. This value should be the same as the value listed
  11. # in the `grammar.js` file from the repository.
  12. #
  13. # This name will also be the name of the stylesheet file used when highlighting
  14. # this language.
  15. name = "syncat_stylesheet"
  16. # A list of file extensions which should be parsed using this language.
  17. extensions = ["syncat"]

Once you have filled this file to your liking, the command syncat install will install all
of those languages. Running syncat install again later will update all languages, and install
any new ones.

Usage

  1. # Colours this file based on the extension
  2. syncat src/main.rs
  3. # Uses the shell expansion, colouring each file by its own extension
  4. syncat src/*.rs
  5. # Colours the file using a specific language
  6. syncat -l js src/package.json
  7. # Exports the default configuration into your system's configuration directory
  8. syncat init
  9. # Installs (or updates) all languages listed in the `languages.toml` file
  10. syncat install
  11. # Installs only a specific entry in the `languages.toml` file
  12. syncat install rust
  13. # Uninstalls a language. A few points to note:
  14. # * The language must still be listed in the `languages.toml` file.
  15. # * This does not remove the file from `languages.toml`, only deletes its installation.
  16. syncat remove rust
  17. # Show information about all languages listed in `languages.toml`
  18. syncat list