-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Roman Nikitenko <[email protected]>
- Loading branch information
1 parent
b3530c3
commit 4839988
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
/* eslint-disable header/header */ | ||
|
||
import * as vscode from 'vscode'; | ||
import * as cp from 'child_process'; | ||
|
||
const TERMINAL_SECTION_ID = 'terminal'; | ||
const LINUX_DEFAULT_PROFILE_ID = 'integrated.defaultProfile.linux'; | ||
const WARNING_MESSAGE = 'Default terminal profile is not configured, you can try sh profile as default or select another profile in settings'; | ||
const SH_AS_DEFAULT = 'Use sh as default profile'; | ||
const OPEN_SETTINGS = 'Open Settings'; | ||
|
||
export async function resolveTerminalProfile(outputChannel: vscode.OutputChannel): Promise<void> { | ||
const shellOutput = cp.execSync('echo ${SHELL}') || ''; | ||
const shellValue = shellOutput.toString(); | ||
outputChannel.appendLine(`echo $SHELL: ${shellValue}`); | ||
|
||
const shellEnvVar = process.env.SHELL; | ||
outputChannel.appendLine(`SHELL env variable: ${shellEnvVar}`); | ||
|
||
const terminalConfig = vscode.workspace.getConfiguration(TERMINAL_SECTION_ID); | ||
const defaultProfile = terminalConfig.get<string>(LINUX_DEFAULT_PROFILE_ID); | ||
outputChannel.appendLine(`Default terminal profile: ${defaultProfile}`); | ||
|
||
if ((!shellValue || shellValue.includes('nologin')) && !defaultProfile) { | ||
outputChannel.appendLine('Default terminal profile is not configured'); | ||
return suggestProfileResolving(terminalConfig, outputChannel); | ||
} | ||
} | ||
|
||
async function suggestProfileResolving(terminalConfig: vscode.WorkspaceConfiguration, outputChannel: vscode.OutputChannel): Promise<void> { | ||
const selected = await vscode.window.showWarningMessage(WARNING_MESSAGE, OPEN_SETTINGS, SH_AS_DEFAULT); | ||
outputChannel.appendLine(`${selected} was selected for resolving default terminal profile`); | ||
|
||
if (selected === OPEN_SETTINGS) { | ||
vscode.commands.executeCommand('workbench.action.openSettings2', { query: `${TERMINAL_SECTION_ID}.${LINUX_DEFAULT_PROFILE_ID}` }); | ||
} else if (selected === SH_AS_DEFAULT) { | ||
terminalConfig.update(LINUX_DEFAULT_PROFILE_ID, 'sh', false); | ||
} | ||
} |