Skip to content

Commit

Permalink
Add config syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
vovkkk committed Jun 18, 2015
1 parent 4fc3c0c commit 0e38a88
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 10 deletions.
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
The MIT License (MIT)

Copyright (c) 2008 Tim Harper
Copyright (c) 2015 Adam Bullmer
Copyright (c) 2015 Vova Kolobok

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
# Sublime Text git Commit Message Syntax
# Git Syntaxes
Syntax Highlighting for SublimeText

Syntax Highlighting for SublimeText / Text Mate
![](https://leto21h.storage.yandex.net/rdisk/ba2874260630e3a93d2f9e2f85d90842af2bc4de368e9fb5b7aabf95eda95c9f/inf/f9LX--q8AvzANsoPK90KCkq6HKdoWKAz5oCEO2sJcBokNtdo2f4iuKc3PsG1PsPeYFediDpOOiaC5nZiGRUlMA==?uid=0&filename=2015-06-18%2014-43-50%20C%20%20Users%20vova%20.gitconfig%20-%20Sublime%20Text%202.png&disposition=inline&hash=&limit=0&content_type=image%2Fpng&tknv=v2&rtoken=b3a47b6091b952b1ec8f1bb701abb096&force_default=no)

## How to make commits with Sublime Text
For the following options, you'll need to use the appropriate command from below:
**Note** for Windows, you must have `Build 3065` or lated to have command line support
# Features
* Highlight all Git files (gitconfig, gitattributes, commit message, interactive rebase todo)
* Toggle comments in all files above with default keystroke whatever it is (usually <kbd>ctrl+/</kbd>)
* Many scopes, e.g. you can set separate colour for every command in rebase file (i.e. `pick`, `fixup`, etc.)

- Mac / Linux: `subl -w`
- Windows: `subl.exe -w`
## How to use ST as editor for Git
**Note** for Windows, you must have `Build 3065` or lated to have command line support, Or just add folder into `PATH` and call `sublime_text` instead of `subl`

- Mac / Linux: `subl -n -w`
- Windows: `subl.exe -n -w`

### Preferred Method: Edit `.bashrc`
This will allow for more editing options than just the git commit, like editing diffs. This also leaves flexibility as it can be easily overridden, by the `.gitconfig` for example.
Add the following to your `.bashrc`:
On Mac and Linux:

```
export EDITOR="subl -w"
export EDITOR="subl -n -w"
```

### Alternate Method: Ammend your `.gitconfig`
You can run the following command to let git update your `.gitconfig`

```
git config --global core.editor 'subl -w'
git config --global core.editor 'subl -n -w'
```

Or add the following line manually to your `.gitconfig`
```
[core]
editor = 'subl -w'
editor = 'subl -n -w'
```

You also can hide menu (as on screenshot above) and tabs:

editor = "sublime_text -n -w --command toggle_menu --command toggle_tabs"


## Credits
* Base for Config definitions is borrowed from <https://github.com/textmate/git.tmbundle>
* Commit definitions are borrowed from <https://github.com/adambullmer/sublime_git_commit_syntax>

<hr>

All sources under [MIT](LICENSE)
77 changes: 77 additions & 0 deletions config.YAML-tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Git Config
scopeName: text.git.config
fileTypes: [.git/config, git/config, .gitconfig, etc/gitconfig, .gitmodules, .gitattributes]
uuid: 8c0801ac-9327-4672-b410-323e690f84a5

patterns:
- include: '#section'

- include: '#comment'

- include: '#attributes'

repository:
comment:
match: ((#).*$\n?)|((;).*$\n?)
captures:
'1': {name: comment.line.number-sign.git-config}
'2': {name: punctuation.definition.comment.git-config}
'3': {name: comment.line.semi-colon.git-config}
'4': {name: punctuation.definition.comment.git-config}

boolean:
name: constant.language.boolean.git-config
match: \b(?i:yes|no|0|1|true|false)\b

section:
name: meta.section.git-config
begin: \[\s*([\w_-]+)(?:\s+((")(?:[^"\\]|\\["\\])*("))|\.([\w_-]+))?\s*\]
end: (?=\[)
captures:
'1': {name: entity.name.section.git-config}
'2': {name: string.name.section.subsection.git-config}
'3': {name: punctuation.definition.section.subsection.begin.git-config}
'4': {name: punctuation.definition.section.subsection.end.git-config}
'5': {name: entity.name.section.subsection.git-config}
patterns:
- include: '#value_pair'
- include: '#comment'

string:
name: string.quoted.double.git-config
begin: '"'
beginCaptures:
'0': {name: punctuation.definition.string.begin.git-config}
end: '"'
endCaptures:
'0': {name: punctuation.definition.string.end.git-config}
patterns:
- name: constant.character.escape.git-config
match: \\[ntb"\\]
- name: invalid.illegal.unknown-escape.git-config
match: \\.

value_pair:
name: meta.value-pair.section-item.git-config
begin: ([-\w]+)\s*(=)\s*(?!$)
end: $|(?=[#;])
captures:
'1': {name: key.support.constant.git-config}
'2': {name: keyword.operator.assignment.git-config}
patterns:
- name: constant.character.escape.git-config
match: \\[ntb"\\]
- include: '#boolean'
- include: '#string'
- include: '#comment'
- name: string.value.git-config
match: '[^\n]+'

attributes:
name: meta.attributes.git-config
begin: ^([\*\S]+)(?=(?!=)\s*(?!=)(\S+)($|(?=[#;])))
end: $|(?=[#;])
captures:
'1': {name: keyword.attributes-pattern.git-config}
228 changes: 228 additions & 0 deletions config.tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>.git/config</string>
<string>git/config</string>
<string>.gitconfig</string>
<string>etc/gitconfig</string>
<string>.gitmodules</string>
<string>.gitattributes</string>
</array>
<key>name</key>
<string>Git Config</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#section</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>include</key>
<string>#attributes</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>attributes</key>
<dict>
<key>begin</key>
<string>^([\*\S]+)(?=(?!=)\s*(?!=)(\S+)($|(?=[#;])))</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.attributes-pattern.git-config</string>
</dict>
</dict>
<key>end</key>
<string>$|(?=[#;])</string>
<key>name</key>
<string>meta.attributes.git-config</string>
</dict>
<key>boolean</key>
<dict>
<key>match</key>
<string>\b(?i:yes|no|0|1|true|false)\b</string>
<key>name</key>
<string>constant.language.boolean.git-config</string>
</dict>
<key>comment</key>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>comment.line.number-sign.git-config</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.git-config</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>comment.line.semi-colon.git-config</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.git-config</string>
</dict>
</dict>
<key>match</key>
<string>((#).*$\n?)|((;).*$\n?)</string>
</dict>
<key>section</key>
<dict>
<key>begin</key>
<string>\[\s*([\w_-]+)(?:\s+((")(?:[^"\\]|\\["\\])*("))|\.([\w_-]+))?\s*\]</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.section.git-config</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>string.name.section.subsection.git-config</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.definition.section.subsection.begin.git-config</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.definition.section.subsection.end.git-config</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>entity.name.section.subsection.git-config</string>
</dict>
</dict>
<key>end</key>
<string>(?=\[)</string>
<key>name</key>
<string>meta.section.git-config</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#value_pair</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
</array>
</dict>
<key>string</key>
<dict>
<key>begin</key>
<string>"</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.git-config</string>
</dict>
</dict>
<key>end</key>
<string>"</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.end.git-config</string>
</dict>
</dict>
<key>name</key>
<string>string.quoted.double.git-config</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\\[ntb"\\]</string>
<key>name</key>
<string>constant.character.escape.git-config</string>
</dict>
<dict>
<key>match</key>
<string>\\.</string>
<key>name</key>
<string>invalid.illegal.unknown-escape.git-config</string>
</dict>
</array>
</dict>
<key>value_pair</key>
<dict>
<key>begin</key>
<string>([-\w]+)\s*(=)\s*(?!$)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>key.support.constant.git-config</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.assignment.git-config</string>
</dict>
</dict>
<key>end</key>
<string>$|(?=[#;])</string>
<key>name</key>
<string>meta.value-pair.section-item.git-config</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\\[ntb"\\]</string>
<key>name</key>
<string>constant.character.escape.git-config</string>
</dict>
<dict>
<key>include</key>
<string>#boolean</string>
</dict>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>match</key>
<string>[^\n]+</string>
<key>name</key>
<string>string.value.git-config</string>
</dict>
</array>
</dict>
</dict>
<key>scopeName</key>
<string>text.git.config</string>
<key>uuid</key>
<string>8c0801ac-9327-4672-b410-323e690f84a5</string>
</dict>
</plist>

0 comments on commit 0e38a88

Please sign in to comment.