I have a remote machine with a .bashrc
file.
I tried logging in using the Remote Development extension from VSCode, but the first thing I noticed was that the .bashrc
wasn't loaded in the terminal.
At first, I thought the problem was the one described here.
I tried editing those files, but it didn't help.
I noticed that the startup command is
/bin/bash '--init-file' '/root/.vscode-server/bin/ddc367ed5c8936efe395cffeec279b04ffd7db78/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration-bash.sh'
and I figured out that inside >Preferences: Open Remote Settings
there's this one entry called Terminal > Integrated > Shell integration: Enabled
.
I disabled it and the command became just
/bin/bash
I tried to modify setting.json
, which originally had
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash",
},
and I edited it as follows
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash",
"args": [ "l" ]
},
as I discovered that .bashrc
is only run if we're using a login terminal.
Still the problem persists, it seems like the Remote terminal ignores the general settings in setting.json
I haven't found any other setting in VSCode that could help me.
I also tried as suggested here, but it didn't work neither since the instruction is ignored.
Note: the setting.json
file I was editing was given by the command >Preferences: Open User Settings (JSON)
In the file you can find the following code
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
},
"zsh": {
"path": "zsh"
},
"fish": {
"path": "fish"
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
}
}
I added a new profile:
"bash (2)": {
"path": "/bin/bash",
"icon": "terminal-bash",
"args": ["--login"]
}
When connecting to the remote machine, the default profile can be selected
Then, a drop-down menu will appear on the top bar showing all the possible profiles
As expected, the "bash (2)" profile appears with the correct argument.
When launching again the shell, hovering over its icon should display the launch command
which is what we wanted.
Unfortunately, this didn't solve my problem: the .bashrc
file wasn't run since the new shell was launched as 'root' user, not as 'ubuntu' user (for which I defined the bashrc file)
To solve this, I simply run >Dev Containers: Open Container Configuration File
and edited as follows
{
"remoteUser": "ubuntu",
"workspaceFolder": "/home/ubuntu",
"settings": {
"terminal.integrated.shellIntegration.enabled": false
}
}
This solved my problem.
Edit: found out that if you run the shell with --login
argument, only .bash-profile
and .profile
are executed.
To solve this, simply remove the --login
argument or choose the default bash profile.
What solved the problem was indeed the different user with which the shell was launched ('ubuntu' over 'root')