Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use vscode settings for shell execution #1134

Merged
merged 3 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/vscode/tasks/src/lib/cli-task.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CliTaskDefinition } from './cli-task-definition';
import { Task, TaskGroup, TaskScope } from 'vscode';
import { ShellExecution, Task, TaskGroup, TaskScope } from 'vscode';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ShellExecution used somewhere here? I don't see a reference within this file.

Maybe it has side effects?

import { getShellExecutionForConfig } from './shell-execution';
import { findClosestNg, findClosestNx } from '@nx-console/server';
import { join } from 'path';
Expand Down
40 changes: 1 addition & 39 deletions libs/vscode/tasks/src/lib/shell-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,8 @@ export interface ShellConfig {
export function getShellExecutionForConfig(
config: ShellConfig
): ShellExecution {
let execution: ShellExecution;
if (platform() === 'win32') {
execution = getWin32ShellExecution(config);
} else {
execution = getUnixShellExecution(config);
}

return execution;
}

function getWin32ShellExecution(config: ShellConfig): ShellExecution {
return new ShellExecution(config.displayCommand, {
cwd: config.cwd,
executable:
'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe',
shellArgs: [
`-Sta -NoLogo -NonInteractive -C "& {${config.program.replace(
/ /g,
'` ' // NOTE: In powershell ` is the escape key.
)} ${config.args.join(' ')}}"`,
],
});
}

let bashPath: string;
function getUnixShellExecution(config: ShellConfig): ShellExecution {
if (!bashPath) {
try {
bashPath = execSync('which bash').toString().trim() || '/bin/bash';
} catch {
bashPath = '/bin/bash'; // Default to where bash is usually installed.
}
}
return new ShellExecution(config.displayCommand, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much Much Simpler than before! 👍

cwd: config.cwd,
executable: bashPath,
shellArgs: [
'-l',
'-c',
`${config.program.replace(/ /g, '\\ ')} ${config.args.join(' ')}`,
],
shellArgs: [config.program, ...config.args],
});
}