Skip to content

Commit 56e22c7

Browse files
committed
ipython
1 parent dad8c0b commit 56e22c7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

ipython/00-init.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
ip = get_ipython()
55
ip.run_line_magic('rehashx', '')
6+
7+
# Alias hyphenated executables with underscores (e.g. ws-status -> ws_status)
8+
for d in os.environ.get('PATH', '').split(os.pathsep):
9+
if os.path.isdir(d):
10+
for f in os.listdir(d):
11+
if '-' in f and os.access(f'{d}/{f}', os.X_OK):
12+
ip.alias_manager.soft_define_alias(f.replace('-', '_'), f)
613
ip.system = lambda cmd: ip.system_raw(f'bash -c {shlex.quote("shopt -s expand_aliases; source ~/.bashrc; " + cmd)}')
714
ip.getoutput = lambda cmd: subprocess.run(['bash', '-c', f'shopt -s expand_aliases; source ~/.bashrc; {cmd}'],
815
capture_output=True, text=True).stdout.strip().split('\n')

ipython/02-keybindings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ~/.ipython/profile_default/startup/02-keybindings.py
2+
from subprocess import run
3+
from prompt_toolkit.keys import Keys
4+
from prompt_toolkit.filters import HasFocus
5+
from prompt_toolkit.enums import DEFAULT_BUFFER
6+
7+
def _ssage(event):
8+
buf = event.app.current_buffer
9+
res = run(["ssage_extract", "--do_print", buf.text or "0"], capture_output=True, text=True)
10+
buf.text = res.stdout.rstrip('\n')
11+
buf.cursor_position = len(buf.text)
12+
13+
ip = get_ipython()
14+
if ip.pt_app: ip.pt_app.key_bindings.add(Keys.ControlJ, filter=HasFocus(DEFAULT_BUFFER))(_ssage)

0 commit comments

Comments
 (0)