Skip to content

Commit 22148db

Browse files
committed
Make bash PATH injection a little more robust on Linux
1 parent 166ae8b commit 22148db

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/interceptors/fresh-terminal.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,17 @@ ${END_CONFIG_SECTION}`;
235235
const editShellStartupScripts = async () => {
236236
await resetShellStartupScripts();
237237

238+
// The key risk here is that one of these scripts (or some other process) will be
239+
// overriding PATH itself, so we need to append some PATH reset logic. The main
240+
// offenders are: nvm config's in .bashrc/.bash_profile, OSX's path_helper and
241+
// git-bash ignoring the inherited $PATH.
242+
238243
// .profile is used by Dash, Bash sometimes, and by Sh:
239244
appendOrCreateFile(path.join(os.homedir(), '.profile'), SH_SHELL_PATH_CONFIG)
240245
.catch(reportError);
241246

242-
// Bash uses some other files by preference, if they exist:
247+
// Bash login shells use some other files by preference, if they exist.
248+
// Note that on OSX, all shells are login - elsewhere they only are at actual login time.
243249
appendToFirstExisting(
244250
[
245251
path.join(os.homedir(), '.bash_profile'),
@@ -249,6 +255,15 @@ const editShellStartupScripts = async () => {
249255
SH_SHELL_PATH_CONFIG
250256
).catch(reportError);
251257

258+
// Bash non-login shells use .bashrc, if it exists:
259+
appendToFirstExisting(
260+
[
261+
path.join(os.homedir(), '.bashrc')
262+
],
263+
SHELL === 'bash', // If you use bash, we _always_ want to set this
264+
SH_SHELL_PATH_CONFIG
265+
).catch(reportError);
266+
252267
// Zsh has its own files (both are actually used)
253268
appendToFirstExisting(
254269
[

0 commit comments

Comments
 (0)