formulahendry / vscode-terminal

Terminal for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=formulahendry.terminal
46 stars 22 forks source link

Is there a way to run a .bashrc file or similar on startup? #4

Closed MattMcFarland closed 8 years ago

MattMcFarland commented 8 years ago

Hi, great extension!!!

Just as I put in the subject, is there any way that we can configure this extension to run a .bashrc file when a new terminal instance is created?

formulahendry commented 8 years ago

Hi @MattMcFarland , sorry I am not quite familiar with the .bashrc file. After some investigation, maybe you could try this extension: Code Runner (It is superset of the Terminal extension since it not only supports powershell, bat/cmd, bash/sh but also supports other script language like js, php, python, perl, ruby, go, lua, groovy even F#, C#). Moreover, unlike this Terminal extension to run command directly of each line one by one, It would execute shellscript (bash/sh) with bash command. You may also override the code-runner.executorMap to specify the bashrc file like below. But I am not sure whether it will work since the current way to run script is non-interactive. Or maybe bash --login to execute /etc/profile?

{
    "code-runner.executorMap": {
        "shellscript": "bash --rcfile path/to/rcfile"
    }
}

Or, if you just want to do something before running the shell script, you could set the config like below

{
    "code-runner.executorMap": {
        "shellscript": "echo before run; bash"
    }
}
MattMcFarland commented 8 years ago

Thanks for the reply! The .bashrc file just sets up the terminal environment when you start it. It is commonly used to set the prompt and environment variables. Do you know if there is an easy way to execute a command at start? "source .bashrc" - or something? I think that would be a nice addition to mac / linux users.

formulahendry commented 8 years ago

Hi @MattMcFarland , sorry currently this Terminal extension does not support this function but there are two other alternatives for your requirement:

danlafreniere commented 6 years ago

I know this was closed but I wanted to comment in case my solution helps anyone else. I did a work-around where I forced the integrated terminal to run as a login shell (sources bash_profile) and then within bash_profile I source bashrc.

First within your VSCode user settings file add:

"terminal.integrated.shellArgs.osx": [ "-l" ]

which will force the login shell to run.

Then add this to your .bash_profile file in root:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

This serves to basically give us the same config for login and non-login shells. See: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html