-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
116 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
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,30 @@ | ||
import { exec } from 'child_process'; | ||
import { getShellPath } from '../utils'; | ||
import { Logger } from '../helpers'; | ||
|
||
/** | ||
* Evaluate the command dynamically using `which` command | ||
* @param command | ||
* @returns | ||
*/ | ||
export const evaluateCommand = (command: string): Promise<string> => { | ||
const shell = getShellPath(); | ||
let shellPath: string | undefined = undefined; | ||
if (typeof shell !== 'string' && !!shell) { | ||
shellPath = shell.path; | ||
} else { | ||
shellPath = shell || undefined; | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
exec(`which ${command}`, { shell: shellPath }, (error, stdout) => { | ||
if (error) { | ||
Logger.error(`Error evaluating command: ${command}`); | ||
reject(error); | ||
return; | ||
} | ||
|
||
resolve(stdout.trim()); | ||
}); | ||
}); | ||
}; |
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,36 @@ | ||
import { workspace } from 'vscode'; | ||
import { ShellSetting } from '../models'; | ||
import { getPlatform } from './getPlatform'; | ||
|
||
/** | ||
* Retrieves the shell path configuration based on the current platform and terminal settings. | ||
* | ||
* This method checks for the following configurations in order: | ||
* 1. `integrated.automationProfile.<platform>`: Returns the automation profile if it exists. | ||
* 2. `integrated.defaultProfile.<platform>` and `integrated.profiles.<platform>`: Returns the shell setting from the default profile if it exists. | ||
* 3. `integrated.shell.<platform>`: Returns the shell setting if the above configurations are not found. | ||
* | ||
* @returns {string | ShellSetting | undefined} The shell path configuration or undefined if not found. | ||
*/ | ||
export const getShellPath = (): string | ShellSetting | undefined => { | ||
const platform = getPlatform(); | ||
const terminalSettings = workspace.getConfiguration('terminal'); | ||
|
||
const automationProfile = terminalSettings.get<string | ShellSetting>( | ||
`integrated.automationProfile.${platform}` | ||
); | ||
if (!!automationProfile) { | ||
return automationProfile; | ||
} | ||
|
||
const defaultProfile = terminalSettings.get<string>(`integrated.defaultProfile.${platform}`); | ||
const profiles = terminalSettings.get<{ [prop: string]: ShellSetting }>( | ||
`integrated.profiles.${platform}` | ||
); | ||
|
||
if (defaultProfile && profiles && profiles[defaultProfile]) { | ||
return profiles[defaultProfile]; | ||
} | ||
|
||
return terminalSettings.get(`integrated.shell.${platform}`); | ||
}; |
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