diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java
index 239300e..173b20a 100644
--- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java
+++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java
@@ -10,8 +10,13 @@
*******************************************************************************/
package org.eclipse.dltk.sh.internal.ui.selection;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.dltk.core.IMember;
import org.eclipse.dltk.ui.documentation.IScriptDocumentationProvider;
@@ -21,7 +26,53 @@
@Override
public Reader getInfo(String content) {
- return new StringReader(new ManPage(content).getStrippedHtmlPage().toString());
+ String helpInfo = getHelp(content);
+ if (!helpInfo.isEmpty()) {
+ return new StringReader("" + helpInfo + "
");
+ }
+ StringBuilder manInfo = new ManPage(content).getStrippedPage();
+ if (manInfo.length() == 0) {
+ return null;
+ }
+ // Any more than ~10kb and the hover help starts to take a really long time to
+ // render, so truncate it in that case and advise to use the man page view
+ final int maxLen = 1024 * 10;
+ StringBuilder sb = new StringBuilder("");
+ if (manInfo.length() > maxLen) {
+ sb.append(manInfo.substring(0, maxLen));
+ } else {
+ sb.append(manInfo);
+ }
+ sb.append("
");
+ if (manInfo.length() > maxLen) {
+ sb.append(
+ "This man page is truncated, use Show Man Page (Alt+M) to see the whole page for the selected word.
");
+ }
+ return new StringReader(sb.toString());
+ }
+
+ private static String getHelp(String command) {
+ List commands = new ArrayList<>();
+ commands.add("bash");
+ commands.add("-c");
+ commands.add("help " + command);
+ ProcessBuilder process = new ProcessBuilder(commands);
+ final StringBuilder out = new StringBuilder();
+ try (InputStream stream = process.start().getInputStream()) {
+ final char[] buffer = new char[1024];
+ try (Reader in = new InputStreamReader(stream)) {
+ for (;;) {
+ int rsz = in.read(buffer, 0, buffer.length);
+ if (rsz < 0) {
+ break;
+ }
+ out.append(buffer, 0, rsz);
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return out.toString();
}
@Override