diff options
-rw-r--r-- | plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java | 40 |
1 files changed, 38 insertions, 2 deletions
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 8269ba2..1376164 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. + * Copyright (c) 2009, 2017 Red Hat Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -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,38 @@ public class ShellDocumentationProvider implements IScriptDocumentationProvider @Override public Reader getInfo(String content) { - return new StringReader(new ManPage(content).getStrippedHtmlPage().toString()); + String helpInfo = getHelp(content); + if (!helpInfo.isEmpty()) { + return new StringReader("<pre>" + helpInfo + "</pre>"); + } + String info = new ManPage(content).getStrippedHtmlPage().toString(); + if (info.equals("<pre></pre>")) { + return null; + } + return new StringReader(info); + } + + public static String getHelp(String command) { + List<String> 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]; + 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) { + // ignore + } + return out.toString(); } @Override |