-
Notifications
You must be signed in to change notification settings - Fork 329
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
Add shell command integration #61
Conversation
eliangcs
commented
Jun 27, 2016
•
edited
Loading
edited
- Execute any strings in backticks as shell commands
- Shell command lexer (syntax highlighting)
- Shell command completer
- Sync with master and resolve conflicts
Hello @eliangcs , do you have some thoughts on how the "Shell command completer" should work? |
@fogine I agree with you that bash completion is not needed here at the moment. But we do want to make sure the original autocomplete feature won't be broken by the backtick syntax. |
Also, is it ok if I push the "pipe to shell command" redirection to this PR, @eliangcs ? localhost> post | `tee /tmp/req.log <<< $data` # $data variable would be available with the httpie response here Or it could automatically redirect the httpie output to localhost> post | `tee /tmp/req.log` The bash expression of the above command would be automatically resolved to: echo $httpieResponse | tee /tmp/req.log Which is less flexible but preserves the bash-like "pipe" functionallity |
@fogine I'm not sure if I understand your question correctly. But in my original design, the content quoted with backticks is different from the content coming after the first pipe char ( Anything that is quoted in backticks should be preprocessed in shell environment before the whole command is executed by http-prompt. So for example, if you do: http://localhost> post | `head -n 2 | grep name` It should prompt the user for the input for the
Then the http://localhost> post | name 123 On the other hand, anything coming after the first pipe char should be treated as a shell command that takes the previous http-prompt output as stdin. For example: http://localhost> post | head -n 2 | grep name It should make the post request and get the response first. Then put the response output to |
@eliangcs , to be honest, I haven't known about the special behavior of a code quoted with backticks in the bash, I have been always using the The way how you described your bash-like design makes sense and is more intuitive, thanks for the explanation. ps: I won't have time to implement the remaining functionality till next week... |
I started implementing "pipe to shell command redirection" as we discussed above. May I ask you, @eliangcs , do you know how "rule precedence" work in the
I don't quite understand the statement. https://api.github.com> get | tee /tmp/test ...the Do you know if it's possible with a Thank you for your time @eliangcs ! |
@fogine Can you explain more? Take |
@eliangcs , in the After the However I think I get it now. What I haven't realized is that currently, the |
…kticks shell command. Eg.: localhost> httpie | `echo "sed 's/localhost/127.0.0.1/'"`
shell commands - lexer rules, pipe to shell cmd redirection, tests
@fogine I just finished this PR along with your patch. Would you like to review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work @eliangcs !
The code has got much prettier.
I've not found any bugs so far...
Just two mentioned minor things from my observation...
Thanks.
p = Popen(cmd, shell=True, stdout=PIPE) | ||
return p.stdout.read().decode('utf-8').rstrip() | ||
|
||
def _is_backticks_cmd_preceded_with_pipe_redir(self, node): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _is_backticks_cmd_preceded_with_pipe_redir
method is no longer needed (unused).
@@ -169,6 +184,12 @@ def __init__(self, context, listener=None): | |||
self.tool = None | |||
self._output = Printer() | |||
|
|||
# If there's a pipe, as in "httpe post | sed s/POST/GET/", this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a typo :) "httpe"
@fogine I've fixed the two things you mentioned. Good catch, thanks! |