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

Access to shell completions. #6

Open
mchav opened this issue Aug 16, 2016 · 9 comments
Open

Access to shell completions. #6

mchav opened this issue Aug 16, 2016 · 9 comments

Comments

@mchav
Copy link
Owner

mchav commented Aug 16, 2016

Been trying to do this for a while to no avail.

http://stackoverflow.com/questions/4726695/bash-and-readline-tab-completion-in-a-user-input-loop

@mchav mchav changed the title Accesss to shell completions. Access to shell completions. Aug 16, 2016
@wilhelmtell
Copy link

Maybe the solution is not to have your own REPL, but to hook up to bash command execution? I've never done that, I wonder if that's possible.

Is this interesting?

@mchav
Copy link
Owner Author

mchav commented Aug 18, 2016

@wilhelmtell so use preexec to get a list of all the completions? Definitely an interesting option. It saves us having to use an external tool like rlwrap or writing a custom c program. It does seem a little unsafe though. I'm thinking of just writing a c program to do the work.

@wilhelmtell
Copy link

wilhelmtell commented Aug 19, 2016

rlwrap won't help. What I meant is, you want to stay in the user's environment, in the user's bash prompt. This way, all the user's settings are there -- including their completions, their bash prompt, their word expansions, everything. All you want to do is prefix their commands, that's it. Not take the command from them, not provide completion for them, not provide a prompt for them. If you stay out of the REPL, you don't need to worry about any of these.

So, googling for that, I found that hint about hooking up to the bash command execution. So I wondered if it's possible to set up a hook that is run before any command bash executes, that gives you the command prior to executing it, and allows you to alter it.

Then, you'd need two commands, rather than a with and an EOF: one command to hook onto the command execution, and one to unhook.

@mchav
Copy link
Owner Author

mchav commented Aug 19, 2016

Alright. That's what I was looking into. It seems running exec with xdotool and the prompt + \t\t can get a list of completions. And once we have those it's a matter of sending them back to the main shell via a file and using the list of completions.

Not sure how you could hook bash in the same process.

@mchav mchav added this to the 0.0.2 milestone Aug 19, 2016
@mchav
Copy link
Owner Author

mchav commented Aug 20, 2016

If possible the solution must not use external tools.

@dragonator
Copy link
Contributor

I've been working on this for the last week or something and I think I have a working solution.
It is not perfect but I think that it is pretty good for start.

The last thing that is left is to move the cursor to the appropriate place after a word completion is made.

Does anybody have an idea how this can be done?

@dragonator
Copy link
Contributor

dragonator commented Sep 5, 2016

Hello again,

I just create a "Pull request" with working implementation: #34

I hope you find it useful.

I'm new to bash scripting and this was quite of a challenge for me, but I'm glad that I manage to get it working.
I'll be very happy if someone can provide me his personal feedback on the changes and/or propose improvements.

@mchav
Copy link
Owner Author

mchav commented Sep 6, 2016

@dragonator I'm currently looking through the code. Your pull request seems great though. Thank you. I think I'll bump it up to version 0.0.2 after the code review.

@mchav
Copy link
Owner Author

mchav commented Sep 13, 2016

It seems that now we don't have file name completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants