-
Notifications
You must be signed in to change notification settings - Fork 54
Drop Read Bash Data
Spawn a bash process then execute commands from vy.
The ibash plugin is a tool that permits to talk to the bash interpreter. It is possible to execute commands through bash and start some processes like a python interpreter, maxima etc.
pip install ibash
Then place the code in your ~/.vy/vyrc file.
# Used to talk to extern processes, playing with interpreters etc.
# Available: Unix/Linux
import vyapp.plugins.ibash
autoload(vyapp.plugins.ibash)
Note: You can place it in your extra plugins section.
Vy implements a key-command to display a text window which contains data that was written to sys.stdout.
The ibash plugin writes output from bash to sys.stdout. You can view the underlying bash process output by pressing:
<Alt-q>
The ibash plugin uses the scheme of output target. It is needed to set an AreaVi instance as output target to be able to read output from commands that are sent to the bash interpreter.
First of all, pick up an AreaVi instance that you want to read output from bash commands or processes. Once you have decided where to read output from commands, switch the focus to the AreaVi instance then press in NORMAL mode:
<Tab>
After setting a set of output targets then it is possible to send commands to the bash interpreter and read the commands output.
This is the most used feature of the ibash plugin, consider it was already set an output target and you want to send the command below to the bash interpreter:
ls -la
How would you proceed? you would place the cursor over that line then press:
<Shift-Return>
in NORMAL mode or in INSERT mode. When the keycommand above happens in NORMAL mode, the code line over the cursor is sent to the bash interpreter and the cursor is placed one line down. When it happens in INSERT mode, the code line is sent to the bash and a newline is inserted down the cursor position. It is means that either in NORMAL mode or in INSERT mode it is possible to drop code to the bash interpreter; Such a behavior is useful when dealing with e-scripts or when using vy as a terminal-like.
The key-command below is used to input some code and drop it to the bash process.
<F9>
Sometimes it is interesting to drop entire regions of selected code. For such just select the data then press:
<Control-F9>
It is possible to start processes that run on top of the bash process, in such a situation it will be useful to send unix signals to the child processes like SIGINT. For such, switch to NORMAL mode then press:
<Control-C>
Sometimes it is interesting to run commands as root, for such it is needed to have set the environment variable SUDO_ASKPASS.
Check out if it is already set with:
echo $SUDO_ASKPASS
If it is not set then it is needed to install some askpass program. One available option is x11-ssh-askpass.
Issue the command below to have the SUDO_ASKPASS permanently set.
echo 'export SUDO_ASKPASS=path/x11-ssh-askpass' >> ~/.bashrc
The path is the folder where askpass script is located. It is generally located in /usr/bin.
Now it is possible to run commands with:
sudo command
The askpass program will show up asking for the password then the command will be run as root.
It is useful to run a bash process as root sometimes, for such, drop the command below to the bash interpreter:
sudo bash -i
It will run a bash process with different permissions on top of the bash process.
Some processes like the python interpreter when started through the ibash plugin would have the output correctly outputed over the AreaVi instance that was set as target by passing some special arguments. An example follows:
tee >(python -i -u)
When the python interpreter is started through tee and with -i and -u it adjusts the correct scheme of buffering. The -i argument means that the python interpreter would run in interactive mode.
Sometimes it is needed to restart the bash process, for such, switch to NORMAL mode then process
<Alt-semicolon>
Execute the command:
lsh()
That will restart the process.