forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellIntegrationScripts.java
More file actions
67 lines (55 loc) · 1.91 KB
/
Copy pathShellIntegrationScripts.java
File metadata and controls
67 lines (55 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.terminal.api;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import com.microsoft.copilot.eclipse.core.CopilotCore;
/**
* Utility class for accessing the shell integration script.
*/
public final class ShellIntegrationScripts {
/**
* The marker string output by the shell integration script after each command completes.
* Uses OSC (Operating System Command) escape sequence format: ESC ] 7775 ; marker BEL
* This is invisible in terminal output but can be detected programmatically.
*/
public static final String SHELL_MARKER = "\u001b]7775;C\u0007";
private static final String SCRIPTS_PATH = "scripts/";
private static final String SH_SCRIPT = "copilot-sh-integration.sh";
private ShellIntegrationScripts() {
// Utility class
}
/**
* Gets the absolute file path to the POSIX sh integration script.
*
* @return the absolute path to the sh script, or null if not found
*/
public static String getShScriptPath() {
try {
Bundle bundle = FrameworkUtil.getBundle(ShellIntegrationScripts.class);
if (bundle == null) {
return null;
}
URL scriptUrl = FileLocator.find(bundle, new Path(SCRIPTS_PATH + SH_SCRIPT));
if (scriptUrl == null) {
return null;
}
URL fileUrl = FileLocator.toFileURL(scriptUrl);
if (fileUrl == null) {
return null;
}
File scriptFile = new File(fileUrl.getPath());
if (scriptFile.exists()) {
return scriptFile.getAbsolutePath();
}
} catch (IOException e) {
CopilotCore.LOGGER.error("Failed to locate shell integration script: " + SH_SCRIPT, e);
}
return null;
}
}