Use forward slashes by default in Windows #16671
Replies: 99 comments 19 replies
-
PowerShell already does the work for you and you have no need to normalize paths. |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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). |
Beta Was this translation helpful? Give feedback.
-
@lzybkr and when both slashes are used? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@doctordns Don't use street and prison jargon in this respected community
|
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Yes, there's no need to have "Slash" in the name. |
Beta Was this translation helpful? Give feedback.
-
Such discussions are not acceptable here.
|
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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). |
Beta Was this translation helpful? Give feedback.
-
Or we could just skip using that "word" altogether Prince style, and use images instead: 🤣 OK, had my fun, backing away from the keyboard. |
Beta Was this translation helpful? Give feedback.
-
There was too much for me to read here. Was this forgotten or is it being worked on? 😢 This is a problem I'm also running into, in my situation it's when using WSL with PowerShell. e.g.: I want to use valgrind (wsl make ./mycode.c, wsl valgrind ./mycompiledcode), but if i autocomplete it will automatically add a ".\" at the beginning and my command won't work. So I need to fully type names or keep going back and forth correcting the slashes. It would be amazing if there was an easy way to change the default slash direction on autocomplete or something like that. |
Beta Was this translation helpful? Give feedback.
-
I suggest we follow up on the completion aspect of this in the PSReadLine repo, which is here: |
Beta Was this translation helpful? Give feedback.
-
I ran into a situation a few weeks ago where I was calling into Bash through PowerShell, but PowerShell automatically replaced It's fine if this option doesn't work with every program in every situation. We don't have to make it the default. I just need it to work on my machine without me having to resort to painful workarounds. |
Beta Was this translation helpful? Give feedback.
-
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.Beta Was this translation helpful? Give feedback.
All reactions