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

strip python subprocess prefix to enable python shell detections #27

Closed
wants to merge 3 commits into from

Conversation

Granitosaurus
Copy link

This fixes #26

$ ps -ww -o "pid=" -o "ppid=" -o "args="                                                                              
  17309    1624 /usr/bin/python -u /usr/bin/xonsh
  30755   17309 /usr/bin/ps -ww -o pid= -o ppid= -o args=
$ python -c "import shellingham;print(shellingham.detect_shell())"                                                    
('xonsh', '/usr/bin/xonsh')

@uranusjr
Copy link
Member

What I’m afraid of is this might cause false positives when the user runs a scrip called (say) bash. It would probably be a good idea to only allow stripping for chosen shells (e.g. xonsh).

@Granitosaurus
Copy link
Author

@uranusjr Could you clarify on the false positive issue? Right now if the first argument contains python -> remove first argument and any argument with leading -. I guess if the process is called my-python-shell it would break but that's kinda expected as my-python-shell would be unhandled anyways.

@uranusjr
Copy link
Member

I can kind of conceive a situation someone names a script handling bash stuff like ~/.local/bash. Not very likely by any means, but it’s better to be safe. What I have in mind is basically what you’re doing, but only if the replacement found ends with xonsh.

@Granitosaurus
Copy link
Author

Granitosaurus commented Feb 11, 2020

I can kind of conceive a situation someone names a script handling bash stuff like ~/.local/bash. Not very likely by any means, but it’s better to be safe. What I have in mind is basically what you’re doing, but only if the replacement found ends with xonsh.

Sounds fair! Let me take an attempt at this approach.

@Granitosaurus
Copy link
Author

@uranusjr ☝️ - change to handle xonsh explicitly.

uranusjr added a commit that referenced this pull request Feb 12, 2020
uranusjr added a commit that referenced this pull request Feb 12, 2020
@uranusjr
Copy link
Member

I pushed a tidied up version of this in #28. Could you help test whether that works?

@uranusjr uranusjr closed this in #28 Feb 12, 2020
@Granitosaurus Granitosaurus deleted the python_prefix branch February 12, 2020 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failing to detect xonsh shell because of python process name prefix.
2 participants