Skip to content

Commit

Permalink
buildtin: Add first version of bind
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mrshu committed Jun 19, 2019
1 parent 9d2c651 commit 06c1b6a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ def ShellMain(lang, argv0, argv, login_shell):
builtin_e.ALIAS: builtin.Alias(aliases, errfmt),
builtin_e.UNALIAS: builtin.UnAlias(aliases, errfmt),

builtin_e.BIND: builtin.Bind(line_input),

builtin_e.HELP: builtin.Help(loader, errfmt),

builtin_e.TYPE: builtin.Type(funcs, aliases, mem),
Expand Down
21 changes: 21 additions & 0 deletions osh/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"alias": builtin_e.ALIAS,
"unalias": builtin_e.UNALIAS,

"bind": builtin_e.BIND,

# OSH only
"repr": builtin_e.REPR,
}
Expand Down Expand Up @@ -1213,6 +1215,25 @@ def __call__(self, arg_vec):
return status


BIND_SPEC = _Register('bind')


class Bind(object):
def __init__(self, readline_mod):
self.readline_mod = readline_mod

def __call__(self, arg_vec):
if len(arg_vec.strs) == 1:
raise args.UsageError('bind keyseq:function-name')

status = 0
for i in xrange(1, len(arg_vec.strs)):
readline_option = arg_vec.strs[i]
self.readline_mod.parse_and_bind(readline_option)

return status


class _TrapHandler(object):
"""A function that is called by Python's signal module.
Expand Down
1 change: 1 addition & 0 deletions osh/runtime.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module runtime
| TEST | BRACKET | GETOPTS
| COMMAND | TYPE | HELP | HISTORY
| DECLARE | TYPESET | ALIAS | UNALIAS
| BIND
| REPR
| BUILTIN

Expand Down

0 comments on commit 06c1b6a

Please sign in to comment.