-
Notifications
You must be signed in to change notification settings - Fork 7.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use forward slashes by default in Windows #10509
Comments
PowerShell already does the work for you and you have no need to normalize paths. |
@iSazonov Yes and no. Sure, if you are combining path segments, you can use path cmdlets. But if you are writing a script that references a relative path with multiple segments, and if you intend for your script to work cross platform, you're not going to do that. In PowerShell 7 preview 3 on Windows, tab completion completes paths using a backslash. That is the one place where I think we're doing it wrong now that PowerShell is cross platform. There should at least be an option to select the directory separator character you want used on Windows as part of tab completion: either @chriskuech: Aside from tab completion of paths, are there other places where you feel |
@KirkMunro , are you saying that there is an (at least partially implemented) way to normalize paths in PowerShell today? If so, will it work on latest 6.x? The use cases I was having an issue with were automatic variables and @iSazonov, the proposed solution would not have worked for my scenario because I generated a list of paths on Windows, generated a list of paths on Linux, then attempted to compare them, which failed due to the separators. The automatic variables consistently lack a trailing directory separator, so PowerShell beautifully allows creating paths with literals. Ex: $RepoRoot = "$PSScriptRoot/../.."
$SourceRoot = "$RepoRoot/src"
$BuildRoot = "$RepoRoot/.build" I think this is much more clear than $RepoRoot = Join-Path $PSScriptRoot "../.."
$SourceRoot = Join-Path $RepoRoot "src"
$BuildRoot = Join-Path $RepoRoot ".build" so I hope it can work in the future, even if not by default. |
@chriskuech my personal habit has become something like: $SourceRoot = $RepoRoot | Join-Path -ChildPath 'src' It's a little clearer but yeah it's not perfect. |
|
@chriskuech Thanks for the additional information. I wasn't suggesting that PowerShell partially supports normalization of paths. I was simply calling out that I personally dislike that tab completion uses a backward slash by default on Windows, and a forward slash by default on Linux or macOS. If I could tweak some setting to change that so that forward slash is used even on Windows paths by default, I would make that change, and this is one place where I think there may be an opportunity to make cross platform PowerShell work easier. Those personal needs aside, I wonder if a |
Well, we do get platform-specific normalization in PS> Convert-Path C:/Windows
C:\Windows # normalized to Windows-native "\" So, perhaps as an alternative to introducing a Separately and complementarily, the opt-in preference mechanism for using The catch at the moment is that |
I think it would be nice if path completion used the path separator that appears explicitly in the completion text, and if there is none, then default to the platform native separator. So on Windows, I think this would cover a majority of the annoyances without requiring a configuration option, and is actually preferable because you occasionally might need the other form for whatever reason. |
@lzybkr, I like the idea, also in light of a concern regarding a configuration- / preference-variable-based solution that I neglected to mention: the scoping issue; with the usual dynamic scoping, code that makes fixed assumptions about path separators may break (which has echoes of PowerShell/PowerShell-RFC#7). |
@lzybkr and when both slashes are used? |
So many options - random, alternate each one, always forward slash b/c it's the one true path separator, etc. More seriously, maybe just pick the last one used, that is probably typed by the user whereas others might not be. |
This comment has been minimized.
This comment has been minimized.
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
@iSazonov: This isn't really answered, and should be reopened to allow the ongoing discussion to continue working this out. The OP hasn't even had a chance to respond to questions asked back to him. |
I think I addressed all the questions to me, but let me know if I didn't. I too am not sure why this issue is closed. It wasn't meant as a discussion thread, rather a feature request. The root issue at hand:
I think forcing devs to manually normalize strings with cmdlets is a definite wrong move. I don't see any scenarios where using As more people migrate to the cloud, more and more people develop PowerShell code on Windows and run it on Linux. There will certainly be a point in the future (if not already passed) where the number of users preferring true cross-platform behavior exceeds any who feel strongly about keeping |
@chriskuech: My bad, I didn't specifically pose the question to you. I was wondering if you felt a |
@KirkMunro I'm not sure However, I am very hesitant to endorse any cmdlet-based solution, as it doesn't solve the root issue and will either disallow string interpolation for paths or require code changes to every path string definition. Specifically, |
@KirkMunro @mklement0 The issue is not locked and everyone can pull comments. |
To be clear, the issue is still "use forward slash on Windows". "Compare paths" was only brought up as one (of multiple) motivating examples. Proposal If this is unreasonable, I would like to know why and if there is documentation guiding when PowerShell design diverges across platforms. |
@iSazonov: Maintainers of the PS repo shouldn't be dismissive to users issues without discussion. You originally replied without taking the time to understand the needs of the OP, marking the issue as answered, but the issue was not posted as a question, it was posted as a feature request, and as can be seen by the discussion it is clearly not "answered". |
Who says? That's absolutely not true. An open issue is open, and a closed issue is closed. Those two distinctions have very clear meaning. I only look at closed issues if they are my own and I want to go back to check something. On a rare occasion I may go searching closed issues for discussions on a certain topic. But 90% or more of my time in issues is in open issues, as it should be. The only thing blurring the line between the two and making open issues lose their meaning is summarily closing them before they are resolved, like you have done with this issue.
Based on this approach to managing issues, you're forcing people to lose the distinction between open and closed, such that they have to search all issues rather than focus on the open issues, which means checking the 2K open issues plus the 4K closed issues for discussions relevant to them instead of just focusing on the open issues. That is a broken, flawed issue management strategy.
That is ridiculous. The discussion is focused on dealing with Windows having a backslash as the default when you are writing scripts for cross platform. It has remained focused on that topic. You're trying to make it sound like it isn't focused at all. @iSazonov, I agree that there are too many open issues; however, the fact that there are too many open issues does not mean we should be dismissive and shut conversation down prematurely on new issues. We must continue to encourage feedback and be open to discussion about PowerShell in open issues, and only close them once they are truly resolved. The volume of open issues must be dealt with differently. |
Loyal linux users?Incomprehensible advice. |
|
The problem is that this is both syntactically awkward ( Conceptually, the path separator is a constant (an automatic variable in PowerShell terms), and with the proposed configurability we're turning it into preference variable. Either way, a variable is the expected - and efficient - form. |
A variable that you cannot change to is not a variable. It is an observable, equivalent to a parameterless function. I have no data regarding the (in)efficiency of a cmdlet call in PowerShell but if it is a problem for built-in cmdlets, it is a problem that should be solved. |
Even what is conceptually a constant in PowerShell is surfaced as a variable, such as |
What would offer a solution is if we had a calculated automatic read-only variable, analogous to a In fact, we already have such automatic variables, e.g.,
That is,
|
@mklement0 Do we really need two variables for this? I've read the reasoning you have provided, but pairing up variables for this single purpose seems unnecessary to me. My preference would be to have I haven't put a ton of thought into this, but up front I feel going with a terse name and avoiding having to work with multiple variables is better for scripters in this case. |
@KirkMunro, I'd be fine with
In short:
|
This particular example should be deprecated to |
I've never liked this, tbh, and wonder what is gained by having that variable undefined by default. I would like Also, if I ever want to know the platform-native separator, I can just invoke
No, it should not. Using |
Indeed. That is why you should specify them as positional parameters instead. |
Yes, but that's not only a keyboardful, if you will, but also hard to remember.
Agreed, and that's why The sole reason this is necessary is the absence of lexical scoping in PowerShell. While the problem of a preference variable affecting all child scopes due to dynamic scoping applies to all preference variables (in the case of the global scope even affecting all modules), with the one at hand it would be especially problematic, because:
Hence the need to have an undefined by default variable, that you can easily make private: Again, the all-scopes |
@mklement0 Hey, do you have any interest in following up on your ideas? I and I'm sure many others would love to see better forward slash support on Windows. |
Thanks, @rkitover - while I think pursuing this is worthwhile, I hope someone else takes this on. |
This comment has been minimized.
This comment has been minimized.
@doctordns Don't use street and prison jargon in this respected community
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Yes, there's no need to have "Slash" in the name. |
Such discussions are not acceptable here.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
To be clear, my objection was not to the warning, but to the sordid details. Once again, please stop discussing in this direction and switch to constructive suggestions. |
There were no sordid details - unless you consider a clinical term for a bodily function "sordid". And it should be self-evident that some description of the potentially offensive meaning of the term in question is necessary. To also be clear: I have no stake in this discussion (to me the term isn't offensive), but I find this baffling overreaction to a concern voiced by a user in good faith disconcerting. As for the actual discussion at hand: FWIW, the current references in the help topics don't use the term in isolation (and I'm not aware of code elements using it at all) - they use backslash and forward slash (again, not a personal concern of mine). As for constructive suggestions: the discussion already encompasses that too - see @aaronfranke's comment. I understand your argument that the word is commonly used and should therefore be regarded as acceptable, and perhaps that is ultimately the proper resolution to this discussion. But there should be always be room for such a discussion (as long as the language used in the discussion doesn't violate the CoC, which I think was definitely not the case here). |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Summary of the new feature/enhancement
PowerShell aims to be cross-platform, but I have been having many issues operating on paths across both Windows and Linux. I understand the need to support
\
in Windows for the foreseeable future, but I would at least like the default path character to be the same on both Windows and *nix, presumably by setting the default path delimiter to/
. The current alternative is forcing users to normalize paths themselves with-replace "\\", "/"
in their paths.The text was updated successfully, but these errors were encountered: