├── .gitignore ├── .travis.yml ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── calysto_bash.ipynb ├── calysto_bash ├── __init__.py ├── __main__.py ├── images │ ├── logo-32x32.png │ └── logo-64x64.png ├── kernel.json └── kernel.py ├── setup.py └── test_bash_kernel.py /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints/ 2 | MANIFEST 3 | dist/ 4 | build/ 5 | *.egg-info/ 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | dist: trusty 3 | python: 4 | - "2.7" 5 | - "3.5" 6 | - "3.6" 7 | install: 8 | - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; 9 | - bash miniconda.sh -b -p $HOME/miniconda 10 | - export PATH="$HOME/miniconda/bin:$PATH" 11 | - hash -r 12 | - conda config --set always_yes yes --set changeps1 no 13 | - conda update -q conda 14 | - conda info -a 15 | - conda uninstall --force libedit 16 | - conda install -c conda-forge pip 17 | - pip install . 18 | script: 19 | - make test 20 | - python -m calysto_bash install --user 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2019, Calysto Development Team 2 | 3 | BSD 3-Clause License 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | include setup.py 4 | include Makefile 5 | include calysto_bash.ipynb 6 | include test_bash_kernel.py 7 | recursive-include calysto_bash *.py *.json *.png 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Note: This is meant for calysto_bash developer use only 2 | .PHONY: all clean test release 3 | 4 | export NAME=`python setup.py --name 2>/dev/null` 5 | export VERSION=`python setup.py --version 2>/dev/null` 6 | 7 | all: clean 8 | python setup.py install 9 | 10 | clean: 11 | rm -rf build 12 | rm -rf dist 13 | 14 | test: clean 15 | pip install jupyter_kernel_test nbconvert 16 | python -V 2>&1 | grep "Python 3" && python test_bash_kernel.py || echo "Skipping unit test" 17 | jupyter nbconvert --to notebook --execute --ExecutePreprocessor.kernel_name=calysto_bash --ExecutePreprocessor.timeout=60 --stdout calysto_bash.ipynb > /dev/null; 18 | make clean 19 | 20 | release: test clean 21 | pip install wheel 22 | python setup.py register 23 | python setup.py bdist_wheel --universal 24 | python setup.py sdist 25 | git commit -a -m "Release $(VERSION)"; true 26 | git tag v$(VERSION) 27 | git push origin --all 28 | git push origin --tags 29 | twine upload dist/* 30 | printf '\nUpgrade bash_kernel-feedstock with release and sha256 sum:' 31 | shasum -a 256 dist/*.tar.gz 32 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | A Calysto Jupyter kernel for Bash. 2 | 3 | To install:: 4 | 5 | pip install calysto_bash 6 | 7 | To use it, run one of: 8 | 9 | .. code:: shell 10 | 11 | jupyter notebook 12 | # In the notebook interface, select 'Calysto Bash' from the 'New' menu 13 | ipython qtconsole --kernel calysto_bash 14 | ipython console --kernel calysto_bash 15 | 16 | This is based on `MetaKernel `_, 17 | which means it features a standard set of %%magics. 18 | 19 | A sample notebook is available online_. 20 | 21 | 22 | Advanced Installation Notes:: 23 | We automatically install a Jupyter kernelspec when installing the 24 | python package. This location can be found using ``jupyter kernelspec list``. 25 | If the default location is not desired, you can remove the directory for the 26 | ``calysto_bash`` kernel, and install using `python -m calysto_bash install`. See 27 | ``python -m calysto_bash install --help`` for available options. 28 | 29 | 30 | .. _online: http://nbviewer.ipython.org/github/Calysto/calysto_bash/blob/master/calysto_bash.ipynb 31 | -------------------------------------------------------------------------------- /calysto_bash.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Jupyter Bash Kernel\n", 8 | "============\n", 9 | "\n", 10 | "Interact with Bash in a Notebook. All commands are interpreted by Bash. Since this is a [MetaKernel](https://github.com/Calysto/metakernel), a standard set of magics are available. Help on commands is available using the `%help` magic or using `?` with a command." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "metadata": { 17 | "collapsed": false 18 | }, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "Hello, world!\r\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "echo 'Hello, world!'" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "metadata": { 36 | "collapsed": false 37 | }, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | ".ipynb_checkpoints/\n", 44 | "MANIFEST\n", 45 | "dist/\n", 46 | "build/\n", 47 | "*.egg-info/\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "cat .gitignore" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "metadata": { 59 | "collapsed": false 60 | }, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "HISTORY.rst \u001b[34m__pycache__\u001b[39;49m\u001b[0m bash_kernel.ipynb test_bash_kernel.py\n", 67 | "README.rst \u001b[34mbash_kernel\u001b[39;49m\u001b[0m flit.ini\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "ls" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 4, 78 | "metadata": { 79 | "collapsed": false, 80 | "scrolled": true 81 | }, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "Available line magics:\n", 88 | "%activity %cd %connect_info %dot %download %edit %get %help %html %include %install %install_magic %javascript %jigsaw %kernel %kx %latex %load %ls %lsmagic %macro %magic %parallel %plot %pmap %px %python %reload_magics %restart %run %set %shell\n", 89 | "\n", 90 | "Available cell magics:\n", 91 | "%%activity %%brain %%debug %%dot %%file %%help %%html %%javascript %%kx %%latex %%macro %%processing %%px %%python %%shell %%show %%time %%tutor\n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "%lsmagic" 97 | ] 98 | } 99 | ], 100 | "metadata": { 101 | "kernelspec": { 102 | "display_name": "Calysto Bash", 103 | "language": "bash", 104 | "name": "calysto_bash" 105 | }, 106 | "language_info": { 107 | "codemirror_mode": "shell", 108 | "file_extension": ".sh", 109 | "help_links": [ 110 | { 111 | "text": "MetaKernel Magics", 112 | "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" 113 | } 114 | ], 115 | "mimetype": "text/x-bash", 116 | "name": "bash", 117 | "version": "0.1.0" 118 | } 119 | }, 120 | "nbformat": 4, 121 | "nbformat_minor": 0 122 | } 123 | -------------------------------------------------------------------------------- /calysto_bash/__init__.py: -------------------------------------------------------------------------------- 1 | """A Bash kernel for Jupyter""" 2 | 3 | __version__ = '0.2.2' 4 | -------------------------------------------------------------------------------- /calysto_bash/__main__.py: -------------------------------------------------------------------------------- 1 | 2 | from .kernel import BashKernel 3 | 4 | if __name__ == '__main__': 5 | BashKernel.run_as_main() 6 | -------------------------------------------------------------------------------- /calysto_bash/images/logo-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Calysto/calysto_bash/dfa6833187e1fe9d9c229fd7bcc839fd7813d74b/calysto_bash/images/logo-32x32.png -------------------------------------------------------------------------------- /calysto_bash/images/logo-64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Calysto/calysto_bash/dfa6833187e1fe9d9c229fd7bcc839fd7813d74b/calysto_bash/images/logo-64x64.png -------------------------------------------------------------------------------- /calysto_bash/kernel.json: -------------------------------------------------------------------------------- 1 | { 2 | "argv": ["python", 3 | "-m", "calysto_bash", 4 | "-f", "{connection_file}"], 5 | "display_name": "Calysto Bash", 6 | "language": "bash", 7 | "mimetype": "text/x-sh", 8 | "name": "calysto_bash" 9 | } 10 | -------------------------------------------------------------------------------- /calysto_bash/kernel.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import json 4 | import os 5 | import sys 6 | from metakernel import MetaKernel 7 | 8 | from . import __version__ 9 | 10 | 11 | def get_kernel_json(): 12 | """Get the kernel json for the kernel. 13 | """ 14 | here = os.path.dirname(__file__) 15 | with open(os.path.join(here, 'kernel.json')) as fid: 16 | data = json.load(fid) 17 | data['argv'][0] = sys.executable 18 | return data 19 | 20 | 21 | class BashKernel(MetaKernel): 22 | app_name = 'calysto_bash' 23 | implementation = 'Calysto Bash' 24 | implementation_version = __version__ 25 | language = 'bash' 26 | language_version = __version__ 27 | banner = "Calysto Bash - interact with bash" 28 | language_info = { 29 | 'mimetype': 'text/x-sh', 30 | 'name': 'bash', 31 | 'file_extension': '.sh', 32 | "version": __version__, 33 | 'help_links': MetaKernel.help_links, 34 | } 35 | kernel_json = get_kernel_json() 36 | 37 | def get_usage(self): 38 | return "This is the bash kernel." 39 | 40 | def do_execute_direct(self, code): 41 | if not code.strip(): 42 | return 43 | self.log.debug('execute: %s' % code) 44 | shell_magic = self.line_magics['shell'] 45 | try: 46 | resp = shell_magic.eval(code.strip()) 47 | self.Print(resp) 48 | except Exception as e: 49 | self.Error(e) 50 | self.log.debug('execute done') 51 | 52 | def get_completions(self, info): 53 | shell_magic = self.line_magics['shell'] 54 | return shell_magic.get_completions(info) 55 | 56 | def get_kernel_help_on(self, info, level=1, none_on_fail=False): 57 | code = info['code'].strip() 58 | if not code or len(code.split()) > 1: 59 | if none_on_fail: 60 | return None 61 | else: 62 | return "" 63 | shell_magic = self.line_magics['shell'] 64 | return shell_magic.get_help_on(info, 1) 65 | 66 | def repr(self, data): 67 | return data 68 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """Setup script for octave_kernel package. 2 | """ 3 | import glob 4 | 5 | DISTNAME = 'calysto_bash' 6 | DESCRIPTION = 'A Jupyter kernel for Bash.' 7 | LONG_DESCRIPTION = open('README.rst', 'rb').read().decode('utf-8') 8 | MAINTAINER = 'Steven Silvester' 9 | MAINTAINER_EMAIL = 'steven.silvester@ieee.org' 10 | URL = 'http://github.com/Calysto/calysto_bash' 11 | LICENSE = 'BSD' 12 | REQUIRES = ["metakernel (>=0.20.7)", "jupyter_client (>=4.3.0)", "ipykernel"] 13 | INSTALL_REQUIRES = ["metakernel >=0.20.7", "jupyter_client >=4.3.0", "ipykernel"] 14 | PACKAGES = [DISTNAME] 15 | PACKAGE_DATA = { 16 | DISTNAME: ['*.m'] + glob.glob('%s/**/*.*' % DISTNAME) 17 | } 18 | DATA_FILES = [ 19 | ('share/jupyter/kernels/calysto_bash', [ 20 | '%s/kernel.json' % DISTNAME 21 | ] + glob.glob('%s/images/*.png' % DISTNAME) 22 | ) 23 | ] 24 | CLASSIFIERS = """\ 25 | Intended Audience :: Science/Research 26 | License :: OSI Approved :: BSD License 27 | Operating System :: OS Independent 28 | Programming Language :: Python 29 | Programming Language :: Python :: 2.7 30 | Programming Language :: Python :: 3.3 31 | Programming Language :: Python :: 3.4 32 | Topic :: Scientific/Engineering 33 | Topic :: Software Development 34 | Topic :: System :: Shells 35 | """ 36 | 37 | from setuptools import setup 38 | 39 | with open('calysto_bash/__init__.py', 'rb') as fid: 40 | for line in fid: 41 | line = line.decode('utf-8') 42 | if line.startswith('__version__'): 43 | version = line.strip().split()[-1][1:-1] 44 | break 45 | 46 | 47 | setup( 48 | name=DISTNAME, 49 | version=version, 50 | maintainer=MAINTAINER, 51 | maintainer_email=MAINTAINER_EMAIL, 52 | packages=PACKAGES, 53 | package_data=PACKAGE_DATA, 54 | include_package_data=True, 55 | data_files=DATA_FILES, 56 | url=URL, 57 | download_url=URL, 58 | license=LICENSE, 59 | platforms=["Any"], 60 | description=DESCRIPTION, 61 | long_description=LONG_DESCRIPTION, 62 | classifiers=list(filter(None, CLASSIFIERS.split('\n'))), 63 | requires=REQUIRES, 64 | install_requires=INSTALL_REQUIRES 65 | ) 66 | -------------------------------------------------------------------------------- /test_bash_kernel.py: -------------------------------------------------------------------------------- 1 | """Example use of jupyter_kernel_test, with tests for IPython.""" 2 | 3 | import unittest 4 | import jupyter_kernel_test as jkt 5 | 6 | 7 | class BashKernelTests(jkt.KernelTests): 8 | kernel_name = "calysto_bash" 9 | 10 | language_name = "bash" 11 | 12 | code_hello_world = "echo 'hello, world'" 13 | 14 | completion_samples = [ 15 | { 16 | 'text': 'fdis', 17 | 'matches': {'fdisk'}, 18 | }, 19 | ] 20 | 21 | code_page_something = "ls?" 22 | 23 | if __name__ == '__main__': 24 | unittest.main() 25 | --------------------------------------------------------------------------------