run-in-terminal

Run some commands in terminal, or just run terminal

pohmelie

38,377

13

1.0.1

MIT

GitHub

run-in-terminal package

Atom package for executing your current file directly in terminal, or just open the terminal with a specified directory.

Why?

Some packages can run terminal «here», some can run scripts not in terminal, but tabs/views/etc. I prefer terminal, so this one can run terminal «here» with any arguments and run scripts or any kind of shell «one-liners».

Features

What's new (changelog)

1.0.1 - Add atom v1.19 support

Options

Field Type Description Default value Example value
Launch file in terminal command string command to start the terminal and run a program based on filetype or shebang operating system dependent konsole --noclose --workdir "{working_directory}" -e {launcher} "{file_dir}"
Save file before run terminal boolean Saves the open file before the terminal is started true -
Launch directory in terminal command string command to start the terminal and open a directory operating system dependent konsole --noclose --workdir "{working_directory}"
List of programs by extension string comma separated pairs: extension-program your-programs .py python3, .lua lua
Use exec cwd boolean child_process.exec cwd parameter true -
Use shebang boolean use shebang if available true -

Interpolation parameters

Parameter Description
{file_path} path to current file
{launcher} selected program from list or shebang
{args} additional (optional) arguments
{working_directory} path to current working directory
{project_directory} path to project's root directory
{git_directory} path to nearest git root directory

How it works

In deep, run-in-terminal uses the node.js child_process.exec function, so exec have cwd (current working directory) argument. But it doesn't work for all terminals. Some of them need the launch «working directory» argument. That's why run-in-terminal have string interpolation of arguments. What does string interpolation mean? run-in-terminal builds full command at first step and replace predefined substrings with parameters at second. For values from «example value» column above we can have such scenario:

Current opened file in Atom: /path/to/somedir/foo.py, which has #!/usr/bin/python3 as shebang.

start-terminal-here-and-run -> konsole --noclose --workdir "{working_directory}" -e /usr/bin/python3 "{file_path}"

this will be interpolated to:

start-terminal-here-and-run -> konsole --noclose --workdir "/path/to/somedir" -e /usr/bin/python3 "/path/to/somedir/foo.py"

If run-in-terminal can't determine launcher or file_path (file not saved and has no name) it will do start-terminal-here.

Thanks to:

bobrocke, clintwood, LeoVerto, marales, djengineerllc, LevPasha, Kee-Wang, jnelissen, maxbrunsfeld.