- Notifications
You must be signed in to change notification settings - Fork0
apowers313/magicpatch
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
magicpatch makes theJupyterIJavascript kernel as close as possible to theIPython experience by adding%magic
commands,!shell
execution,{variable}
substitution, and more! You can find examples inthis Jupyter notebook.
# IJavascript should already be installed before installing magicpatchnpm install -g magicpatchmagicpatch-install
More demoshere.
Wherever possible, this module tries to duplicate the features ofIPython experience.
Magic commands traditionally start with%
because it isn't a valid operator in Python. This package adds a number of default magics and allows you too define your own using the%addmagic
command or through the$$.addMagic
global function.
As a quick introduction to magics, here's a simple example of the%echo
magic:
See thebuilt in magics sectiono below for magics included in this package, or while running Jupyter you can use%lsmagic
to list the names of all the magics or%quickref
to get a quick guide to all the magics.
Shell commands can be run quickly by starting the line with!
. For example,!ls
will run the commandls
in the underlying shell and show the output.
The output of magics can be assigned to variables. For example,mod = %require myPackage
would load themyPackage
npm module and assign the results to the variablemod
.
Variables can be used as inputs to magics by wrapping them in curly braces. For example,%echo {myVar}
will print the contents ofmyVar
.
If you want to know what a magic does, you can quickly get documentation using?
or??
. For example%echo?
will print the documentation for the%echo
magic, and%echo??
will print the source code for the%echo
magic.
Input is cached in the globalIn
and_ih
arrays, whereIn[0]
was the first text that you ran in your notebook. You can also access the last three inputs through the_i
,_ii
, and_iii
global variables.
Similar to input caching, the output of your last three commands is stored in_
,__
, and___
. Note that there is no globalOut
array due to memory usage concerns.
Cell magics allow the entire Jupyter cell to be treated differently. For example%%script bash
will treat the rest of the cell as a bash script. You can find a demo inthis notebook.
By default, all magics require the leading special symbol%
, but you can turn that off for convenience using%automagic on
. With automagic turned on,%echo
can simply be typedecho
.
To date, the following magics have been added:
- %addmagic (magicpatch only)
- %automagic
- %cat
- %cd
- %cp
- %dhist
- %dirs
- %echo (magicpatch only)
- %env
- %hist
- %history
- %inspect (magicpatch only)
- %load
- %loadjs (magicpatch only)
- %loadpy
- %ls
- %lsmagic
- %mkdir
- %mv
- %notify (magicpatch only)
- %npm
- %pip
- %popd
- %pushd
- %pwd
- %quickref
- %report (magicpatch only)
- %require (magicpatch only)
- %rm
- %rmdir
- %sx
- %who
- %whos
- %%script
Adding your own magics is as easy as calling%addmagic %yourmagicname yourMagicFunction
from Jupyter or$$.addMagic("%yourmagicname", {fn: yourMagicFunction})
from a module. Your magic will be passed an array of strings that were passed in on the command line. Similar toprocess.argv the first string is always your command name. For more advanced usage, such as adding documentation for your magic, creating cell magics, or accessing magicpatch internals to create fancy magics, refer to theAddingMagics.md documentation.
This is a community project! All bug fixes, new magics, and contributions are welcome. I really want to encourage people to add new magics -- anything that helps people develop faster or have more fun would be a worthwhile contribution.
Contributors and participants are expected to be good humans. No jerks allowed.