Execute CoffeeScript, JavaScript or Shell code from the Atom editor and replace the code with the result
eval-and-replace
Execute CoffeeScript, JavaScript or Shell code from the Atom editor and replace the code with the result.
Install
apm install eval-and-replace
Commands
Commands | Description | Default keybinding |
---|---|---|
eval-and-replace:coffee |
Executes selected CoffeeScript code | ctrl-shift-e ctrl-shift-c or ctrl-k ctrl-e |
eval-and-replace:js |
Executes selected JavaScript code | ctrl-shift-e ctrl-shift-j |
eval-and-replace:shell |
Executes selected Shell code | ctrl-shift-e ctrl-shift-s |
Be careful with eval-and-replace:shell
; nobody will prevent you from executing rm -rf /
!
Shell environment variables
When executing shell code with eval-and-replace:shell
you have access to these variables:
FILE_PATH
: path to of the currently opened fileFILE_NAME
: name of the currently opened filePROJECT
: path to the Atom project
CoffeeScript / JS Context
CoffeeScript / JS code is executed in its own context, this means you can only use ECMAScript
functions (i.e. norequire
). But the same context is used for all selections, so you can reuse
variables. Additionally you have access to these functions and variables:
i
,j
,n
,x
,y
,z
: initialized with0
filePath
: path of the opened filefileName
: name of the opened fileproject
: path of the current Atom projectPI
: alias forMath.PI
E
: alias forMath.E
random()
: alias forMath.random()
pow()
: alias forMath.pow()
sqrt()
: alias forMath.sqrt()
abs()
: alias forMath.abs()
sin()
: alias forMath.sin()
cos()
: alias forMath.cos()
tan()
: alias forMath.tan()
floor()
: alias forMath.floor()
ceil()
: alias forMath.ceil()
round()
: alias forMath.round()
License
This project is licensed under the terms of the MIT license. A copy of the license can be found in the root directory of the project in the file LICENSE.md.