Auto Script on Shell Open
A Visual Studio Code extension that automatically executes user-configured scripts when a new terminal is created. This is useful for automatically setting up your terminal environment for each project.
Features
- Automatically executes configured scripts whenever a new terminal is created
- Works with both user-created terminals and terminals created by other extensions
- Project-specific configuration through
.vscode/auto-script-on-shell-open.json
- Supports platform-specific scripts (Windows/Linux/macOS)
- Shell-specific script execution
- Environment variable configuration
- Script execution order control
- Respects VS Code's terminal creation options (e.g., skips hidden terminals)
Usage
- Create a
.vscode/auto-script-on-shell-open.json
file in your project root:
{
"version": "1.0.0",
"env": {
"PROJECT_ROOT": "${workspaceFolder}"
},
"scripts": [
{
"command": "echo 'Setting up development environment...'"
}
]
}
- The configured scripts will automatically run whenever a new terminal is created in your workspace.
Configuration Examples
Basic Configuration
{
"version": "1.0.0",
"scripts": [
{
"command": "source ./env/bin/activate"
}
]
}
{
"version": "1.0.0",
"scripts": [
{
"command": "source ./env/bin/activate",
"platforms": ["darwin", "linux"]
},
{
"command": ".\\env\\Scripts\\activate.bat",
"platforms": ["win32"]
}
]
}
Shell-Specific Scripts
{
"version": "1.0.0",
"scripts": [
{
"command": "source ~/.zshrc",
"shell": "zsh"
},
{
"command": "source ~/.bashrc",
"shell": "bash"
},
{
"command": "$PROFILE | Invoke-Expression",
"shell": "powershell"
}
]
}
Environment Variables and Script Order
{
"version": "1.0.0",
"env": {
"WORKSPACE_ROOT": "${workspaceFolder}",
"NODE_ENV": "development"
},
"scripts": [
{
"command": "nvm use",
"order": 1
},
{
"command": "npm install",
"order": 2,
"env": {
"NPM_CONFIG_PRODUCTION": "false"
}
}
]
}
Configuration Schema
Root Configuration
Property |
Type |
Required |
Description |
version |
string |
Yes |
Configuration format version (currently "1.0.0") |
scripts |
ScriptConfig[] |
Yes |
Array of script configurations |
env |
object |
No |
Global environment variables |
Script Configuration
Property |
Type |
Required |
Description |
command |
string |
Yes |
The command to execute |
platforms |
string[] |
No |
Target platforms ("win32", "darwin", "linux") |
shell |
string |
No |
Target shell ("bash", "zsh", "powershell", etc.) |
env |
object |
No |
Script-specific environment variables |
order |
number |
No |
Execution order (lower numbers run first) |
Backward Compatibility
For backward compatibility with version 0.0.1, the extension still supports the legacy configuration format:
{
"script": "source ./env/bin/activate"
}
However, it's recommended to migrate to the new format for access to the new features.
Requirements
- Visual Studio Code version 1.96.0 or higher
Known Issues
- The script execution has a small delay (500ms) after terminal creation to ensure the terminal is ready to receive commands
- Scripts are executed in the terminal's default shell, so ensure your scripts are compatible with the shell being used
Release Notes
1.0.0
Major update:
- Multi-script support with execution order
- Platform-specific script configuration
- Shell-specific script configuration
- Environment variable support
- Improved error handling and feedback
0.0.1
Initial release:
- Basic functionality to execute scripts on terminal creation
- Project-specific configuration through JSON file