Skip to content

Instantly share code, notes, and snippets.

@kholodilov
Last active August 29, 2015 14:04
Show Gist options
  • Save kholodilov/ca99fddf93a54851e193 to your computer and use it in GitHub Desktop.
Save kholodilov/ca99fddf93a54851e193 to your computer and use it in GitHub Desktop.
Sublimerge custom comparisons
{
"custom_comparisons_user": [
/************************************* GIT *************************************/
/*
* Custom Git comparison. Displays quick panel with modified files and allows to compare working copy to HEAD to see uncommited changes.
*/
{
"name": "Show All Uncommited Changes...", //comparison name
"requires": "git", //What does it require. Currently 'git', 'svn' 'hg' or null (if doesn't require any of VCS)
"steps": [ //comparison is divided into steps. You can define more steps when needed.
{
"quick_panel": { //Displays a Quick Panel with given attributes
"name": "modified_file", //Quick Panel name. Used to populate a variable 'modified_file' with seleted item value
"source": { //Data source
"execute": { //Execute a shell command
"command": "{git} status --porcelain",
"directory": "{sublimerge:repo_root}" //Set a command working directory
},
"item": { //Single item extractor
"regexp": "^\\s*[^\\s]+\\s+\"?(.*?)\"?$", //Regular expression to parse each output line
"caption": ["@0"], //Caption is an array. Each item is another line. @n - placeholder for regular expression match
"value": "@1" //Value must be a single string
},
"empty_message": "There are no uncommited changes" //Message to be displayed when data source is empty (no items created)
}
}
},
{ //define variables
"define": {
"right_file": "{sublimerge:repo_root}/{modified_file}",
"left_file": "{sublimerge:temp_dir}/{modified_file|basename}@HEAD"
}
},
{
"compare": { //Executes file comparison
"execute": { //Execute a shell command. Please note about 'modified_file' variable which we defined in previous step
"command": "{git} show HEAD:\"./{modified_file}\" > \"{left_file}\"",
"directory": "{sublimerge:repo_root}"
},
"left": { //Left file
"file": "{left_file}", //Full file path
"temporary": true //This file is generated by previous shell command, so remove it automatically after use
},
"right": {
"file": "{right_file}",
"temporary": false //This file is our working copy, so is not temporary
}
}
}
]
},
{
"name": "Show Stashed Changes...",
"requires": "git",
"steps": [
{
"quick_panel": {
"name": "stash",
"source": {
"execute": {
"command": "{git} stash list",
"directory": "{sublimerge:repo_root}"
},
"item": {
"regexp": "^(stash@\\{\\d+\\}):.*$",
"caption": ["@0"],
"value": "@1"
},
"empty_message": "There are no stashed changes"
}
}
},
{
"quick_panel": {
"name": "file",
"source": {
"execute": {
"command": "{git} stash show --name-status {stash}",
"directory": "{sublimerge:repo_root}"
},
"item": {
"regexp": "^[^\\s]+\\s+(.+)$",
"caption": ["@0"],
"value": "@1"
}
}
}
},
{
"define": {
"right_file": "{sublimerge:temp_dir}/{file|basename}_modified{file|ext}",
"left_file": "{sublimerge:temp_dir}/{file|basename}_original{file|ext}"
}
},
{
"capture": {
"execute": {
"command": "{git} show {stash}:\"./{file}\" > \"{right_file}\"",
"directory": "{sublimerge:repo_root}"
}
}
},
{
"compare": {
"execute": {
"command": "{git} show {stash}^1:\"./{file}\" > \"{left_file}\"",
"directory": "{sublimerge:repo_root}"
},
"left": {
"file": "{left_file}",
"title": "{file|basename}@original",
"temporary": true
},
"right": {
"file": "{right_file}",
"title": "{file|basename}@modified",
"temporary": true
}
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment