-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Support Invoke-Item -Path <folder> #4262
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
Changes from 1 commit
65513b8
706a7b2
1a3134c
08f6a43
1aa5e77
c04d1be
186f8ff
46442da
4a4cd71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1323,12 +1323,38 @@ protected override void InvokeDefaultAction(string path) | |
|
|
||
| string resource = StringUtil.Format(FileSystemProviderStrings.InvokeItemResourceFileTemplate, path); | ||
|
|
||
| #if UNIX | ||
| void StartProcessWithOpen(string filename) | ||
| { | ||
| System.Diagnostics.Process process = new System.Diagnostics.Process(); | ||
| // The file is possibly not an executable, so we try invoking the default program that handles this file. | ||
| const string quoteFormat = "\"{0}\""; | ||
| process.StartInfo.FileName = Platform.IsLinux ? "xdg-open" : /* OS X */ "open"; | ||
| if (NativeCommandParameterBinder.NeedQuotes(filename)) | ||
| { | ||
| path = string.Format(CultureInfo.InvariantCulture, quoteFormat, filename); | ||
| } | ||
| process.StartInfo.Arguments = filename; | ||
| // xdg-open on Ubuntu outputs debug info to stderr, suppress it | ||
| process.StartInfo.RedirectStandardError = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's probably true. I guess we'll just have to have the debug spew coming out.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What error an user see if run the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the same stderr if run directly |
||
| process.Start(); | ||
| } | ||
| #endif | ||
|
|
||
| if (ShouldProcess(resource, action)) | ||
| { | ||
| System.Diagnostics.Process invokeProcess = new System.Diagnostics.Process(); | ||
|
|
||
| try | ||
| { | ||
| // special case directories on UNIX so that we can open them in the window-manager | ||
| // corefx doesn't return error if you try to start a directory | ||
| #if UNIX | ||
| if (Directory.Exists(path)) | ||
| { | ||
| StartProcessWithOpen(path); | ||
| } | ||
| #endif | ||
| // Try Process.Start first. | ||
| // - In FullCLR, this is all we need to do. | ||
| // - In CoreCLR, this works for executables on Win/Unix platforms | ||
|
|
@@ -1339,15 +1365,7 @@ protected override void InvokeDefaultAction(string path) | |
| catch (Win32Exception ex) when (ex.NativeErrorCode == 13) | ||
| { | ||
| // Error code 13 -- Permission denied. | ||
| // The file is possibly not an executable, so we try invoking the default program that handles this file. | ||
| const string quoteFormat = "\"{0}\""; | ||
| invokeProcess.StartInfo.FileName = Platform.IsLinux ? "xdg-open" : /* OS X */ "open"; | ||
| if (NativeCommandParameterBinder.NeedQuotes(path)) | ||
| { | ||
| path = string.Format(CultureInfo.InvariantCulture, quoteFormat, path); | ||
| } | ||
| invokeProcess.StartInfo.Arguments = path; | ||
| invokeProcess.Start(); | ||
| StartProcessWithOpen(path); | ||
| } | ||
| #elif CORECLR | ||
| catch (Win32Exception ex) when (ex.NativeErrorCode == 193 || ex.NativeErrorCode == 5) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check NeedQuotes? Maybe do that for every filename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NeedQuotescheck is needed only if you are specifying arguments for ProcessInfo, for example, the argument string may have space in it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we could remove the 'if' and each name quoted - "filename.txt", "file name.txt".