Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tysonandre/git-diff-syntax-highlight
git pager with syntax highlighting for diffs
https://github.com/tysonandre/git-diff-syntax-highlight
coderay color diff git git-diff ruby syntax-highlighting
Last synced: 14 days ago
JSON representation
git pager with syntax highlighting for diffs
- Host: GitHub
- URL: https://github.com/tysonandre/git-diff-syntax-highlight
- Owner: TysonAndre
- Created: 2020-02-09T15:58:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-09T18:24:23.000Z (almost 5 years ago)
- Last Synced: 2024-11-26T01:42:13.158Z (2 months ago)
- Topics: coderay, color, diff, git, git-diff, ruby, syntax-highlighting
- Language: Ruby
- Size: 106 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
git-diff-syntax-highlight
=========================Utilities to include syntax highlighting in the terminal, for git diffs and other commands.
This is a patched version of https://gist.github.com/skanev/0eeb943e3111a1df55fd
which fixes rare bugs I've encountered in that gist.
It also patches the syntax highlighting to match my personal preferences.This is configured to highlight ruby, C, C++, Clojure, CSS, ERB, Go, Java, JavaScript, JSON, PHP, Lua, Python, SASS, SCSS, SQL, XML, and YAML files.
![Demo](images/git_diff.png)
Scripts
-------- `git-diff-syntax-highlight.rb` - A syntax highlighter for git diffs.
- `colorless` - Like `less filename.extension`, but with syntax highlighting.
- `coderay_colorize` - Like `cat filename.extension`, but with syntax highlighting.Known Issues
------------- RVM can break this when switching to a different ruby version.
- Highlighting using background colors is poorly handled and result in code that are hard to read.
This may be fixable by ensuring some minimum contrast when generating color codes.
- At the time of writing, there is no support for Markdown in `coderay`, which this depends onDependencies
------------This requires that `term-ansicolor` and `coderay` be installed, and that ruby be set up.
```
gem install --user term-ansicolor coderay
```Colorizing Git diffs
--------------------Add the following to .gitconfig.
The `simple-log`, `simple-diff`, and `simple-show` aliases are provided because syntax highlighting is slow for projects with long histories,
and because changes in rvm paths can break diffs completely.```
[core]
pager = /path/to/git-diff-syntax-highlight.rb --highlight | less -F -X
# The -F -X is optional.
# In addition to --highlight, --coderay-colors may be used to change the syntax highlighting.
```The `git-simple-*` scripts are found in [./bin](./bin).
After adding those to a directory the shell's `$PATH`, you probably also want to create aliases for the original diffs.```
[alias]
simple-log = !git-simple-log
simple-diff = !git-simple-diff
simple-show = !git-simple-show
```Similar Projects
----------------https://github.com/dandavison/delta is a similar project written in Rust, with more themes and configuration options.
https://github.com/sharkdp/bat is similar to the `colorless` script this provides, with more themes.
https://github.com/trishume/syntect is the library those Rust projects use. I'd expect it to have faster startup times and better performance on long diffs.