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: Provide cwd for che terminal creation #384

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
31 changes: 29 additions & 2 deletions code/extensions/che-terminal/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2022 Red Hat, Inc.
* Copyright (c) 2022-2024 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -44,7 +44,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<Api> {

// containerName is undefined in case the user closed the QuickPick
if (containerName) {
const pty = new MachineExecPTY(machineExecClient, containerName);
const cwd = await getCurrentWorkingDirectory();
const pty = new MachineExecPTY(machineExecClient, containerName, undefined, cwd);
const terminal = vscode.window.createTerminal({ name: `${containerName} container`, pty });
terminal.show();
}
Expand Down Expand Up @@ -127,3 +128,29 @@ export class MachineExecPTY implements vscode.Pseudoterminal {

export function deactivate(): void {
}

/**
* Provides current working directory for a terminal creation.
*
* @returns:
* - value of the PROJECTS_ROOT env variable if there is no any workspace folder
* - path to a folder if there is only one workspace folder
* - IDE proposes an user to select a folder if there is more then 1 workspace folder,
* current function returns path to the selected folder
*/
async function getCurrentWorkingDirectory(): Promise<string | undefined> {
const folders = vscode.workspace.workspaceFolders;
if (folders === undefined || folders.length < 1) {
return process.env.PROJECTS_ROOT as string;
}

if (folders.length === 1) {
return folders[0].uri.path
}

const options = {
placeHolder: "Select current working directory for new terminal"
vitaliy-guliy marked this conversation as resolved.
Show resolved Hide resolved
};
const workspace: vscode.WorkspaceFolder = await vscode.commands.executeCommand('_workbench.pickWorkspaceFolder', [options]);
return workspace.uri.path;
}
Loading