Skip to content

Instantly share code, notes, and snippets.

@aeberlin
Created December 2, 2015 15:09
Show Gist options
  • Save aeberlin/61998f5ef9c5eff76eb6 to your computer and use it in GitHub Desktop.
Save aeberlin/61998f5ef9c5eff76eb6 to your computer and use it in GitHub Desktop.
Atom Snippets
childProcess = require('child_process')
fs = require('fs')
path = require('path')
spawn = require('child_process').spawn
spawnPath = atom.project.getPaths()[0]
if not fs.statSync(spawnPath).isDirectory()
spawnPath = path.dirname(dir)
parseCharArray = (array) ->
array.reduce ((str, charIndex) ->
str += String.fromCharCode(charIndex)
), ''
buildShellCommand = (cmd) ->
initCommand = 'cd ' + spawnPath + ' && source ~/.zshrc'
commandArgs = '-c "' + initCommand + ' && ' + cmd + '"'
command = '/usr/local/bin/zsh ' + commandArgs
runShellCommand = (command) ->
full_command = buildShellCommand(command)
output = childProcess.execSync(full_command)
parseCharArray(output)
getEnvironmentVariable = (variable) ->
output = runShellCommand("env | grep '^" + variable + "'")
output.replace(variable + '=', '')
process.env.PATH = getEnvironmentVariable('PATH')
# Open developer tools
# editor = atom.workspace.getActiveTextEditor()
# editorElement = atom.views.getView(editor)
# atom.commands.dispatch(editorElement, 'window:toggle-dev-tools')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment