Try to open man page as help for subprocess commands

This makes for example 'sh?' equivalent to 'man sh', unless there actually
exists a 'sh?' executable.

Resolves #3204.
This commit is contained in:
Alexander Steffen 2019-07-14 00:44:38 +02:00
parent 8576e9c22e
commit 5457ac1c94
2 changed files with 28 additions and 0 deletions

23
news/subprocess-help.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* Open man page when requesting help for subprocess commands, e.g. using ``sh?``
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -563,6 +563,11 @@ class SubprocSpec:
raise XonshError(e.format(self.cmd[0]))
except FileNotFoundError:
cmd0 = self.cmd[0]
if len(self.cmd) == 1 and cmd0.endswith("?"):
with contextlib.suppress(OSError):
return self.cls(
["man", cmd0.rstrip("?")], bufsize=bufsize, **kwargs
)
e = "xonsh: subprocess mode: command not found: {0}".format(cmd0)
env = builtins.__xonsh__.env
sug = suggest_commands(cmd0, env, builtins.aliases)