Run command-line demos from a script.
Project description
Description
pygsc
is a Python script that lets you run shell scripts interactively. This is useful for doing live command line demos.
pygsc
is a (another) rewrite of gsc
. There is a long history with the creation of this tool for a computer class I teach. You can read it
there.
Features
- Run shell scripts "interactively".
- Characters are sent to the shell, on at a time, each time you press a key.
- When the end of a line has been reached, press enter to go to the next line.
- Script any command line application: vim, gnuplot, ssh, etc.
- Modal : switch between insert mode, command mode, and pass through mode (see below).
- If you run into an error in your script (a typo, or some file that is missing), you can switch to pass-through mode to quickly fix the error without exiting the demo.
- Statusline in the upper right corner of the terminal lets you know where you are and what mode your in. This can be disabled.
- Reload scripts while running without starting over. If you reload a script, its contents are updated, but the position in the demo is maintained.
Installing
Install pygsc
with pip
:
$ pip install pygsc
Usage
To start a demo, run gsc
with the script
$ gsc my_demo.sh
This will start shell (by default, $SHELL
) in a forked process and connect to it with a psuedo terminal. Each line in the script
is then loaded and sent to the shell, on character at a time, while the user types. Once the entire line has been sent, gsc
waits
for the user to press return, and the next line is loaded.
You can specify a different shell with the --shell
option.
$ gsc my_demo.sh --shell zsh
Keybindings
Insert Mode
Insert mode is the main mode, gsc
starts up in insert mode. While in insert mode, gsc
will read each line of the script and send
characters to the shell each time the user presses a key. When an entire line has been sent to the shell, gsc
will wait for the user
to press enter before starting the next line in the script.
<any character>
: send next character to shell.
return
: if at the end of current script line send \r
and load next script line. otherwise, send next character.
ctrl-d
: switch to command mode.
ctrl-p
: switch to pass-through mode.
ctrl-c
: exit gsc
Line Mode
Line mode is special type of insert mode where entire lines are sent to the shell instead of single characters. This mode is useful for quickly testing a script.
<any character>
: send next line to the shell.
return
: send \r
to shell and load next script line.
ctrl-d
: switch to command mode.
ctrl-c
: exit gsc
Command Mode
Command mode allows the user to make (simple) adjustments during the demo. The user can move the current character position, for example to skip a line or backup.
i
: switch to insert mode.
I
: switch to line mode.
p
: switch to pass-through mode.
j
: jump to the next line in the script.
k
: jump to the previous line in the script.
h
: jump to the previous character in the current script line.
k
: jump to the next character in the current script line.
^
: jump to the first character in the current script line.
$
: jump to the end of the current script line (one past the last character).
s
: toggle status line on/off.
R
: reload scripts (useful for developing scripts, you can edit the script in a text file while running and reload).
Pass-through Mode
Pass-through mode sends all user input to the shell. This can be used to fix the current line, fix the environment (remove files that are not supposed to be there), or just temporarily take over the demo.
ctrl-d
: switch to command mode.
ctrl-p
: switch to insert mode (ctrl-p
acts as a toggle between insert and pass-through mode).
Temporary Pass-through Mode
Temporary Pass-through mode is a special version of pass-through mode that exits as soon as the user pressed return. It is useful for allowing the user to insert a password.
return
: send \r
to shell and switch back to previous mode.
Commands
A script may embed commands in its comments. These are special keywords recognized by gsc
that will cause
some side effect or action to take place. Commands may provide arguments that will be processed by gsc
when
the command is recognized. The syntax for a command is
# name[: [arg1 [arg2 [...]]]]
If a command takes arguments, a colon ':' must separate the command name from the arguments. Multiple arguments are separated by spaces. If an argument contains spaces, it must be quoted.
pause: N
Pause the session for N
seconds. If N
is less than zero, the session will be paused until the user presses a key.
display: 'message to display'
Display a message in a separate display window. This command requires a message display backend to be installed.
Currently, the only backend supported is pygame
. So, to use this command, pygame
must be installed.
passthrough
Switch to pass-through mode. See above.
temporary passthrough
Switch to temporary pass-through mode. See above.
line
Switch to line mode. See above.
statusline: [on|off]
Enable/disable the status line.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pygsc-0.7.tar.gz
.
File metadata
- Download URL: pygsc-0.7.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-56-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d5ed30db5ee20dcf3796549b43ed757fca9571140e7e316fde233f966a7b9df |
|
MD5 | 57e88af939883da0823edc8c7df1fe27 |
|
BLAKE2b-256 | 0e568107b7cbd6f78388bd94304ec4a63dd6627f020fa9b5de97a2dbb334c0eb |
File details
Details for the file pygsc-0.7-py3-none-any.whl
.
File metadata
- Download URL: pygsc-0.7-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-56-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dce192c163c909506da0079cfe2e91c891ac27fc65acc3d4cfb044ffc529b991 |
|
MD5 | a6950e66d48d85208019973cab808759 |
|
BLAKE2b-256 | fe9cc74ce7c368551d9cb933218f7f8a6c8c04ea8acee05dce6c1200bbc0f2e1 |