Feature Request - Configure Command to set launch directory for profiles #3546

Closed
opened 2026-01-30 23:23:42 +00:00 by claunia · 4 comments
Owner

Originally created by @chorman0773 on GitHub (Aug 24, 2019).

Originally assigned to: @bitcrazed on GitHub.

Description of the new feature/enhancement

I have mostly switched to using Windows Terminal (due to the ability to have all of my shells in one place), however, I primarily use cygwin bash. This has a problem that, despite the value of the
startingDirectory option in the profile (and possibly overriden by a directory option from #607), it always starts in $HOME (which expands to /home/<userdir>), rather than the cygwin equivalent of the starting directory (which for <Drive-Letter>:\<path\...> is /cygdrive/<Drive-Letter (in lowercase)>/<path/...>). I propose that to fix this, and any similar issues that may arise with other shells, it be possible (though optional), to specify a command to executed in the new shell that will switch to the starting directory.

Proposed technical implementation details (optional)

In profile settings, there is an optional field called dirCommand which can be anything. If present, the shell is started by running the shell commandline, then immediately after, the command specified by dirCommand is run by the newly started command processor, substituting each occurance of a properly named variable, say $StartingDir with the starting directory, then (possibly) removing the command from history. An example of this for cygwin bash would be

... (cygwin bash profile)
"dirCommand":"cd `cygpath $StartingDir` && exec /bin/bash"
...

If dirCommand is absent, opening the profile has the exact same effect as opening the profile currently does (without respect to dirCommand).

Originally created by @chorman0773 on GitHub (Aug 24, 2019). Originally assigned to: @bitcrazed on GitHub. # Description of the new feature/enhancement I have mostly switched to using Windows Terminal (due to the ability to have all of my shells in one place), however, I primarily use cygwin bash. This has a problem that, despite the value of the `startingDirectory` option in the profile (and possibly overriden by a directory option from #607), it always starts in $HOME (which expands to `/home/<userdir>`), rather than the cygwin equivalent of the starting directory (which for `<Drive-Letter>:\<path\...>` is `/cygdrive/<Drive-Letter (in lowercase)>/<path/...>`). I propose that to fix this, and any similar issues that may arise with other shells, it be possible (though optional), to specify a command to executed in the new shell that will switch to the starting directory. # Proposed technical implementation details (optional) In profile settings, there is an optional field called `dirCommand` which can be anything. If present, the shell is started by running the shell `commandline`, then immediately after, the command specified by `dirCommand` is run by the newly started command processor, substituting each occurance of a properly named variable, say `$StartingDir` with the starting directory, then (possibly) removing the command from history. An example of this for cygwin bash would be ``` ... (cygwin bash profile) "dirCommand":"cd `cygpath $StartingDir` && exec /bin/bash" ... ``` If `dirCommand` is absent, opening the profile has the exact same effect as opening the profile currently does (without respect to `dirCommand`).
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-Fix labels 2026-01-30 23:23:42 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Aug 24, 2019):

Thanks for the feature request!
I’m not sure about this. Every other shell seems to inherit its working directory properly; should we go out of our ways to support broken shells?

@DHowett-MSFT commented on GitHub (Aug 24, 2019): Thanks for the feature request! I’m not sure about this. Every other shell seems to inherit its working directory properly; should we go out of our ways to support broken shells?
Author
Owner

@chorman0773 commented on GitHub (Aug 24, 2019):

To be fair, I do have to invoke cygwin's bash directly (mintty.exe starts a new window, presumably because it is its own console host), and because its a cygwin application, it doesn't know anything about windows paths and certainly not windows environment variables (as far as I know cygwin bash doesn't inherit any environment variables, except maybe PATH after some modification, from the windows environment.). It would also be useful for remote shells that have access to (part of or the whole of) the hosts filesystem, for example, my local-network ssh profile could run some command that goes to the transformed directory on an smb mount.

@chorman0773 commented on GitHub (Aug 24, 2019): To be fair, I do have to invoke cygwin's bash directly (mintty.exe starts a new window, presumably because it is its own console host), and because its a cygwin application, it doesn't know anything about windows paths and certainly not windows environment variables (as far as I know cygwin bash doesn't inherit any environment variables, except maybe PATH after some modification, from the windows environment.). It would also be useful for remote shells that have access to (part of or the whole of) the hosts filesystem, for example, my local-network ssh profile could run some command that goes to the transformed directory on an smb mount.
Author
Owner

@bitcrazed commented on GitHub (Aug 28, 2019):

Thanks for the ask @chorman0773. However, Terminal is not going to get into the business of trying to correct for different shell/app/tool behaviors. This responsibility is likely best handled by the shell, not the Terminal.

@bitcrazed commented on GitHub (Aug 28, 2019): Thanks for the ask @chorman0773. However, Terminal is not going to get into the business of trying to correct for different shell/app/tool behaviors. This responsibility is likely best handled by the shell, not the Terminal.
Author
Owner

@chorman0773 commented on GitHub (Aug 28, 2019):

Ok, I understand. I can work around the issue. I was just wondering if it was possible for support of remote shells and shells that run in a cygwin environment and therefore unable to understand windows paths (as using calls to linux functions, which are translated by cygwin).

@chorman0773 commented on GitHub (Aug 28, 2019): Ok, I understand. I can work around the issue. I was just wondering if it was possible for support of remote shells and shells that run in a cygwin environment and therefore unable to understand windows paths (as using calls to linux functions, which are translated by cygwin).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3546