Set initial command #14439

Closed
opened 2026-01-31 04:10:24 +00:00 by claunia · 6 comments
Owner

Originally created by @Wobbegong3 on GitHub (Jul 9, 2021).

Description of the new feature/enhancement

Proposed technical implementation details (optional)

Originally created by @Wobbegong3 on GitHub (Jul 9, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 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 <!-- 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) <!-- A clear and concise description of what you want to happen. -->
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-FixResolution-Won't-Fix labels 2026-01-31 04:10:24 +00:00
Author
Owner

@Wobbegong3 commented on GitHub (Jul 9, 2021):

I would really like it if there was a way (perhaps in Settings -> choose profile -> General) to specify a command to be executed when that profile is initially opened. Ideally this command would be stored in the command history for that profile (so that pressing the up-arrow key will allow it to be executed again).

@Wobbegong3 commented on GitHub (Jul 9, 2021): I would really like it if there was a way (perhaps in Settings -> choose profile -> General) to specify a command to be executed when that profile is initially opened. Ideally this command would be stored in the command history for that profile (so that pressing the up-arrow key will allow it to be executed again).
Author
Owner

@zadjii-msft commented on GitHub (Jul 9, 2021):

Please refer to the docs

image

@zadjii-msft commented on GitHub (Jul 9, 2021): Please refer to [the docs](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-general#command-line) ![image](https://user-images.githubusercontent.com/18356694/125099307-80c7d800-e09d-11eb-8021-17f161de6f65.png)
Author
Owner

@DHowett commented on GitHub (Jul 9, 2021):

I think the request is more for adding a command that gets emitted directly into the shell after startup, such that it is present in history and stuff. We've so far opted not to support that, because there is no generic way to tell an application what to do after it's started. As an example...

If we supported firstCommand, what does it mean when you do this?

"commandline": "vim.exe",
"firstCommand": "cd c:\; dir"

??? We would probably send the characters c d \ ... into vim, which would almost certainly not do what you're expecting. Further, that example is already broken for cmd:

"commandline": "cmd.exe",
"firstCommand": "cd c:\; dir"
                       ^ oops, cmd doesn't use ; as a command separator!

At the end of the day, it would have to become a configuration option for "characters to yell into the shell when it starts up." That might work for some use cases, but I think it'd be more trouble than it's worth for the rest. You can start with a specific command in a number of ways-

pwsh -noexit -c Cool-Command

cmd /k /s cool_command

bash -c "cool_command ; exec bash -l -i"

In every case, we're leveraging the shell's natural ability to run commands on its own 😄

@DHowett commented on GitHub (Jul 9, 2021): I think the request is more for adding a command that gets emitted directly into the shell after startup, such that it is present in history and stuff. We've so far opted **not** to support that, because there is no generic way to tell an application what to do after it's started. As an example... If we supported `firstCommand`, what does it mean when you do this? ``` "commandline": "vim.exe", "firstCommand": "cd c:\; dir" ``` ??? We would probably send the characters `c` `d` ` ` `\` ... into vim, which would almost certainly not do what you're expecting. Further, that example is already broken for cmd: ``` "commandline": "cmd.exe", "firstCommand": "cd c:\; dir" ^ oops, cmd doesn't use ; as a command separator! ``` At the end of the day, it would have to become a configuration option for "characters to yell into the shell when it starts up." That might work for some use cases, but I think it'd be more trouble than it's worth for the rest. You can start with a specific command in a number of ways- `pwsh -noexit -c Cool-Command` `cmd /k /s cool_command` `bash -c "cool_command ; exec bash -l -i"` In every case, we're leveraging the shell's natural ability to run commands on its own :smile:
Author
Owner

@Wobbegong3 commented on GitHub (Jul 9, 2021):

I understand that there would be limitations to the sort of commands that
could be handled in this way. But, in my case, the only commands that I
would be executing would be BAT scripts that execute GAWK scripts that
simply read one or more input files (usually .txt or .csv files that get
written by other processes) and generate some output and exit. How about
if you limit what "firstcommand" can be to a .BAT", .CMD, or something
similar and throw an error for anything else?

@Wobbegong3 commented on GitHub (Jul 9, 2021): I understand that there would be limitations to the sort of commands that could be handled in this way. But, in my case, the only commands that I would be executing would be BAT scripts that execute GAWK scripts that simply read one or more input files (usually .txt or .csv files that get written by other processes) and generate some output and exit. How about if you limit what "firstcommand" can be to a .BAT", .CMD, or something similar and throw an error for anything else?
Author
Owner

@Wobbegong3 commented on GitHub (Jul 9, 2021):

Mike,

The "Command Line" that you have circled is (in this case) really just a
command shell. What I was asking for was a way to specify the initial
command to be executed within that shell, and then be able to execute that
command over and over again simply by pressing and .

Peter

@Wobbegong3 commented on GitHub (Jul 9, 2021): Mike, The "Command Line" that you have circled is (in this case) really just a command shell. What I was asking for was a way to specify the initial command to be executed within that shell, and then be able to execute that command over and over again simply by pressing <Up-Arrow> and <Enter>. Peter
Author
Owner

@cmidkiff87 commented on GitHub (Sep 1, 2021):

Edit: I didn't read

... it would have to become a configuration option for "characters to yell into the shell when it starts up." ... but I think it'd be more trouble than it's worth for the rest.


Perhaps sending keystrokes to the shell?

In my case, what I want is to have my dev environment automatically run my front and back ends in their own terminals (something like)

wt \
  new-tab -p "Git Bash" -d /path/to/back/end  --keystrokes "dotnet{SPACE}run{SPACE}--project{SPACE}proj/dir{ENTER}" \
  new-tab -p "Git Bash" -d /path/to/front/end --keystrokes "npm{SPACE}run{SPACE}dev"
wt \
  new-tab -p "Git Bash" -d /path/to/back/end \
  new-tab -p "Git Bash" -d /path/to/front/end

which would launch two terminals, each with two tabs pointing to the front and back end, and one terminal which has already launched the application.

Then, if I need to restart the application, I can still ctrl + c and up + enter


The work around for me is to open wt in python (pywinauto), and then send keystrokes via copy + paste (pyperclip).
It's kludgey and subject to race conditions, but that's the best work around so far

@cmidkiff87 commented on GitHub (Sep 1, 2021): Edit: I didn't read >... it would have to become a configuration option for "characters to yell into the shell when it starts up." ... but I think it'd be more trouble than it's worth for the rest. --- Perhaps sending keystrokes to the shell? In my case, what I want is to have my dev environment automatically run my front and back ends in their own terminals (something like) ```sh wt \ new-tab -p "Git Bash" -d /path/to/back/end --keystrokes "dotnet{SPACE}run{SPACE}--project{SPACE}proj/dir{ENTER}" \ new-tab -p "Git Bash" -d /path/to/front/end --keystrokes "npm{SPACE}run{SPACE}dev" wt \ new-tab -p "Git Bash" -d /path/to/back/end \ new-tab -p "Git Bash" -d /path/to/front/end ``` which would launch two terminals, each with two tabs pointing to the front and back end, and one terminal which has already launched the application. Then, if I need to restart the application, I can still `ctrl + c` and `up + enter` --- The work around for me is to open `wt` in python (pywinauto), and then send keystrokes via copy + paste (pyperclip). It's kludgey and subject to race conditions, but that's the best work around so far
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14439