Skip to content

Instantly share code, notes, and snippets.

@brettz9
Created April 24, 2019 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettz9/45d6ffb9b71342a8a0ebcc5e1ec17f6e to your computer and use it in GitHub Desktop.
Save brettz9/45d6ffb9b71342a8a0ebcc5e1ec17f6e to your computer and use it in GitHub Desktop.
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