Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildtin: Add first version of bind #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does bash process all positional arguments?

When I do help bind, it doesn't have the customary ... syntax for the last arg:

[keyseq:readline-function or readline-command]

I've never used bind honestly. Can you maybe write some manual test cases in the comments?

Ideally tests should be automatic, but interactive readline stuff is hard to test of course... I maintain some manual test cases here, and those would be useful for bind

https://github.com/oilshell/oil/wiki/Testing-the-Interactive-Shell

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