Created
April 24, 2019 06:54
-
-
Save brettz9/45d6ffb9b71342a8a0ebcc5e1ec17f6e to your computer and use it in GitHub Desktop.
open-in-sourcetree mod; offered in https://github.com/cliffrowley/atom-open-in-sourcetree/issues/11#issuecomment-485305081
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require('fs') | |
path = require('path') | |
{CompositeDisposable} = require 'atom' | |
ProjectPathListView = require './project-path-list-view' | |
getActiveFilePath = () -> | |
document.querySelector('.tree-view .selected')?.getPath?() || | |
atom.workspace.getActivePaneItem()?.buffer?.file?.path | |
findGitRoot = (dirpath, origpath = dirpath) -> | |
if fs.existsSync(path.join(dirpath, '.git')) | |
return dirpath | |
parentDirpath = path.dirname(dirpath) | |
if (parentDirpath == dirpath or parentDirpath == '.') | |
return origpath | |
return findGitRoot(parentDirpath, origpath) | |
module.exports = | |
subscriptions: null | |
activate: (state) -> | |
@subscriptions = new CompositeDisposable | |
@subscriptions.add atom.commands.add 'atom-workspace', | |
'open-in-sourcetree:open', (e) => @openApp(e) | |
deactivate: -> | |
@subscriptions.destroy() | |
# openApp: -> | |
openApp: (e) -> | |
e.stopImmediatePropagation() | |
filepath = @getPath?() || @getModel?().getPath?() || getActiveFilePath() | |
try | |
isFile = fs.lstatSync(fs.realpathSync(filepath)).isFile() | |
catch | |
isFile = true | |
if isFile | |
dirpath = path.dirname(filepath) | |
else | |
dirpath = filepath | |
return if not dirpath | |
gitroot = findGitRoot(dirpath) | |
require('./open-sourcetree')(gitroot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment