VSCode: How to run a command after each terminal open? - vscode-extensions

On Windows I have to run the command start-ssh-agent.cmd on each new terminal session I open. My development environment is VSCode, and I open a dozen new terminals each day. After each terminal open, I have to manually run this command.
Is there is a way to run this command on the terminal each time I open one ?
This may take the form of a VSCode extension, VSCode configuration (settings) or a Windows environment configuration.
Any idea?

On Linux systems you should use:
"terminal.integrated.shellArgs.linux"
On Windows and OSX:
terminal.integrated.shellArgs.windows
and
terminal.integrated.shellArgs.osx
respectively.
If you want to apply shellArgs setting on a per-workspace basis - you can, despite the fact that documentation says:
The first time you open a workspace which defines any of these settings, VS Code will warn you and subsequently always ignore the values after that
At least version 1.42 of VSCode asks you something like:
"This workspace wants to set shellArgs, do you want to allow it?"
See issue 19758
On Linux, if you are using bash (default for shell in VSCode), there are some subtleties:
"terminal.integrated.shellArgs.linux": ["your_init_script.sh"]
will execute the script and close terminal right away. To prevent this you'll have to end the script with $SHELL command.
#!/bin/bash
echo "init"
export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
$SHELL
But that way you end up in a subshell. Sometimes it's unacceptable (Read 1) (Read 2).
"terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]
will leave you in the initial shell, but will not execute the .bashrc init file. So you may want to source ~/.bashrc inside your_init_script.sh
#!/bin/bash
source ~/.bashrc
echo "init"
export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
And if you already have some_init_script.sh in a repository, and for some reason don't feel like adding source ~/.bashrc into it, you can use this:
"terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]
your_init_script.sh:
#!/bin/bash
source ~/.bashrc
source some_init_script.sh
some_init_script.sh:
#!/bin/bash
echo "init"
export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
Outside of VSCode you can do without creating extra file. Like this
bash --init-file <(echo "source ~/.bashrc; source some_init_script.sh")
But I could not pass this string into terminal.integrated.shellArgs.linux - it needs to be split into array somehow. And none of the combinations I've tried worked.
Also, you can open terminal at a specific folder:
terminal.integrated.cwd
Change env:
"terminal.integrated.env.linux"
"terminal.integrated.env.windows"
"terminal.integrated.env.osx"
And even change terminal to your liking with
terminal.integrated.shell.linux
terminal.integrated.shell.windows
terminal.integrated.shell.osx
Or
terminal.external.linuxExec
terminal.external.osxExec
terminal.external.windowsExec

I actually found a pretty neat Linux solution for this. It should also work on Windows if you use a shell like Bash. I'm not sure if it's possible using vanilla CMD.
Add something like this to your .bashrc or .zshrc:
#
# Allow parent to initialize shell
#
# This is awesome for opening terminals in VSCode.
#
if [[ -n $ZSH_INIT_COMMAND ]]; then
echo "Running: $ZSH_INIT_COMMAND"
eval "$ZSH_INIT_COMMAND"
fi
Now, in your VSCode workspace setting, you can set an environment variable like this:
"terminal.integrated.env.linux": {
"ZSH_INIT_COMMAND": "source dev-environment-setup.sh"
}
Now the script "dev-environment-setup.sh" will be automatically sourced in all new VSCode terminal windows.

You can do the following:
"terminal.integrated.shellArgs.windows": ["start-ssh-agent.cmd"]
Modified from: https://code.visualstudio.com/docs/editor/integrated-terminal#_shell-arguments

The other answer are great but a little outdated. You will get a warning in VSCode. Here is what I'm doing in my XXX.code-workspace file on linux:
"terminal.integrated.profiles.linux": {
"BashWithStartup": {
"path": "bash",
"args": [
"--init-file",
"./terminal_startup.sh"
]
}
},
"terminal.integrated.defaultProfile.linux": "BashWithStartup"
Be sure to make sure your terminal_startup.sh script is executable:
chmod u+x terminal_startup.sh

For anyone using the wonderful cmder, you'll need something akin to the following in your settings.json
{
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "C:\\path\\to\\cmder"
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
],
}
And then you can add any aliases into the user_aliases.cmd file that should already exist in %CMDER_ROOT%\\config\\user_aliases.cmd

I use the following for powershell on Windows:
{
"terminal.integrated.shellArgs.windows": [
"-NoExit",
"-Command", "conda activate ./env"
]
}

After much trial and error, the following worked for me on OSX:
"terminal.integrated.shellArgs.osx": [
"-l",
"-c",
"source script.sh; bash"
],
For context, I'm using this with a jupyter notebook to set environment variables that cannot simply be defined using terminal.integrated.env.osx

After the April 2021 update the configuration structure has been changed.
Check the documentation.
There's a distinction even between terminal instances. To run a file on Windows:
PowerShell
{
"terminal.integrated.profiles.windows": {
"My PowerShell": {
"path": "pwsh.exe",
"args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "My PowerShell"
}
Command Prompt
{
"terminal.integrated.profiles.windows": {
"cmder": {
"path": "C:\\WINDOWS\\System32\\cmd.exe",
"args": ["/K", "C:\\cmder\\vendor\\bin\\vscode_init.cmd"]
}
},
"terminal.integrated.defaultProfile.windows": "cmder"
}

I did this for accessing x64 Native Tools Command Prompt for 2022:
{
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"x64 Native": {
"path": [
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat",
],
"icon": "terminal-cmd"
},
},
"terminal.integrated.defaultProfile.windows": "x64 Native",
}

If you use PowerShell you can add a PowerShell Script to your your profile in which you can execute what you want. Each development environment has 4 Profiles, stored in $Profile:
AllUsersAllHosts
AllUsersCurrentHost
CurrentUserAllHosts
CurrentUserCurrentHost
Eg create a profile in VSCode with
code $profile.CurrentUserAllHosts
Some more details

Related

How do I activate venv in each new terminal in a Dev Container?

I'm trying to create a devcontainer.json that will create a Python virtual environment and activate it in the terminal immediately.
I use postCreateCommand to create the environment, and that seems to work:
"postCreateCommand": "python3 -m venv .venv",
But I haven't figured out how to get the terminal to always activate it. I've tried adding this setting:
"settings": {
"python.terminal.activateEnvInCurrentTerminal": true
}
As well as post*Commands:
"postAttachCommand": ". .venv/bin/activate",
"postStartCommand": ". .venv/bin/activate",
"postCreateCommand": ". .venv/bin/activate",
They don't seem to reliably activate it. I think postAttachCommand worked sometimes, but not always.

How to change default directory in Windows Subsystem for Linux

I am setting up my development environment, so I just installed Windows Subsystem for Linux and it always seems to open a fresh terminal in my Windows home directory - /mnt/c/Users/dl and I'm trying to make it default to the linux home directory - /home/dl.
I checked to see what the home directory is in the Linux subsystem in /etc/passwd and it is correctly set:
dl:x:1000:1000:,,,:/home/dl:/bin/bash
Then I came across this solution, but it doesn't seem to have any affect:
// Set starting directory
"startingDirectory": "\\\\wsl$\\Ubuntu\\home\\dl\\"
I know I can just run cd ~ in my dot files (which is what I'm currently using), but I'm looking for a way where /home/dl is just the default and cd ~ isn't needed. Is this possible?
You should only change the startingDirectory for WSL (Ubuntu in this case) terminal sessions.
Open settings.json via CTRL+SHIFT+,
Make sure you are modifying startingDirectory under profiles/list/name: "Ubuntu"
Example below (the slashes need to be escaped):
....
{
"guid": "{2c4de342-xxx-xxx-xxx-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "\\\\wsl$\\Ubuntu\\home\\windows_username_in_lower_case"
},
....
Documentation about startingDirectory including default values and expected values.
Inside settings.json you will also find an explanation of the json schema which is here
If you need to know how or where to edit Windows Terminal settings/preferences: https://learn.microsoft.com/en-us/windows/terminal/get-started
In Windows 10 21H2 or later and Windows 11, it's now much simpler. According to the Microsoft Doc:
On newer versions of Windows, startingDirectory can accept Linux-style paths.
That means you can simply use:
"startingDirectory": "/home/yourusername"
No need for any prefixes for Windows directory structure, nor escaped backslashes. Just plain old Linux forward-slash notation.
This works in both WSL1 and WSL2.
Note: I tried to use "~" and it failed. There may be some way to use {$USERPROFILE}, but haven't tried it.
Changing the home directory with WSL is done the same way as in Linux:
Enter bash
Type the command sudo vim /etc/passwd
Find your account's line, which might look like:
shadyar:x:1000:1000:"",,,:/home/shadyar:/bin/bash
Change the home directory, which above is /home/shadyar, to the new directory, using WSL
note: If you want to set Windows directory as home directory, you need to prepend it with /mnt/, like /mnt/c for C:/, /mnt/d for D:/, etc
Save the file and exit vim by typing :wq and press Enter
Exit bash and re-launch it
To test, use the commands:
cd ~
pwd
The other answers here (especially the latest one from #TomBoland) are great for starting in an arbitrary directory, but the example in your question was to start in your home directory. The easiest way to do that is simply to create or change the "commandline" property to wsl ~. This is an undocumented flag to wsl.exe, and it must be the first argument (e.g. wsl ~ -u root).
Current and Recent Windows Terminal Releases
Since Windows Terminal now has a GUI for Settings, you can just edit your profile to point to wsl ~ in the ->General->Command Line setting.
Older Windows Terminal Releases, or if you want to edit manually
If you are editing your settings.json directly (currently found in %userprofile%\AppData\Local\Packages\MicrosoftWindowsTerminal...\LocalState\settings.json, but this may change) ...
Remove the "source" attribute and replace it with "commandline":
"guid": "{2d5ef231-38b7-51cf-b940-2309a097f644}",
"hidden": false,
"name": "Ubuntu",
//"source": "Windows.Terminal.Wsl",
"commandline": "wsl ~",
"startingDirectory": "//wsl$/Ubuntu/",
"tabTitle": "Ubuntu"
Also, for the fun of it, here's an alternative (hacky) way to open WSL to ~/$HOME (without hardcoding as with the other answers). This is absolutely not needed since it's much easier to use wsl ~, but:
wsl -e sh -c 'cd $HOME; exec $SHELL'
This starts up sh, changes the directory to $HOME, and then exec's your $SHELL to replace the sh.
Should you use Windows Terminal with WSL, then the simplest solution is to configure the starting directory via the Settings menu:
and then:
startingDirectory Should be a windows path, not a nix path. Try D:\Folder\SubFolder instead
refer this link,worked for me
github
I tried many things here and none worked but I finally found a workaround.
After opening your ubuntu, you can set the default path by editing your .bashrc file.
I personally wanted to change it from the default /home/${my_username} to my current user directory (like command prompt C:/users/${my_username}), so I just ran this in my Ubuntu terminal
echo 'cd "../../mnt/c/users/${my_username}"' >> $HOME/.bashrc
Step 1: Open windows command prompt and type "bash"
or open Linux app directly .
Step 2: Type a route which is something like this : /mnt/c/Users/HP/..(You can enter your desired directory here).
For example : /mnt/c/Users/HP/Documents , and by this you will get inside Documents.
For WSL2 Ubuntu the syntax should now match the following example in the json:
"guid": "{2d5ef231-38b7-51cf-b940-2309a097f644}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu/",
"tabTitle": "Ubuntu"
To start in /: "startingDirectory": "//wsl$/Ubuntu/",
To start in /root: "startingDirectory": "//wsl$/Ubuntu/root/",
To start in /home: "startingDirectory": "//wsl$/Ubuntu/home/",
No need to do any of that, just open up the profile for Ubuntu under settings, then update the Command line to add the following option
C:\Windows\system32\wsl.exe -d Ubuntu --cd ~

How do I get Windows 10 Terminal to launch WSL?

I'm using the new Windows Terminal, and trying to get it to launch my WSL terminal. This is the setting that I'm trying to use:
{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "%LOCALAPPDATA%/wsltty/bin/mintty.exe --WSL= --configdir='%APPDATA%/wsltty' -~ ",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "wsl",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
}
But all it's doing is opening some sort of CMD.
What's the correct command to run the WSL terminal
Edit:
I did notice that the GUID was the same thing as the regular CMD, so I changed that. Then it did launch an external shell.
You need to do following things first.
1. Install Linux (e.g. Ubuntu)
Search "Ubuntu" in the Microsoft store, then buy and install. This is actually WSL (Windows Subsystem for Linux).
Of course, you want to experience other versions of Linux, as well as Debian:
2. Enable WSL permissions
After installing the WSL version of Linux, you also need to enable WSL permissions:
Open another PowerShell window with "Run as Administrator".
Then enter the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
After the command is completed, you can execute the Linux command in the built-out Terminal.
First enter ubuntu in cmd, take a little time to start Ubuntu, set the username and password.
Then you can play with Ubuntu happily. Below I entered a few common commands such as ps, touch, ls etc., as shown below.
3. Change settings
Click "Settings" in right top corner of above image, the file profile.json file will be opened. Then inside the word "profiles" in profile.json file, add below snippet.
{
"guid": "{78e390db-1bff-4533-9d7c-20f53d8bafa1}",
"name": "WSL",
"colorscheme": "Campbell",
"historySize": 9001,
"snapOnInput": true,
"cursorColor": "#FFFFFF",
"cursorShape": "bar",
"commandline": "wsl ~",
"fontFace": "Consolas",
"fontSize": 12,
"acrylicOpacity": 0.75,
"useAcrylic": true,
"closeOnExit": false,
"padding": "0, 0, 0, 0"
}
Near the word "schemes" in profile.json file, you need to update below:
"schemes": [
{
"name": "Campbell",
"foreground": "#A7B191",
"background": "#0C0C0C",
"colors": [
"#0C0C0C",
"#C50F1F",
"#13A10E",
"#C19C00",
"#0037DA",
"#881798",
"#3A96DD",
"#CCCCCC",
"#767676",
"#E74856",
"#16C60C",
"#F9F1A5",
"#3B78FF",
"#B4009E",
"#61D6D6",
"#F2F2F2"
]
}
The complete setting file (profile.json) which can be obtained here.
Actually, the WSL here is Ubuntu.
4. Add icons to different types of tabs
You can add icons for Tab to this location:
%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState
I put some 32x32 PNG in this folder, and then in profile.json I can reference the image resource with the path starting with ms-appdata:// .
The icon is available here:
Icons
Then replace the contents of the new profile-withIcons.json file below with the previous settings.
profile-withIcons.json
After finishing the contents of the folder is like this:
The final result is:
To launch any distribution, you can also use this for commandline:
wsl.exe -d <name_of_the_distribution>
Like :
wsl.exe -d Ubuntu-18.04
You can list all distributions with :
wsl.exe -l
.
PS : Tux icon for Linux :
ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png
Turns out that all I needed to do was change the commandline to ubuntu1804.exe. Like this:
{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline": "ubuntu1804.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{0caa0dad-35be-5f56-a8ff-abceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "wsl",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
}
While my answer is off-question (since answered by the O.P.) I found this question while searching for adding a Windows Terminal (WT) profile for my recent Ubuntu installation, since I had recently re-imaged my laptop.
Updated 19/10/03: Installation order does not matter. My profile for “ubuntu” appears after installing ubuntu, and then launching the ubuntu instance in PowerShell and establish my user account and password. THEN Windows Terminal adds the appropriate shell profile for WSL.
I have developed a tool for tweaking the terminal configurations here :
Windows Terminal Tweaker 🚀⚡
It lets you add different profiles , gives color pickers to choose color schemes and provides options to tweak every single thing while applying the settings live.
Open settings
Change the "Default Profile" in the drop down.
Click "Save" on the bottom right.
Create a new profile in the windows terminal settings and select the following command line
C:\Windows\system32\wsl.exe -d Ubuntu-20.04
where -d selects the distribution to be run.
Windows Terminal allows you to open the settings and change things there. If you already have ubuntu installed, it should be an option to set the ubuntu profile as your default config.
Copy paste the guid for ubuntu into the defaultProfile and it will automatically launch WSL ubuntu instead of powershell by default.
The premise of the question was fouled by the mistake with the GUID, as the OP says the sample code was actually correct. So, the question could be re-interpreted as--
What is the minimum required change to the default settings.json to point to an application of your choosing? (which is what got me here)
guid - has to be unique. I've had success with changing just the last number for each customization.
commandline - From within Bravo Yeung's answer is a link to a sample settings.json file: "commandline": "wsl ~"
This little bitty value is made possible by setting a default distro: "The default WSL distribution is the one that runs when you run wsl on a command line:"
wsl --setdefault <DistributionName>
However, seems commandline:wsl doesn't work with startingDirectory.
I've successfully omitted commandline in favor of source + startingDirectory:
// Make changes here to the cmd.exe profile.
"guid": "{long-guid-here}",
"hidden": false,
"name": "Debian",
"tabTitle" : "WSL (Debian)",
"source": "Windows.Terminal.Wsl",
"startingDirectory" : "C:\\Users\\myuser"
Here is a good link which got me started the first time I installed Windows Terminal and customized the settings, Easily add Anaconda Prompt to Windows Terminal to make life better
Recent versions of Windows Terminal include support for Dynamic Profiles, in which new WSL distros will automatically be added to the list of available profiles.
However, if Windows Terminal is running when you install the new distro, it will not currently get added while running. You must exit and re-start Windows Terminal, and the new profile will automatically appear.
Once it is added, you can edit/move it using the Settings dialog or by editing settings.json as usual. Each WSL distro is identified using a GUID which will have been auto-populated.
As described in the linked article, Dynamic Profiles can be turned off by disabling their source(s) such as the following in settings.json:
"disabledProfileSources": ["Windows.Terminal.Wsl", "Windows.Terminal.Azure", "Windows.Terminal.PowershellCore"]

ConEmu + WSL: Open new console in current tab directory

I'm using WSL and ConEmu build 180506. I'm trying to setup a task in ConEmu to use the current directory of the active tab when opening a new console but I cannot get it to work.
What I did is to setup the task {Bash: bash} using the instructions on this page
setting the task command as :
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -C~ -cur_console:pm:/mnt
Then following the instruction on this page, I added to my .bashrc
if [[ -n "${ConEmuPID}" ]]; then
PS1="$PS1\[\e]9;9;\"\w\"\007\e]9;12\007\]"
fi
and finally setup a shortcut using the macro :
Shell("new_console", "{bash}", "", "%CD%")
But it always open the new console in the default directory ('/home/[username]').
I don't understand what I'm not doing right.
I also noticed that a lot of environment variables listed here are not set. Basically, only $ConEmuPID and $ConEmuBuild seem to be set.
Any help would be appreciated.
GuiMacro Shell was intended to run certain commands, not tasks.
You think you may try to run macro Task("{bash}","%CD%")
Or set your {bash} task parameters to -dir %CD% and just set hotkey for your task.
Of course both methods require working CD acquisition from shell. Seems like it's OK in your case - %d shows proper folder.
I found the answer:
Shell("new_console:I", "bash.exe", "", "%CD%")
The readme is actually pretty good: https://github.com/cmderdev/cmder/blob/master/README.md

Running custom script extension on deployed scale set instances

currently I'm using custom script extension to run scripts on demand on my azure vm server as part of our software solution, our other dev team is moving an application to a scale set and i am no longer capable of deploying custom script extension on demand to the scale set instances. the only solution i have found for running custom script extension on scale set instances is to reconfigure the deployment template with it, this method is not good for me as the scripts should be run on demand and are changed frequently and updating the template every time is bad practice.
Is there anyway to configure custom script extension on scale set instances on demand like on regular virtual machines?
powershell example for regular on demand script deployment on vm:
Set-AzureRmVMCustomScriptExtension -ResourceGroupName myResourceGroup `
-VMName myVM `
-Location myLocation `
-FileUri myURL `
-Run 'myScript.ps1' `
-Name DemoScriptExtension
I found a workaround for this using PowerShell and ARM JSON templates (I'm using Powershell version 5.1). In commandToExecute under virtualMachineProfile in your json template, specify a value that almost always changes and it will force the command to re-execute to run every time your template is deployed. You will see in my template that I added: ' -Date ', deployment().name to the commandToExecute. The value for deployment().name is specified in my New-AzureRmResourceGroupDeployment command as:
-Name $($(Get-Date -format "MM_dd_yyyy_HH_mm"))
The deployment name is based on the date and time, which will be different per minute.
PowerShell Command:
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $PathToJsonTemplate -TemplateParameterFile $PathToParametersFile -Debug -Name $($(Get-Date -format "MM_dd_yyyy_HH_mm")) -force
The custom script extension section under virtualMachineProfile in my script appears as such (pay attention to the commandToExecute):
"virtualMachineProfile": {
"extensionProfile": {
"extensions": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "MyExtensionName",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat(parameters('customScriptExtensionSettings').storageAccountUri, '/scripts/MyScript.ps1')]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File MyScript.ps1', ' -Date ', deployment().name)]"
},
"protectedSettings": {
"storageAccountName": "[parameters('customScriptExtensionSettings').storageAccountName]",
"storageAccountKey": "[listKeys(variables('accountid'),'2015-05-01-preview').key1]"
}
}
},
This will allow you to update a Custom Script Extension on a Virtual Machine Scale Set that has already been deployed. I hope this helps!
Is there anyway to configure custom script extension on scale set
instances on demand like on regular virtual machines?
For now, Azure does not support this.
We only can use VMSS custom script to install software at the time the scale set is provisioned.
More information about VMSS extension, please refer to this link.