Created
February 14, 2017 18:51
-
-
Save gforsyth/d557934a8c9fbfa9ae395896a0217130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### custom keybindings | |
| from prompt_toolkit.keys import Keys | |
| from builtins import events | |
| from prompt_toolkit.filters import Condition, EmacsInsertMode, ViInsertMode | |
| @events.on_post_init | |
| def custom_keys(): | |
| handler = __xonsh_shell__.shell.key_bindings_manager.registry.add_binding | |
| @Condition | |
| def less_than_ten_files(cli): | |
| return len(g`*`) < 10 | |
| @handler(Keys.ControlW) | |
| def say_hi(event): | |
| print('hi', end='') | |
| @handler(Keys.ControlL, filter=less_than_ten_files) | |
| def run_ls(event): | |
| ls -l | |
| event.cli.renderer.erase() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment