microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.36k stars 28.6k forks source link

Option to specify separator for "Copy Relative Path" action #56279

Closed IllusionMH closed 3 years ago

IllusionMH commented 6 years ago

Workaround (from @bpasero) You can use this extension: https://marketplace.visualstudio.com/items?itemName=rssowl.copy-relative-path-posix

Original Issue:

Looked for other mentions but haven't found related requests or discussion.

I'm often using Copy Relative Path feature to compose import strings or share with other developers on Mac/Linux. Therefore, new Copy relative path feature that has native path separators on Windows doesn't help in these cases (in comparison with Copy path).

Please add option to change path separators used in Copy Relative Path action, so I will be able to set / as path separator and have same behavior across all platforms.

vscodebot[bot] commented 6 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

isidorn commented 6 years ago

Both copy path and copy relative path respect the platform they are on I can leave this open as a feature request. Add a setting just for this sounds like a bad idea to me

fyi @bpasero

IllusionMH commented 6 years ago

@isidorn proposed option will open more use cases for Windows users (other have them "for free"). JS/TS imports expect path with forward slashes independently from OS, as well as paths for images/resources used in HTML/CSS. Ability to copy path with expected separator will remove pain from manually changing them (which should be done with Copy Path). UDP. Also users who prefers CLI to work with git and uses git-bash instead of CMD will benefit from this too.

I've proposed to make it as option, because it is already released in this way and separator change might be considered breaking change. Moreover this will provide same behavior as in WebStorm: relative path - always forward slashes, (full) path - according to OS.

yumeyao commented 5 years ago

6308

There was a closed issue with similar request, but was rejected by the arrogant developer.

esmirnov commented 5 years ago

There is extension for that https://marketplace.visualstudio.com/items?itemName=alexdima.copy-relative-path

IllusionMH commented 5 years ago

This extension had problems earlier, but copies now, however doesn't play nicely with workspaces and 2 "Copy relative path" options in dropdown aren't good.

Still unified behavior across OSes and IDE would be great for built-in functionality would be great.

esmirnov commented 5 years ago

@IllusionMH agree, it's not perfect. I would suggest a new setting "preferedPathSepartor" with possible values "Native", "Forward", "Backward".

dwelle commented 5 years ago

I'd so love an option to set POSIX (forward slash) separators everywhere in vscode on windows. I hate manually replacing\escaping slashes everywhere. I'm not using cmd.exe, windows explorer accepts POSIX paths, so why do we need backslashes at all?

Please add an option to display POSIX all the way.

efortes commented 5 years ago

I often use the vscode Windows Subsystem for Linux (WSL) terminal to navigate to a file by right clicking a file in VS code and hitting the Copy path options. This will deliver me a windows path ( C:\Users. ). As i'm using WSL I want the possibility to copy an Unix path. The path would then be: /c/Users. ( https://github.com/Microsoft/vscode/issues/63633 )

mandrie commented 5 years ago

+1 for making the slash direction optional to the user. I do a lot of work with Markdown file on Windows in VSCode for Azure Devops Wiki and relative path file links need to use forward slashes and not backslashes, so I am constantly using the "Copy Relative Path" and replacing the backslashes

victor-ruben commented 5 years ago

This extension does something like that: https://github.com/CoenraadS/Copy-WSL-Path

IllusionMH commented 5 years ago

@victor-ruben unfortunately this extension doesn't help. It will produce full path like /mnt/c/long/path/to/project/src/file/project.js (see) but in this issue we are asking for path relative for workspace. So it will be simple src/file/project.js.

dwelle commented 5 years ago

@IllusionMH there's https://marketplace.visualstudio.com/items?itemName=dkaba.better-file-path

gomesalexandre commented 5 years ago

What's the status on this ? It would be really nice to have options for relative file path copy, same way as you do for the window title for example. Given this is already implemented there, it should be quite trivial

gomesalexandre commented 5 years ago

I would like to contribute it if possible, just not sure where to get started

libasoles commented 5 years ago

+1 for this. Makes total sense for me.

victor-ruben commented 5 years ago

I would like to contribute it if possible, just not sure where to get started

Perhaps a PR to this extension https://github.com/CoenraadS/Copy-WSL-Path

Juxn3 commented 5 years ago

+1 for this

kyletheninja commented 5 years ago

I would suggest a new setting "preferedPathSepartor" with possible values "Native", "Forward", "Backward".

esmirnov proposes the perfect solution in my eyes. I recently started using VS code for angularJS development and the copy relative path function would be fantastic for pasting template links into directives and js links into index.html, but backslash is an escape character in JS. It's super annoying to have this great and useful feature have such a debilitating limitation, which is how I would describe the situation as pertains to use in JS.

maplion commented 5 years ago

Can there just be an added context menu option that one can turn on, such as "Copy Relative Path with /"? I would find this very useful as even being a Windows user, I use the forward slash path more often than the backslash one.

bobbogomip commented 5 years ago

I use vscode because it is portable.

I never use cmd.

Please please can Windows vscode support some way of getting paths with forward slashes?

xmadsen commented 5 years ago

An obvious feature, should definitely exist for WSL users who want to work with Linux users and not look like idiots using Windows slashes :+1:

ElvenSpellmaker commented 5 years ago

I'd like to chime in and say I use Cygwin through Mintty and the backslashes are really killing my productivity due to them being forward slashes, and not being able to configure a full path output. =|

I'm not sure why there's no way of overriding this, the times I need backslashes are really rare.

pianeer commented 5 years ago

This is a necessary feature and huge productivity booster for those of us who use Linux shells in Windows. Could we please add this as a configuration option with the default set to the native format but at least have the ability to override it?

Juxn3 commented 5 years ago

This is a functionality that is very much needed, I work on windows but everything is mounted on Linux servers, it is a nuisance to be changing the bars.

ElectronicElephant commented 4 years ago

I think it's OK to leave the option to the user. It's really needed.

vadimmos commented 4 years ago

The ability to choose a separator is something that is so lacking.

hornta commented 4 years ago

Or don't specify an option and always return a path with "/"

sethidden commented 4 years ago

Especially now when WSL is a thing this is important. Even without WSL there are shells that use the Linux format - git bash for example. Switching to stock cmd just because I need to paste a VS Code path is a pain.

bpasero commented 4 years ago

I just released an extension that should take care of this (as I still think this should be something an extension provides and not be a setting): https://marketplace.visualstudio.com/items?itemName=rssowl.copy-relative-path-posix

image

Features:

@IllusionMH If there are no objections and people think the extension is OK enough, I would suggest to close this issue.

lalomartins commented 4 years ago

Thanks for the extension, but I think there's quite enough argument above that this should be built-in. Whether it's a setting, or a separate menu entry like in the extension, or simply always copy the posix slash (which works everywhere except cmd as was pointed out earlier), I don't know, but it's not something to be left to an extension IMO.

saschanaz commented 4 years ago

I think it should be reversed, the default should be standard POSIX and the cmd compatibility should be an extension.

bpasero commented 4 years ago

I pushed an update for the extension so that it can also be used via keybinding or from the command palette. In that case of usage it will copy the relative path of the active editor.

maplion commented 4 years ago

@bpasero Thanks for this, I'm going to use it until there is an alternative.

Orbling commented 4 years ago

This really should be a standard feature, guess the developers don't actually develop on Windows platforms much.

Few developers are going to use cmd.exe as a terminal, it'll usually be bash, often as not people will be developing for non-windows environments. Having the copy path options forcibly use a type of slash that's wrong in the majority of usage cases is daft and makes the feature next to useless. It really does need to be settings-based or have two completely separate options. May well want to be per language, as desktop applications in an MS flavour might still want the backslash.

rob4226 commented 4 years ago

Extensions are nice but please add it as a native setting so it can be set on a per-folder or per-workspace basis in settings.json. This is especially needed for developing Angular apps. It's a reasonable request with good support and no real downsides. It can default to false to keep current behavior but something like the following would be very helpful. Thank you. "editor.copyRelativePathForwardSlashes": true

dacioromero commented 4 years ago

It can default to false to keep current behavior but something like the following would be very helpful. Thank you. "editor.copyRelativePathForwardSlashes": true

I'm thinking that "editor.copyRelativePathSlashType" would be a better option that could have "forward", "back", or "os" (default). That way if someone wanted backslashes over forward for whatever reason they have the option.

eliveikis commented 4 years ago

Another upvote. Especially with Windows Subsystem for Linux 2 incoming, more and more people are using Windows combined with linux workflows. I personally use git bash or an Ubuntu terminal for day-to-day work.

In addition, many development projects use forward slashes for path definitions that are passed to configs, command lines or API's. Not having this as a VSCode option feels very backwards and is a common pain point.

Even windows explorer accepts forward slashes in the address bar.

shandysulen commented 4 years ago

Please build this in as a setting into VS Code. I am unable to Copy Relative Path properly into my Bash terminal, since it reads "\" as the escape character

bpasero commented 4 years ago

Quick poll: what if there was simply a setting that puts any path on Windows with slash instead of backslash when shown in the UI or copied? Changing this just for the "Copy Path" action seems a bit inconsistent. Would that be OK for people?

lalomartins commented 4 years ago

For me that's definitely desirable (more than OK). Again, the only thing I'm aware of which still requires backslash is cmd, everything else may accept it but also accepts slash, so as I see it there's no real reason to be using backslash.

(And if you're a developer and you're using cmd, please do yourself a favor and take a couple of days to learn PowerShell, it's 2020 already.)

dwelle commented 4 years ago

@bpasero I'm pretty sure that's actually what everyone wants, but they settled for "path". Bring it on! :)

IllusionMH commented 4 years ago

@bpasero overall it will be even more preferable especially if implemented for Compact folders in Explorer and search results and open editors description text (relative path).

Not so optimal for full paths in hovers (tabs, open editors, explorer), but not a problem.

But problem will be reversed to "Copy path" which copies full path and OS separators make more sense here. (Personally I rarely use it, so won't be a big problem for me)

TL;DR; I'm all in for this option, but proper OS path for Copy path makes more sense

bpasero commented 4 years ago

Maybe "Copy Path" could be the only special case where we would use backslash even if this new setting is configured to use slashes. I agree that an absolute path when copied should use backslash on Windows.

sergei-beloglazov commented 4 years ago

I need 2 options for "Copy relative path": 1) for Windows, where I work with IDE 2) for Unix, which is the target for my PHP files The solution with native function with OS separator + plugin suites for me. If there will be an option for separator, it doesn't solve the problem dealing with 2 OS file systems :)

dwelle commented 4 years ago

@sergey-beloglazov if you want to retain platform-specific conventions then simply don't change the (future) setting. Unix is already POSIX, windows will keep backslashes.

This issue is about support of overriding the convention for all platforms.

leandro-hl commented 3 years ago

Also would be great if you fix class discovery. That way we wouldn't need to go copy (type in this case) the path to the file that we wanna import in our .ts

jonlepage commented 3 years ago

yes also need it. Maybe the alt + click on the command can be a good idea!, or shift + rightClick to make appear secret commands like in Window explorer? A option to toggle between path mode can also a great idea. We lost precious time to convert path slash \ / and a plugin to just do this ! no thanks

wonkoRT commented 3 years ago

I'd like this, additionally with an option to copy escaped paths in source code and unescape them while copying and vice versa. Also it would be great if pasting into a source would recognize paths and auto escape them and also convert forward to backslash paths prefixed with \\?\ (escaped \\\\?\\) at least when hitting the max path length limit.

IllusionMH commented 3 years ago

@wonkoRT escaping/unescaping should be separate request because need to escape/unescape depends too much on context of from/to operation (config vs string vs import location, language etc.).

This one about removing difference between how paths(mostly relative) are handled in windows vs *nix for display, copy etc.