terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Custom variables in settings.json for easier profile configuration

Open AlexKay88 opened this issue 5 years ago • 5 comments

Description of the new feature/enhancement

Let one define custom variables in settings.json for use with profiles. E.g. define myCustomVariable for later use within commandline to avoid adding same long path to SSH key file for every profile name. Would also be great to reuse current profile parameters such as "name" to connect to this hostname by stating $profile.name with SSH as shown in example.

Proposed technical implementation details (optional)

"profiles":
{
    "defaults":
    {
        "myCustomVariable": "C:\\Users\\USERNAME\\SSH_KEY_FILE_PATH.key"
    },
    "list":
    [
        {
            "name": "HOSTNAME",
            "commandline": "ssh -i $myCustomVariable $profile.name", 
        },

AlexKay88 avatar Feb 16 '21 13:02 AlexKay88

This isn't a terrible idea, but I'm guessing that this would not play well with the Settings UI. So this would end up being a feature that would work well if you exclusively used the json settings. I'm gonna stick this in the freezer for now. It's a reasonable request, but not one we're likely to get to anytime soon.

zadjii-msft avatar Feb 26 '21 14:02 zadjii-msft

This is dearly required feature for our company now, please take it out the freezer

I have 100s of servers we manage using Windows Terminal Example of one:

{
                "colorScheme": "Raspberry",
                "commandline": "pwsh.exe -c ssh [email protected]",
                "font": 
                {
                    "size": 10
                },
                "guid": "{5f1b74da-9684-591d-8a8a-bed6171bd000}",
                "hidden": false,
                "icon": "C:\\Scripts\\windows-terminal-icons\\icons\\ubuntu.png",
                "name": "server-01"
            },

Now every time we have a new desk agent or employee in the IT team who needs this file we have to copy to his machine and replace myusername with hisusername

Then as we are big enterprise when this file changes because we have added and removed terminal profiles we have to update everyone and its becoming a massive unpleasant time wasting chore.

How can we define at the top of the settings.json an variable for example sshusername=myusername?

and then have each profile

{
                "colorScheme": "Raspberry",
                "commandline": "pwsh.exe -c ssh ${sshusername}@server-01.domain.net",
                "font": 
                {
                    "size": 10
                },
                "guid": "{5f1b74da-9684-591d-8a8a-bed6171bd000}",
                "hidden": false,
                "icon": "C:\\Scripts\\windows-terminal-icons\\icons\\ubuntu.png",
                "name": "server-01"
            },

This way we could push the settings json file via policy to all the machines and have near zero maintenance. Below is an indication of our profiles, they are so long they don't fit on the screen

Image

ghost avatar Jan 14 '25 13:01 ghost

You may not be able to achieve exactly this today, but... it seems much better-served by:

  • ssh_config (to specify the username; configure it once per person and let it be)
  • Terminal fragment extensions, which let your organization deploy a set of JSON profiles which do not require you to edit each user's settings file

This at least prevents you from having to override everyone's settings every time you provision a new server. Plus, ssh_config supports wildcards:

Host *.domain.net
        User myusername

(as an aside: why are you launching PowerShell just to launch ssh? You can launch ssh directly.)

DHowett avatar Jan 14 '25 16:01 DHowett

You may not be able to achieve exactly this today, but... it seems much better-served by:

  • ssh_config (to specify the username; configure it once per person and let it be)
  • Terminal fragment extensions, which let your organization deploy a set of JSON profiles which do not require you to edit each user's settings file

This at least prevents you from having to override everyone's settings every time you provision a new server. Plus, ssh_config supports wildcards:

Host *.domain.net
        User myusername

(as an aside: why are you launching PowerShell just to launch ssh? You can launch ssh directly.)

I am glad you asked my example above is not entirely exactly what we are doing (some sensitive parts has been removed). But since I think this should be Okay to share in this way.

Currently I have set an environment variable some others as well which is SSHADMIN and that is set to my admin username If I drop the pwsh.exe -C The the variable doesn't expand .

Image

ghost avatar Jan 17 '25 10:01 ghost

Oh! I get it.

I think SSHADMIN will work as expected if you use the Windows shell syntax for environment variables: %SSHADMIN%.

($env: is of course PowerShell specific; % works everywhere else on Windows.)

DHowett avatar Jan 18 '25 00:01 DHowett