Feature Request: add #4120

Closed
opened 2026-01-30 23:38:40 +00:00 by claunia · 10 comments
Owner

Originally created by @aster94 on GitHub (Sep 28, 2019).

Description of the new feature/enhancement

Add ability to open new tabs that run one (or more) custom command before the opening

Proposed technical implementation details (optional)

In the profile.json add add a new field, for example commands:

{
            "acrylicOpacity" : 0.5,
            "background" : "#012456",
            "closeOnExit" : true,
            "colorScheme" : "Campbell",
            "commandline" : "powershell.exe",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 10,
            "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "historySize" : 9001,
            "icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
            "name" : "Conda",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true,
            "commands": ["$env:Path += ";PathToConda""]
}

where commands are the commands that the terminal will execute before opening the new tab, in the example it will add the path to conda to the environmental path for the session

a dirty image of what i am talking about

terminal

Originally created by @aster94 on GitHub (Sep 28, 2019). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Add ability to open new tabs that run one (or more) custom command before the opening <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) In the profile.json add add a new field, for example `commands`: ``` { "acrylicOpacity" : 0.5, "background" : "#012456", "closeOnExit" : true, "colorScheme" : "Campbell", "commandline" : "powershell.exe", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "fontFace" : "Consolas", "fontSize" : 10, "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "historySize" : 9001, "icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png", "name" : "Conda", "padding" : "0, 0, 0, 0", "snapOnInput" : true, "startingDirectory" : "%USERPROFILE%", "useAcrylic" : true, "commands": ["$env:Path += ";PathToConda""] } ``` where `commands` are the commands that the terminal will execute before opening the new tab, in the example it will add the path to conda to the environmental path for the session a dirty image of what i am talking about ![terminal](https://user-images.githubusercontent.com/21184718/65813366-a9d2ed80-e1d4-11e9-822f-1200adc100ed.png) <!-- A clear and concise description of what you want to happen. -->
claunia added the Issue-FeatureResolution-By-DesignNeeds-Tag-Fix labels 2026-01-30 23:38:40 +00:00
Author
Owner

@fpqc commented on GitHub (Sep 28, 2019):

I don't understand. Isn't this already possible using a commandline like this (ignoring the problems with escaping the quotation marks):

set "PATH=<PathToConda>;%PATH%" & powershell.exe
@fpqc commented on GitHub (Sep 28, 2019): I don't understand. Isn't this already possible using a commandline like this (ignoring the problems with escaping the quotation marks): ``` set "PATH=<PathToConda>;%PATH%" & powershell.exe ```
Author
Owner

@aabounegm commented on GitHub (Sep 29, 2019):

@fpqc, might be for the simple example of setting and environment variable, but sometimes more complex commands are needed. For example, I want to have a profile for ROS where I run these commands once the tab opens:

source /opt/ros/melodic/setup.bash
export DISPLAY=:0

or even a script stored in the startingDirectory or anywhere else (because I don't want to run these commands for all Ubuntu shells, just ROS). I basically run ROS on WSL, so the commandline is just wsl.exe -d Ubuntu-18.04, and I couldn't find a way to run a command on WSL and keep it running. This commands option would be really helpful.

@aabounegm commented on GitHub (Sep 29, 2019): @fpqc, might be for the simple example of setting and environment variable, but sometimes more complex commands are needed. For example, I want to have a profile for ROS where I run these commands once the tab opens: ```bash source /opt/ros/melodic/setup.bash export DISPLAY=:0 ``` or even a script stored in the `startingDirectory` or anywhere else (because I don't want to run these commands for all Ubuntu shells, just ROS). I basically run ROS on WSL, so the `commandline` is just `wsl.exe -d Ubuntu-18.04`, and I couldn't find a way to run a command on WSL and keep it running. This `commands` option would be really helpful.
Author
Owner

@fpqc commented on GitHub (Sep 29, 2019):

@aabounegm It can be done by setting it in your .bashrc or .zshrc if you need to set up something complicated. Bash and I think zsh support loading --rcfile which lets you load a different rcfile for a different environment.

So in that example, you'd set up a file called ~/ros.bashrc and then set the commandline as
wsl.exe -d Ubuntu-18.04 bash --rcfile ~/ros.bashrc

Here's how you'd do that if your shell is zsh
wsl.exe -d Ubuntu-18.04 zsh --rcs ~/ros.zshrc

@fpqc commented on GitHub (Sep 29, 2019): @aabounegm It can be done by setting it in your .bashrc or .zshrc if you need to set up something complicated. Bash and I think zsh support loading `--rcfile` which lets you load a different rcfile for a different environment. So in that example, you'd set up a file called `~/ros.bashrc` and then set the commandline as ``wsl.exe -d Ubuntu-18.04 bash --rcfile ~/ros.bashrc`` Here's how you'd do that if your shell is zsh ``wsl.exe -d Ubuntu-18.04 zsh --rcs ~/ros.zshrc``
Author
Owner

@aabounegm commented on GitHub (Sep 30, 2019):

@fpqc Thank you for the suggestion. I didn't think about running bash as the command passed to wsl 😅. It works well, except that I lost colors. I'll try to find out why.

Edit: I just needed to add . ~/.bashrc to my custom rcfile to run the default config!

@aabounegm commented on GitHub (Sep 30, 2019): @fpqc Thank you for the suggestion. I didn't think about running `bash` as the command passed to wsl 😅. It works well, except that I lost colors. I'll try to find out why. **Edit**: I just needed to add `. ~/.bashrc` to my custom rcfile to run the default config!
Author
Owner

@DHowett-MSFT commented on GitHub (Sep 30, 2019):

Since Terminal can't really know--or hope to know--what shell you're using, we're not going to add an "initial commands" feature. It's far more extensible to do this in your shell profile (~/.bashrc, Documents\PowerShell\profile.ps1), and you gain the benefit of being able to check that into source control and use complicated logic in it. It's way, way better than "make the terminal pop some commands into the input stream on startup."

@DHowett-MSFT commented on GitHub (Sep 30, 2019): Since Terminal can't really know--or hope to know--what shell you're using, we're not going to add an "initial commands" feature. It's far more extensible to do this in your shell profile (`~/.bashrc`, `Documents\PowerShell\profile.ps1`), and you gain the benefit of being able to check that into source control and use complicated logic in it. It's way, way better than "make the terminal pop some commands into the input stream on startup."
Author
Owner

@aster94 commented on GitHub (Oct 1, 2019):

I don't understand. Isn't this already possible using a commandline like this (ignoring the problems with escaping the quotation marks):

set "PATH=<PathToConda>;%PATH%" & powershell.exe

Not working:
"commandline" : "set `"PATH=C:/Users/vincenzo/.platformio/penv/Scripts;%PATH%`" & powershell.exe",

nor

"commandline" : "set ""PATH=C:/Users/vincenzo/.platformio/penv/Scripts;%PATH%"" & powershell.exe",
nor

"commandline" : "set \"PATH=C:/Users/vincenzo/.platformio/penv/Scripts;%PATH%\" & powershell.exe",

@aster94 commented on GitHub (Oct 1, 2019): > I don't understand. Isn't this already possible using a commandline like this (ignoring the problems with escaping the quotation marks): > > ``` > set "PATH=<PathToConda>;%PATH%" & powershell.exe > ``` Not working: ```"commandline" : "set `"PATH=C:/Users/vincenzo/.platformio/penv/Scripts;%PATH%`" & powershell.exe",``` nor `"commandline" : "set ""PATH=C:/Users/vincenzo/.platformio/penv/Scripts;%PATH%"" & powershell.exe", ` nor `"commandline" : "set \"PATH=C:/Users/vincenzo/.platformio/penv/Scripts;%PATH%\" & powershell.exe",`
Author
Owner

@zadjii-msft commented on GitHub (Oct 1, 2019):

maybe try

            "commandline": "%comspec% /k cmd.exe /c \"set PATH=\"foo;%PATH%\" && powershell.exe\"",

which is going to get cmd to call cmd to process a commandline, and that commandline is going to set the PATH and launch powershell

@zadjii-msft commented on GitHub (Oct 1, 2019): maybe try ``` "commandline": "%comspec% /k cmd.exe /c \"set PATH=\"foo;%PATH%\" && powershell.exe\"", ``` which is going to get cmd to call cmd to process a commandline, and that commandline is going to set the `PATH` and launch powershell
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 1, 2019):

Or, just have a powershell profile.ps1 that sets up the way you'd like your shell to act?

@DHowett-MSFT commented on GitHub (Oct 1, 2019): Or, just have a powershell `profile.ps1` that sets up the way you'd like your shell to act?
Author
Owner

@aster94 commented on GitHub (Oct 1, 2019):

@DHowett that would be indeed the best solution, but i need to have different path added and i would like to avoid to have all together. I mean that sometimes i need a powershell windows that has the path to conda, other times one that has a path to a different command

I know i can do in profile.ps1

$Env:Path += ";<path_1>;<path_2>"

where path_1 and path_2 are the two target path but i would like to have them separated, and honestly i don't know how to load only one of these

@aster94 commented on GitHub (Oct 1, 2019): @DHowett that would be indeed the best solution, but i need to have different path added and i would like to avoid to have all together. I mean that sometimes i need a powershell windows that has the path to conda, other times one that has a path to a different command I know i can do in `profile.ps1` `$Env:Path += ";<path_1>;<path_2>"` where `path_1` and `path_2` are the two target path but i would like to have them separated, and honestly i don't know how to load only one of these
Author
Owner

@aster94 commented on GitHub (Oct 6, 2019):

I also found that this would works good:
"commandline": "powershell.exe -noExit -Command \"& {$Env:Path += '\";C:/Users/vincenzo/Miniconda3/Scripts\"'}\"",

@aster94 commented on GitHub (Oct 6, 2019): I also found that this would works good: `"commandline": "powershell.exe -noExit -Command \"& {$Env:Path += '\";C:/Users/vincenzo/Miniconda3/Scripts\"'}\"",`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4120