Skip to content

Instantly share code, notes, and snippets.

@chrispahm
Last active February 19, 2018 09:35
Show Gist options
  • Save chrispahm/02cd6e1880d53a6f1446c8beceeb773d to your computer and use it in GitHub Desktop.
Save chrispahm/02cd6e1880d53a6f1446c8beceeb773d to your computer and use it in GitHub Desktop.
Init script to run GAMS file through Atom command palette
# GAMS run init script
#
# This atom init script will execute the current GAMS file
# and subsequently open the according listing (.lst) file
# An example hack to log to the console when each text editor is saved.
# You would need to have linter-gams installed and adjust the below filepaths
# to your needs
atom.commands.add 'atom-text-editor', 'gams:run', =>
return unless editor = atom.workspace.getActiveTextEditor()
path = require('path')
fs = require('fs')
shell = require('C:\\Users\\*\\.atom\\packages\\linter-gams\\node_modules\\shelljs')
findUp = require('C:\\Users\\*\\.atom\\packages\\linter-gams\\node_modules\\find-up')
shell.config.execPath = shell.which('node')
filePath = editor.getPath()
directory = editor.getDirectoryPath()
gamsExe = atom.config.get('linter-gams.Gams Executable')
scratchdir = atom.config.get('linter-gams.Scratch directory')
findUp('exp_starter.gms', directory).then (expStarter) ->
if expStarter
filePath = expStarter
directory = path.dirname(expStarter) + path.sep
ggigParams = '--scen=incgen\\\\runInc'
listingPath = path.parse(filePath)
listingPath.ext = '.lst'
listingPath.base = ''
listingPath = path.format(listingPath)
gamsParams = gamsExe + ' ' + filePath + ' lo=0 -scrdir="' + scratchdir + '" ' + ggigParams
shell.cd directory
shell.exec gamsParams, (code, stdout, stderr) ->
if stderr
console.log(stderr)
atom.open({'pathsToOpen': [listingPath], 'newWindow': false})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment