Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/techrah/jupyterext-text-shortcuts
A Jupyter Lab extension for keyboard text shortcuts
https://github.com/techrah/jupyterext-text-shortcuts
jupyterlab-extension keyboard-shortcuts
Last synced: 3 months ago
JSON representation
A Jupyter Lab extension for keyboard text shortcuts
- Host: GitHub
- URL: https://github.com/techrah/jupyterext-text-shortcuts
- Owner: techrah
- License: mit
- Created: 2019-10-27T16:25:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T05:02:31.000Z (over 1 year ago)
- Last Synced: 2024-07-06T02:46:29.590Z (4 months ago)
- Topics: jupyterlab-extension, keyboard-shortcuts
- Language: TypeScript
- Size: 677 KB
- Stars: 47
- Watchers: 3
- Forks: 11
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# text-shortcuts
A jupyterlab extension to insert text via keyboard shortcuts.
![release](https://github.com/techrah/jupyterext-text-shortcuts/workflows/release/badge.svg?branch=master)
## Pre-requisites
- JupyterLab 2.x, 3.x
- [node 12+](https://nodejs.org)## Installation
```bash
jupyter labextension install @techrah/text-shortcuts
```or add it through your Jupyter Lab **Extensions** tab.
Then, add some user shortcuts:
- In Jupyter Lab, select **Settings** / **Advanced Settings Editor** from the menu.
- Select the **Keyboard Shortcuts** tab.
- In the **User Preferences** section, add your shortcuts configuration and click the "save" icon.
Here are two useful shortcuts for programming in R:
```json
{
"shortcuts": [
{
"command": "text-shortcuts:insert-text",
"args": {
"kernel": "ir",
"text": "|>",
"autoPad": true
},
"keys": ["Accel Shift M"],
"selector": "body"
},
{
"command": "text-shortcuts:insert-text",
"args": {
"kernel": "ir",
"text": "<-",
"autoPad": true
},
"keys": ["Alt -"],
"selector": "body"
}
]
}
```**NOTE: As of version 0.1.x You do NOT need to add the above shortcuts to _User Preferences_ unless you want to override the default behaviour.** These two shortcuts are now installed by default. They can be found in _Keyboard Shortcuts / System Defaults_.
### Anatomy of a Text Shortcut
```
{
...
"command": "text-shortcuts:insert-text"
...
}
```Identifies the keyboard shortcut as a text shortcut that is intercepted by this extension.
```
{
...
"keys": [
"Accel Shift M"
],
...
}
````keys` is an array of keyboard shortcuts that activate the insertion of the text snippet. Each entry can be a combination of one or more of the following modifiers, ending with a text character. For example, "Accel Shift M" represents Command-Shift-M on macOS.
- `Accel` : Command (macOS) / Ctrl (Windows)
- `Alt` : Option (macOS) / Alt (Windows)
- `Shift` : Shift
- `Ctrl` : Control```
{
...
"args": {
"kernel": "ir",
"text": "|>",
"autoPad": true
}
...
}
```- `kernel` (optional): If you specify a `kernel`, the shortcut will only work in notebooks that are running the specified kernel. Examples of kernel names are `ir` and `python3`. For a list of installed kernels, use `jupyter kernelspec list`.
- `text`: This is the actual text that you want inserted.
- `autoPad`: (`true` | `false`). If `true`, will add spacing either before, after, or both before and after so that there is a single space on each side of the text.
```
{
...
"selector": "body"
...
}
```CSS selector. Always use `"body"` for this extension.
## Development
### Pre-requisites
- node 5+
- Python 3.6+It is strongly recommended that you set up a virtual Python environment. These instructions will assume that Anaconda is already installed.
- Create a new virtual environment and activate it.
```bash
conda create --name text-shortcuts
conda activate text-shortcuts
```- Install jupyterlab
```bash
conda install jupyterlab
```- Clone this project and in the root of the project folder, install dependencies with the JupyterLab Package Manager
```bash
jlpm
```- Install the extension
```bash
jupyter labextension install . --no-build
```- Start up jupyter lab in watch mode. Don't forget to activate your virtual environment. If you want to use a different browser for development, specify that with the `--browser` switch. If you want to use a custom port, specify that with the `--port` switch.
```bash
conda activate text-shortcuts
jupyter lab --watch --browser="chrome" --port=8889
```- In another terminal, run the TypeScript compiler in watch mode.
```bash
conda activate text-shortcuts
jlpm tsc -w
```For more information on developing JupyterLab extensions, here are some helpful resources:
- [Extension Developer Guide][1]
- [Common Extension Points: Keyboard Shortcuts][2]
- [JupyterLab Extensions by Examples][3]
- [CodeMirror: Document management methods][4]
- [Interface INotebookTracker][5]Pull requests are welcome!
[1]: https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html
[2]: https://jupyterlab.readthedocs.io/en/stable/extension/extension_points.html#keyboard-shortcuts
[3]: https://github.com/jupyterlab/extension-examples
[4]: https://codemirror.net/doc/manual.html#api_doc
[5]: https://jupyterlab.github.io/jupyterlab/interfaces/_notebook_src_index_.inotebooktracker.html