Unsafe JupyterLab API

For giggles, the JupyterLab application is available inside your kernel. You can use it do useful things like loading files:

In [ ]:
JupyterLab.serviceManager.contents.get("index.ipynb")
    .then((x) => {
        display.display({
            "text/plain": JSON.stringify(x.content["cells"][0], null, 2)
        })
    })

Or dangerous things, like open new notebooks:

In [ ]:
JupyterLab.commands.execute("notebook:create-new")
    .then((notebook) => {
        display.display({
            "text/markdown": `## Notebook\n  - ${
                [].concat(Object.keys(notebook)).join('\n  - ')
            }`
        })
    })

Commands are really powerful. Here's all the trouble you could get up to:

In [ ]:
let keys = Object.keys(JupyterLab.commands._commands);
keys.sort();
let namespaces = keys.reduce(function(m, k){
    let ns = k.split(":")[0];
    m[ns] = m[ns] || [];
    m[ns].push(k);
    return m;
}, {});

display.display({
    "text/markdown": "> ## _click the links to search the JupyterLab repository_\n\n" + Object.keys(namespaces).map((ns) => {
        return `### ${ns}\n- ` + namespaces[ns].map(function(cmd){
//             return `<a data-commandlinker-command="${cmd}" href="#">${cmd}</a>`;
            return `[${cmd.split(":")[1]}](https://github.com/jupyterlab/jupyterlab/search?q="${cmd}")`
        }).join("\n- ");
    }).join("\n")
})