├── Git
├── Branch.sketchplugin
├── Checkout.sketchplugin
├── Commit.sketchplugin
├── Init.sketchplugin
└── Open terminal.sketchplugin
├── LICENSE
├── README.md
└── library
└── common.js
/Git/Branch.sketchplugin:
--------------------------------------------------------------------------------
1 | // Branch & checkout (cmd alt ctrl b)
2 |
3 | #import 'library/common.js'
4 |
5 | var currentFolder = com.bomberstudios.getFileFolder()
6 |
7 | var branchName = [doc askForUserInput:'Branch name' initialValue:''];
8 |
9 | if (branchName != null){
10 |
11 | var terminal = SBApplication.application_("Terminal");
12 |
13 | terminal.doScript_in_("cd " + currentFolder + "; cd ../; git checkout -b " + branchName + "; exit",nil);
14 |
15 | }
--------------------------------------------------------------------------------
/Git/Checkout.sketchplugin:
--------------------------------------------------------------------------------
1 | // Checkout (cmd alt ctrl c)
2 |
3 | #import 'library/common.js'
4 |
5 | var currentFolder = com.bomberstudios.getFileFolder()
6 |
7 | var branchName = [doc askForUserInput:'Checkout branch' initialValue:''];
8 |
9 | if (branchName != null){
10 |
11 | var terminal = SBApplication.application_("Terminal");
12 |
13 | terminal.doScript_in_("cd " + currentFolder + "; cd../; git checkout " + branchName+ "; exit",nil);
14 |
15 | }
--------------------------------------------------------------------------------
/Git/Commit.sketchplugin:
--------------------------------------------------------------------------------
1 | // Commits to git (cmd alt y)
2 |
3 | #import 'library/common.js'
4 |
5 | var currentFolder = com.bomberstudios.getFileFolder()
6 |
7 | var commitMsg = [doc askForUserInput:'Commit message' initialValue:''];
8 |
9 | if (commitMsg != null){
10 |
11 | var terminal = SBApplication.application_("Terminal");
12 |
13 | terminal.doScript_in_("cd " + currentFolder + "; cd ../; sleep 2; git commit -m '" + commitMsg + "' -a"+ "; exit",nil);
14 |
15 | }
--------------------------------------------------------------------------------
/Git/Init.sketchplugin:
--------------------------------------------------------------------------------
1 | // Init empty git repo
2 |
3 | #import 'library/common.js'
4 |
5 | var currentFolder = com.bomberstudios.getFileFolder()
6 |
7 | var terminal = SBApplication.application_("Terminal");
8 |
9 | terminal.doScript_in_("cd " + currentFolder + "; cd ../; git init ;",nil);
10 |
11 | terminal.activate();
--------------------------------------------------------------------------------
/Git/Open terminal.sketchplugin:
--------------------------------------------------------------------------------
1 | // Opens terminal in working directory (cmd alt ctrl t)
2 |
3 | #import 'library/common.js'
4 |
5 | var currentFolder = com.bomberstudios.getFileFolder()
6 |
7 | var terminal = SBApplication.application_("Terminal");
8 |
9 | terminal.doScript_in_("cd " + currentFolder + "; cd ../;",nil);
10 |
11 | terminal.activate();
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
2 |
3 | SketchGit
4 | =========
5 |
6 | #### A simple Git client built right into Sketch.
7 |
8 | **Important: For this plugin to work you must be using the non App Store version of Sketch so that its environment is not sandboxed.**
9 |
10 | ---
11 |
12 | ##### Installation
13 | * Download this repo as a zip
14 | * Enable scripting within Sketch (in preferences)
15 | * Place the extracted files/folders into your Sketch plugin directory
~/library/application support/sketch/plugins16 | 17 | #### Default key bindings 18 | 19 | Action | Shortcut 20 | :-----------------------------|:---------------------------------------------------------------- 21 | Commit | cmd + alt + y 22 | Checkout | ctrl + alt + cmd + c 23 | Branch | ctrl + alt + cmd + b 24 | Open terminal in working dir | ctrl + alt + cmd + t 25 | 26 | --- 27 | 28 | Thanks to Bomberstudios for a lot of example code and Pete Hamilton for his help. 29 | -------------------------------------------------------------------------------- /library/common.js: -------------------------------------------------------------------------------- 1 | // Common library of things 2 | 3 | var com = com || {}; 4 | 5 | com.bomberstudios = { 6 | alert: function(msg,title){ 7 | if (title == undefined) { title = "Whoops" }; 8 | var app = [JSTalk application:"Sketch"]; 9 | [app displayDialog:msg withTitle:title]; 10 | }, 11 | create_folder: function(path) { 12 | var file_manager = [NSFileManager defaultManager]; 13 | [file_manager createDirectoryAtPath:path withIntermediateDirectories:true attributes:nil error:nil]; 14 | }, 15 | getFileFolder: function(){ 16 | var pages = [doc pages], 17 | file_url = [doc fileURL], 18 | file_path = [file_url path], 19 | file_folder = file_path 20 | return file_folder; 21 | }, 22 | getExportPath: function(){ 23 | var file_folder = com.bomberstudios.getFileFolder(), 24 | export_folder = file_folder + "/" + ([doc displayName]).split('.sketch')[0] + "_export/"; 25 | return export_folder; 26 | }, 27 | export_all_slices: function(format,path){ 28 | if (path == undefined) { 29 | path = com.bomberstudios.getExportPath(); 30 | } 31 | [doc pages].each(function(page){ 32 | [doc setCurrentPage:page]; 33 | 34 | var layers = [[doc currentPage] allSlices]; 35 | layers.each(function(slice){ 36 | [doc saveArtboardOrSlice:slice toFile:path + [slice name] + "." + format]; 37 | }); 38 | }); 39 | }, 40 | export_all_artboards: function(format,path){ 41 | if (path == undefined) { 42 | path = com.bomberstudios.getExportPath(); 43 | } 44 | [doc pages].each(function(page){ 45 | [doc setCurrentPage:page]; 46 | 47 | var layers = [[doc currentPage] artboards]; 48 | layers.each(function(artboard){ 49 | [doc saveArtboardOrSlice:artboard toFile:path + [artboard name] + "." + format]; 50 | }); 51 | }); 52 | }, 53 | padNumber: function(num){ 54 | num = num.toString(); 55 | if (num.length < 2) { 56 | num = "0" + num; 57 | }; 58 | return num; 59 | }, 60 | isodate: function(){ 61 | var now = new Date(); 62 | var year = now.getFullYear(); 63 | var month = com.bomberstudios.padNumber((now.getMonth() + 1)); 64 | var day = com.bomberstudios.padNumber(now.getDate()); 65 | var hour = com.bomberstudios.padNumber(now.getHours()); 66 | var minute = com.bomberstudios.padNumber(now.getMinutes()); 67 | return year + month + day + hour + minute; 68 | }, 69 | selection_count_is: function(min){ 70 | var min = min || 1, 71 | title = "Whoops"; 72 | if ([selection length] < min) { 73 | if([selection length] === 0) { 74 | title = "Nihilism alert" 75 | } 76 | alert("You need to select at least " + number_to_words(min) + " object" + (min === 1 ? '' : 's') + ", but you selected " + number_to_words([selection length]) + ".", title) 77 | return false; 78 | } else { 79 | return true; 80 | } 81 | }, 82 | number_to_words: function(num){ 83 | switch (num){ 84 | case 0: 85 | return 'none'; 86 | case 1: 87 | return 'one'; 88 | case 2: 89 | return 'two'; 90 | case 3: 91 | return 'three'; 92 | case 4: 93 | return 'four'; 94 | default: 95 | return num; 96 | } 97 | } 98 | }; 99 | 100 | Array.prototype.each = function(callback){ 101 | var count = 0; 102 | for (var i = 0; i < this.length(); i++){ 103 | var el = this[i]; 104 | callback.call(this,el,count); 105 | count++; 106 | } 107 | } 108 | 109 | Number.prototype.times = function(callback){ 110 | for (var s = this - 1; s >= 0; s--){ 111 | callback.call(this,s); 112 | }; 113 | } 114 | 115 | // Aliases 116 | alert = com.bomberstudios.alert 117 | number_to_words = com.bomberstudios.number_to_words 118 | selection_count_is = com.bomberstudios.selection_count_is --------------------------------------------------------------------------------