mirror of
https://github.com/Silverquark/dance.git
synced 2024-09-11 18:48:00 +03:00
api: respect automation profile to run commands (fixes #248)
This commit is contained in:
parent
e5a821ebb9
commit
4e9d32f244
@ -106,8 +106,8 @@ const { api } = await vscode.extensions.getExtension("gregoire.dance").activate(
|
||||
|
||||
Pipes no longer accept shell commands, but instead accept "expressions", those
|
||||
being:
|
||||
- `#<shell command>`: Pipes each selection into a shell command (the shell is
|
||||
taken from the `terminal.external.exec` value).
|
||||
- `#<shell command>`: Pipes each selection into a shell command (the shell
|
||||
respects the `terminal.integrated.automationProfile.<os>` profile).
|
||||
- `/<pattern>[/<replacement>[/<flags>]`: A RegExp literal, as
|
||||
[defined in JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).
|
||||
Do note the addition of a `replacement`, for commands that add or replace
|
||||
|
@ -2,7 +2,6 @@ import * as vscode from "vscode";
|
||||
|
||||
import { Context } from "./context";
|
||||
import type { CommandDescriptor } from "../commands";
|
||||
import type { Register } from "../state/registers";
|
||||
import { parseRegExpWithReplacement } from "../utils/regexp";
|
||||
|
||||
/**
|
||||
@ -345,6 +344,7 @@ export declare namespace command {
|
||||
}
|
||||
|
||||
let canExecuteArbitraryCommands = true;
|
||||
const commonSpawnOptions = { stdio: "pipe", windowsHide: true } as const;
|
||||
|
||||
/**
|
||||
* Executes a shell command.
|
||||
@ -368,8 +368,13 @@ export function execute(
|
||||
|
||||
const promise = import("child_process").then((cp) =>
|
||||
new Promise<string>((resolve, reject) => {
|
||||
const shell = getShell() ?? true,
|
||||
child = cp.spawn(command, { shell, stdio: "pipe" });
|
||||
const automationProfile = getAutomationProfile(),
|
||||
shell = typeof automationProfile?.path === "string" ? automationProfile.path : "",
|
||||
args = Array.isArray(automationProfile?.args) ? automationProfile!.args : [],
|
||||
env = typeof automationProfile?.env === "object" ? automationProfile.env : {},
|
||||
child = shell.length === 0
|
||||
? cp.spawn(command, { ...commonSpawnOptions,shell: true, env })
|
||||
: cp.spawn(shell, [...args, command], { ...commonSpawnOptions,shell: false, env });
|
||||
|
||||
let stdout = "",
|
||||
stderr = "";
|
||||
@ -413,7 +418,13 @@ export function disableExecuteFunction() {
|
||||
canExecuteArbitraryCommands = false;
|
||||
}
|
||||
|
||||
function getShell() {
|
||||
interface AutomationProfile {
|
||||
readonly path?: string;
|
||||
readonly args?: readonly string[];
|
||||
readonly env?: Record<string, string>;
|
||||
}
|
||||
|
||||
function getAutomationProfile() {
|
||||
let os: string;
|
||||
|
||||
switch (process.platform) {
|
||||
@ -434,11 +445,10 @@ function getShell() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const config = vscode.workspace.getConfiguration("terminal");
|
||||
const config = vscode.workspace.getConfiguration("terminal.integrated.automationProfile");
|
||||
|
||||
return config.get<string | null>(`integrated.automationShell.${os}`)
|
||||
?? process.env["SHELL"]
|
||||
?? undefined;
|
||||
return config.get<AutomationProfile | null>(os)
|
||||
?? { path: process.env["SHELL"] };
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user