diff --git a/README.md b/README.md index 7facb88e1f84f336f82a7c3c8a330abe05bbe717..f6cfedf48b1492206fb6ffa6705085750c8b10ef 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ [Atom] + [GitKraken] ==================== -Open the current Atom project in [GitKraken](http://gitkraken.com). This can be activated from the Packages menu, command palette, tree view or the git branch indicator in the status bar. +Open the current [Atom] project in _[GitKraken]_. + +This can be activated from the _Packages_ menu, _command palette_, from the context menu on the root project folder in _tree view_, or the git _branch_ indicator in the _status bar_. + +An instance of _GitKraken_ will be spawned for each project by default, but can be configured in the package settings to only ever run a single instance of the application. Install ------- -`apm install gitkraken` or search "gitkraken" under packages within Atom. +`apm install gitkraken` or search "kraken" under packages within Atom. License ------- diff --git a/index.coffee b/index.coffee index 902cadb4b797660659c724432a1c0081446071c0..71b56a42177876f348306116cff6cbb69aeb27d1 100644 --- a/index.coffee +++ b/index.coffee @@ -1,27 +1,46 @@ -{exec} = require 'child_process' +{execSync, exec} = require 'child_process' +{writeFile, unlink} = require 'fs' +tmp = '/tmp/GitKraken.json' +id = 'com.axosoft.GitKraken' +selector = '[class^="status-bar"] .git-branch' + +#------------------------------------------------------------------------------- module.exports = #os: process.platform #timeout: #timeout: 10000 #killSignal: 'SIGKILL' - selector: '[class^="status-bar"] .git-branch' - subs: null activate: -> - SubAtom = require 'sub-atom' # {CompositeDisposable} = require 'atom' - @subs = new SubAtom #CompositeDisposable + SubAtom = require 'sub-atom' + @subs = new SubAtom #------------------------------------------------------------------------------- @subs.add atom.commands.add 'atom-workspace', 'gitkraken:release': => @open() atom.packages.onDidActivateInitialPackages => - @subs.add 'status-bar','click', @selector, @open + @subs.add 'status-bar','click', selector, @open +#------------------------------------------------------------------------------- open: -> {path} = atom.project.getDirectories()[0] - exec "open -b com.axosoft.GitKraken --args -p '#{path}'" #, @timeout + + if atom.config.get 'gitkraken.singleInstance' + exec "pkill GitKraken; sleep .1 && open -Fb #{id} --args -p '#{path}'" #, @timeout + else + projects = {} + try + projects = require tmp + execSync "ps #{projects[path]} | grep -q GitKraken && + open -b #{id} --args -p '#{path}'" + catch + pid = execSync "open -nb #{id} --args -p '#{path}' & echo $!" + projects[path] = (parseInt pid) + 1 + writeFile tmp, JSON.stringify projects #------------------------------------------------------------------------------- - deactivate: -> @subs.dispose() + deactivate: -> + @subs.dispose() + unlink tmp diff --git a/package.json b/package.json index 5a1315912c30ab5eaabd9ad8c8a577ae43ddda64..83073d2237a67e0f97e37b3aeae194f495b6943a 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,17 @@ "os": [ "darwin" ], + "dependencies": { + "sub-atom": "^1.1.0" + }, "engines": { "atom": "*" }, - "dependencies": { - "sub-atom": "^1.1.0" + "configSchema": { + "singleInstance": { + "description": "Limit to a single instance of the application, else spawn one per project.", + "type": "boolean", + "default": false + } } }