Skip to content

Instantly share code, notes, and snippets.

@gforsyth
Created February 14, 2017 18:51
Show Gist options
  • Select an option

  • Save gforsyth/d557934a8c9fbfa9ae395896a0217130 to your computer and use it in GitHub Desktop.

Select an option

Save gforsyth/d557934a8c9fbfa9ae395896a0217130 to your computer and use it in GitHub Desktop.
### 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