Skip to content
Iury O. G. Figueiredo edited this page Dec 1, 2019 · 1 revision

Spawn processs to send/read data from vy.

It is very useful for running interpreters from vy, one can spawn a programming language interpreter then send/read data from. It allows one to quickly test/debug code.

The plugin also can be used to access remote machines through ssh.

Install

In order to get the spawn plugin working it is necessary to import it first.

The spawn plugin comes with two modules, if you are on unix platforms you can just uncomment the unix_platform module otherwise just uncomment the cross platform module.

Open your ~/.vy/vyrc file then look up for the following lines of code in your extra command plugins section:

# Spawning processes.
# import vyapp.plugins.spawn.unix_platform

# Spawning processes cross_platform.
# import vyapp.plugins.spawn.cross_platform

Usage

The spawn plugin implements some commands, these commands are merely python functions that can be executed from vy.

The most often used command that spawn implements it is the one to instantiate a bash instance to send/read data from.

In order to execute such a command just press:

<Alt-semicolon>

In NORMAL mode. It will display an input text widget where you can drop python code to be executed in vy.

Note: When such an input text widget is showing up then it is meant to be in INPUT mode.

Insert the following piece of code below:

hbash()

After pressing return/enter key the function will be executed and a new AreaVi instance will be opened. The h letter in hbash means it will add a new pane at the right of your current opened pane. You'll be able to read output from the bash process in that new pane.

It is also important to have in mind that you'll be able to send data to the bash process only from the pane that had focus before you executing the hbash function.

Switch the focus to the origin pane (the one that had focus before the new pane being opened) then try typing some commands like:

ls -la
echo 'hello world'

Place the cursor over the line that you want to send to the bash interpreter then press:

<F1>

In NORMAL/INSERT mode. The line under the cursor will be sent to the bash interpreter then it will process the data and send back the result to the output pane.

Notice that you can spawn new processes from the bash process by just dropping commands to it.

If you wanted to send/read data to a python interpreter from the bash process then you could just do:

tee >(stdbuf -o 0 python -i)

The above command would spawn the python interpreter from the bash process then you would be able to talk to the interpreter.

The tee/stdbuf commands are merely a tricky to make it work properly because it is not a terminal at all.

Note: You can execute hpy() or vpy() that are also implemented in spawn. If you play with ruby there is also vrb() and hrb() functions.

The spawn implements two important commands, these are hspawn and vspawn. These commands can be used to instantiate any kind of process.

There are examples below of the usage:

# Spawn a python interpreter and adds a new pane at the right of the current opened pane.
hspawn('bash -c "tee -i >(stdbuf -o 0 python -i -u)"')

# Spawn a bash interpreter and adds a new pane below the current opened pane.
vspawn('bash -i')

Notice that once a pane is instantiated and a process is running it is also possible to send signals to the process by pressing:

Send SIGINT:

<Control-c>

Send SIGQUIT:

<Control-backslash>

In the origin pane, it is the one that is used to control the process.

Access Remote Machines

You can use the command below after launching a bash process to access some remote machine from vy.

tee -i >(stdbuf -o 0 ssh user@addr.com 'bash -i')

You can also define shortcut functions in your ~/.vy/vyrc file to spawn all kind of processes that you often use.

For such you could do:

from vyapp.plugins.spawn.unix_platform HSpawn, VSpawn

def spawn_some_process():
    HSpawn('command to spawn')

def some_other_process():
    VSpawn('command to spawn')

Place that in your ~/.vy/vyrc file, you can put it after spawn imports. The command will be available to be executed from vy.

Clone this wiki locally