CLI: Support tilde (~) shortcut to user profile in -d argument #10374

Closed
opened 2026-01-31 02:19:51 +00:00 by claunia · 10 comments
Owner

Originally created by @Ariane-B on GitHub (Aug 28, 2020).

Description of the new feature/enhancement

Currently, if I want to open a Terminal tab that starts in a specific folder in my user profile, I have to write -d C:\Users\MyUser\somefolder. I wish I could use the shortcut ~ to say "that's my user folder".

Proposed technical implementation details (optional)

For example, I could use the command wt -d ~/somefolder, which would be equivalent to wt -d C:\Users\MyUser\somefolder.

Originally created by @Ariane-B on GitHub (Aug 28, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 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 Currently, if I want to open a Terminal tab that starts in a specific folder in my user profile, I have to write `-d C:\Users\MyUser\somefolder`. I wish I could use the shortcut ~ to say "that's my user folder". <!-- 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. --> For example, I could use the command `wt -d ~/somefolder`, which would be equivalent to `wt -d C:\Users\MyUser\somefolder`.
Author
Owner

@DHowett commented on GitHub (Sep 4, 2020):

Hey, this is a good idea.

@DHowett commented on GitHub (Sep 4, 2020): Hey, this is a good idea.
Author
Owner

@kaifee-haque commented on GitHub (Sep 5, 2020):

Looks like we can already open a Terminal tab that starts in C:\Users\MyUser\somefolder by using the command wt -d somefolder.

@kaifee-haque commented on GitHub (Sep 5, 2020): Looks like we can already open a Terminal tab that starts in `C:\Users\MyUser\somefolder` by using the command `wt -d somefolder`.
Author
Owner

@Ariane-B commented on GitHub (Sep 5, 2020):

That is cool, but it would be nice if it were clearer in the docs, because I was convinced the root for the -d parameter was "My PC" or "C:".

@Ariane-B commented on GitHub (Sep 5, 2020): That is cool, but it would be nice if it were clearer in the docs, because I was convinced the root for the -d parameter was "My PC" or "C:".
Author
Owner

@DHowett commented on GitHub (Sep 5, 2020):

As with all Windows applications, the root of any relative directory parameter is the current working directory.

This means that if you run wt -d x from C:\a it will start a profile in C:\a\x.

We opted not to document behavior that is either incidental or not a deviation from other applications :)

@DHowett commented on GitHub (Sep 5, 2020): As with all Windows applications, the root of any relative directory parameter is the current working directory. This means that if you run `wt -d x` from `C:\a` it will start a profile in `C:\a\x`. We opted not to document behavior that is either incidental or not a deviation from other applications :)
Author
Owner

@Ariane-B commented on GitHub (Sep 5, 2020):

Oh, that's what you meant! I thought you meant that the -d argument was always based on the current user's directory. If the base is the current command line directory, then my suggestion stands.

What you describe makes perfect sense. But in the context of a startup shortcut, for example, the directory it runs from is not immediately obvious. Add in general, I don't think it's entirely safe to assume everyone will always be running the shell command line from their home folder.

Also, there might be cases where a single shell file will be run by several users, who'd want the starting directory to be in -their- user folder.

Finally, some people like to specify things when they're insecure about what the automatic behaviour would be. Simply mentioning the thing is sometimes simpler than researching the default behaviour, after all.

For all these reasons, I think I'll stand behind my suggestion.

@Ariane-B commented on GitHub (Sep 5, 2020): Oh, that's what you meant! I thought you meant that the -d argument was always based on the current user's directory. If the base is the current command line directory, then my suggestion stands. What you describe makes perfect sense. But in the context of a startup shortcut, for example, the directory it runs from is not immediately obvious. Add in general, I don't think it's entirely safe to assume everyone will always be running the shell command line from their home folder. Also, there might be cases where a single shell file will be run by several users, who'd want the starting directory to be in -their- user folder. Finally, some people like to specify things when they're insecure about what the automatic behaviour would be. Simply mentioning the thing is sometimes simpler than researching the default behaviour, after all. For all these reasons, I think I'll stand behind my suggestion.
Author
Owner

@KnapSac commented on GitHub (Sep 9, 2020):

Can I pick this up?

@KnapSac commented on GitHub (Sep 9, 2020): Can I pick this up?
Author
Owner

@zadjii-msft commented on GitHub (Sep 9, 2020):

I'm a little worried about this request. Treating ~ as %USERPROFILE%seems like a good idea, but what if someone wants to use ~ as their WSL ~ directory, not their Windows one?

IMO I'd want that question answered before we ship this.

@zadjii-msft commented on GitHub (Sep 9, 2020): I'm a little worried about this request. Treating `~` as `%USERPROFILE%`seems like a good idea, but what if someone wants to use `~` as their WSL `~` directory, not their Windows one? IMO I'd want that question answered before we ship this.
Author
Owner

@KnapSac commented on GitHub (Sep 9, 2020):

Maybe that should depend on the profile you're targeting? For instance, when opening a WSL profile we could treat ~ as their WSL ~ directory, and for other profiles we could treat it as %USERPROFILE%.

@KnapSac commented on GitHub (Sep 9, 2020): Maybe that should depend on the profile you're targeting? For instance, when opening a WSL profile we could treat ```~``` as their WSL ```~``` directory, and for other profiles we could treat it as ```%USERPROFILE%```.
Author
Owner

@zadjii-msft commented on GitHub (Sep 9, 2020):

Ah but how do we know for certain if they"re targeting a WSL profile? The user could make other WSL profiles other than the dynamically generated ones. In that case, we wouldn't have the source data to tell use that the profile is a WSL profile. Maybe we need to add another wslDistro property that identifies which distro the profile is for. That might play into #592 (et al) as well.

/cc @DHowett since we've been having discussion about this in the past

@zadjii-msft commented on GitHub (Sep 9, 2020): Ah but how do we know for certain if they"re targeting a WSL profile? The user could make other WSL profiles other than the dynamically generated ones. In that case, we wouldn't have the `source` data to tell use that the profile is a WSL profile. Maybe we need to add another `wslDistro` property that identifies which distro the profile is for. That might play into #592 (et al) as well. /cc @DHowett since we've been having discussion about this in the past
Author
Owner

@zadjii-msft commented on GitHub (Mar 3, 2022):

We might have low key done this unintentionally.

#12437

If we find that we were unable to mangle ~ into the user's WSL commandline, then we will re-evaluate that startingDirectory as %USERPROFILE%, which is at least something sensible, if albeit not what they wanted.

I mean, it makes sense. ~ isn't a valid path for a Windows process, but it is for a WSL process. We've already got some magic to make this work for WSL processes. Now we've got different magic to make it work for anything other than wsl.exe. If we see a startingDirectory of ~, we're gonna treat it like %USERPROFILE% now.

This should be in Terminal v1.12.10393.0, Terminal Preview v1.13.10395.0

@zadjii-msft commented on GitHub (Mar 3, 2022): We might have low key done this unintentionally. #12437 > If we find that we were unable to mangle ~ into the user's WSL commandline, then we will re-evaluate that startingDirectory as %USERPROFILE%, which is at least something sensible, if albeit not what they wanted. I mean, it makes sense. `~` isn't a valid path for a Windows process, but it is for a WSL process. We've already got some magic to make this work for WSL processes. Now we've got different magic to make it work for anything other than wsl.exe. If we see a startingDirectory of `~`, we're gonna treat it like `%USERPROFILE%` now. This should be in `Terminal v1.12.10393.0`, `Terminal Preview v1.13.10395.0`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10374