Skip to content

Commit 06c1b6a

Browse files
committed
buildtin: Add first version of bind
* Add a simple, introductory version of the buildtin `bind` command that just passes configuration options to `readline`. * Fixes oils-for-unix#339. Signed-off-by: mr.Shu <[email protected]>
1 parent 9d2c651 commit 06c1b6a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

bin/oil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ def ShellMain(lang, argv0, argv, login_shell):
445445
builtin_e.ALIAS: builtin.Alias(aliases, errfmt),
446446
builtin_e.UNALIAS: builtin.UnAlias(aliases, errfmt),
447447

448+
builtin_e.BIND: builtin.Bind(line_input),
449+
448450
builtin_e.HELP: builtin.Help(loader, errfmt),
449451

450452
builtin_e.TYPE: builtin.Type(funcs, aliases, mem),

osh/builtin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
"alias": builtin_e.ALIAS,
123123
"unalias": builtin_e.UNALIAS,
124124

125+
"bind": builtin_e.BIND,
126+
125127
# OSH only
126128
"repr": builtin_e.REPR,
127129
}
@@ -1213,6 +1215,25 @@ def __call__(self, arg_vec):
12131215
return status
12141216

12151217

1218+
BIND_SPEC = _Register('bind')
1219+
1220+
1221+
class Bind(object):
1222+
def __init__(self, readline_mod):
1223+
self.readline_mod = readline_mod
1224+
1225+
def __call__(self, arg_vec):
1226+
if len(arg_vec.strs) == 1:
1227+
raise args.UsageError('bind keyseq:function-name')
1228+
1229+
status = 0
1230+
for i in xrange(1, len(arg_vec.strs)):
1231+
readline_option = arg_vec.strs[i]
1232+
self.readline_mod.parse_and_bind(readline_option)
1233+
1234+
return status
1235+
1236+
12161237
class _TrapHandler(object):
12171238
"""A function that is called by Python's signal module.
12181239

osh/runtime.asdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module runtime
8282
| TEST | BRACKET | GETOPTS
8383
| COMMAND | TYPE | HELP | HISTORY
8484
| DECLARE | TYPESET | ALIAS | UNALIAS
85+
| BIND
8586
| REPR
8687
| BUILTIN
8788

0 commit comments

Comments
 (0)