ShellHelper

PyShada can also be a slaver of a shell. It is shada.shhelper module. It serves a shell to provide the capabilities of defining and using Python commands for the users. All variables and commands are defined in a shared name space. The name space is persistent over the life of the shell. Everything you defined can be used over the time again and again, just like what you defined for the normal shell. It extents shell with Python.

How to Use shhelper?

After PyShada being installed, you can run following command to start shhelper.


eval `python -m shada.shhelper`

After that, you can see what Python commands is there with following command


$py cmds

You can also define variables in the Python name space.

$py set variable1 “value1”

And show it.

$py values

You can also define new Python commands. Following commands define a Python command to prefix every line, from stdin, a line number and write to stdout.


$py def lineno <<EOF lno = 0 while True: yield line = session.recv() if line is None: break lno = lno + 1 session.send('%04d %s' % (lno, line)) EOF

Then, you can try it

inkscape$ ls -l | $py lineno 0001 total 199376 0002 -rw-r--r-- 1 thinker user 699 Dec 21 23:12 Cython.muse 0003 -rw-r--r-- 1 thinker user 556 Nov 12 20:06 Cython.muse~ 0004 -rw-r--r-- 1 thinker user 64209 Dec 27 13:06 FSM-n-action.png 0005 -rw-r--r-- 1 thinker user 44086 Dec 27 12:37 FSM-n-action.svg 0006 -rw-r--r-- 1 thinker user 667 Mar 25 15:59 NRArenaItem.muse 0007 -rw-r--r-- 1 thinker user 350 Mar 23 10:03 NRArenaItem.muse~ 0008 -rw-r--r-- 1 thinker user 350 Mar 24 12:43 SPCanvasItem.muse 0009 -rw-r--r-- 1 thinker user 156 Mar 23 11:26 SPDesktopWidget.muse 0010 -rw-r--r-- 1 thinker user 89 Mar 23 11:25 SPDesktopWidget.muse~ 0011 -rw-r--r-- 1 thinker user 94 Mar 4 20:33 SPNamedView.muse 0012 -rw-r--r-- 1 thinker user 749 Mar 28 01:03 SPObject.muse 0013 -rw-r--r-- 1 thinker user 90 Mar 25 18:11 SPObject.muse~ 0014 drwxr-xr-x 3 thinker user 512 Apr 1 19:53 arch 0015 drwxr-xr-x 2 thinker user 1536 Nov 7 18:51 arch-html 0016 -rw-r--r-- 1 thinker user 1303 Mar 4 17:16 build_extension.muse 0017 -rw-r--r-- 1 thinker user 670 Jan 14 00:12 build_extension.muse~ 0018 -rw-r--r-- 1 thinker user 36475 Nov 8 09:55 first-dock.png 0019 -rw-r--r-- 1 thinker user 4412 Nov 8 10:05 first-dock.svg 0020 -rw-r--r-- 1 thinker user 45684 Nov 8 10:05 first-dock.svg.png 0021 -rw------- 1 thinker user 203763712 Dec 28 10:41 inkscape.core 0022 -rw-r--r-- 1 thinker user 255 Mar 31 12:02 inkview.muse 0023 -rw-r--r-- 1 thinker user 77 Mar 31 11:31 inkview.muse~ 0024 -rw-r--r-- 1 thinker user 2251 Mar 23 16:12 main.muse 0025 -rw-r--r-- 1 thinker user 2143 Mar 4 20:26 main.muse~ 0026 -rw-r--r-- 1 thinker user 685 Jan 26 22:56 pygobject.muse 0027 -rw-r--r-- 1 thinker user 480 Nov 8 18:23 pygobject.muse~ 0028 -rw-r--r-- 1 thinker user 16248 Nov 2 09:22 wantyou.svg inkscape$

Following is an example of random number generator.

inkscape$ $py def random <<EOF import random v = random.random() session.send(str(v) + '\n') EOF command random was defined inkscape$ $py random 0.217115667522 inkscape$ echo `$py random` 0.969004678594 inkscape$

Easy To Be Used!

shada.shhelper is easy to be used. It is a complement of shell commands. Sometime, shell is just not good for some kind of task, and Python is just good in these categories of work. shada.shhelper integrates Python into shell to make the life of shell easy.