randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.39k stars 81 forks source link

Powershell/CMD not expanding environment variables #248

Open LuminousPath opened 3 years ago

LuminousPath commented 3 years ago

When I try and start up a powershell session via Terminus, I try and pass in a custom powershell profile like I normally do when using windows terminal. However, the command line variables don't seem to be expanding. So the following error code occurs:

The argument '%USERPROFILE%/Documents/WindowsPowershell/Microsoft.Powershell_Programming_profile.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.    
Windows PowerShell                                                                                                                                                                                                                 
Copyright (C) Microsoft Corporation. All rights reserved.                                                                                                                                                                          

Try the new cross-platform PowerShell https://aka.ms/pscore6                                                                                                                                                                       
process is terminated with return code 4294770688.

the current settings I'm using are:

{
  "theme": "default",
  "default_config": {
    "windows": "PowerShell"
  },
  "shell_configs": [
    {
      "name": "PowerShell",
      "cmd": ["powershell.exe", "-NoLogo", "-NoExit", "-File", "%USERPROFILE%/Documents/WindowsPowershell/Microsoft.Powershell_Programming_profile.ps1"],
      "env": {},
      "enable": true,
      "platforms": ["windows"]
    }
  ]
}

I saw in #88 that someone had fixed it by explicitly setting their environment variables, but that didn't seem to do anything.

Is there a particular way that Terminus calls cmd.exe? I would think it uses the same mechanism that sublime uses in its build system...

randy3k commented 3 years ago

Instead of cmd, you might want to use shell_cmd. My guess is that cmd prevents the environmental variable interpolation. See https://forum.sublimetext.com/t/shell-cmd-stopped-working/48792

LuminousPath commented 3 years ago

I don't think the shell_cmd key is available? I get this error in the console when I try and open a new terminal with shell_cmd instead of cmd:

Unable to open <Sublime_Text_Install_Loc>/Data/Packages/Terminus/Terminus.sublime-settings
Traceback (most recent call last):
  File "<Sublime_Text_Install_Loc>\Data\Installed Packages\Terminus.sublime-package\terminus/core.py", line 98, in <lambda>
  File "<Sublime_Text_Install_Loc>\Data\Installed Packages\Terminus.sublime-package\terminus/core.py", line 149, in run_async
KeyError: 'cmd'
LuminousPath commented 3 years ago

Popping open the error line:

https://github.com/randy3k/Terminus/blob/71e5accfcb8bde3b701ec8d7cee7858b167f9fb5/terminus/core.py#L148-L149

I feel like this line might need a guard against only shell_cmd existing in config

randy3k commented 3 years ago

Oh, you are right. We don't respect shell_cmd in config, only as a parameter passed by the build system.

LuminousPath commented 3 years ago

Added a PR that fixes it by assigning cmd and shell_cmd the values from config before the rest of the checks occur