|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections; |
5 | 6 | using System.Collections.Generic; |
6 | 7 | using System.Management.Automation; |
| 8 | +using System.Management.Automation.Language; |
7 | 9 | using Microsoft.PowerShell.Commands.Internal; |
8 | 10 |
|
9 | 11 | namespace Microsoft.PowerShell.Commands |
@@ -34,6 +36,13 @@ public SwitchParameter Raw |
34 | 36 | } |
35 | 37 | } |
36 | 38 |
|
| 39 | + /// <summary> |
| 40 | + /// Gets or sets the delimiters to use when splitting the clipboard content. |
| 41 | + /// </summary> |
| 42 | + [Parameter] |
| 43 | + [ArgumentCompleter(typeof(DelimiterCompleter))] |
| 44 | + public string[] Delimiter { get; set; } = [Environment.NewLine]; |
| 45 | + |
37 | 46 | private bool _raw; |
38 | 47 |
|
39 | 48 | /// <summary> |
@@ -68,11 +77,40 @@ private List<string> GetClipboardContentAsText() |
68 | 77 | } |
69 | 78 | else |
70 | 79 | { |
71 | | - string[] splitSymbol = { Environment.NewLine }; |
72 | | - result.AddRange(textContent.Split(splitSymbol, StringSplitOptions.None)); |
| 80 | + result.AddRange(textContent.Split(Delimiter, StringSplitOptions.None)); |
73 | 81 | } |
74 | 82 |
|
75 | 83 | return result; |
76 | 84 | } |
77 | 85 | } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Provides argument completion for the Delimiter parameter. |
| 89 | + /// </summary> |
| 90 | + public sealed class DelimiterCompleter : IArgumentCompleter |
| 91 | + { |
| 92 | + /// <summary> |
| 93 | + /// Provides argument completion for the Delimiter parameter. |
| 94 | + /// </summary> |
| 95 | + /// <param name="commandName">The name of the command that is being completed.</param> |
| 96 | + /// <param name="parameterName">The name of the parameter that is being completed.</param> |
| 97 | + /// <param name="wordToComplete">The input text to filter the results by.</param> |
| 98 | + /// <param name="commandAst">The ast of the command that triggered the completion.</param> |
| 99 | + /// <param name="fakeBoundParameters">The parameters bound to the command.</param> |
| 100 | + /// <returns>Completion results.</returns> |
| 101 | + public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters) |
| 102 | + { |
| 103 | + wordToComplete ??= string.Empty; |
| 104 | + var pattern = new WildcardPattern(wordToComplete + '*', WildcardOptions.IgnoreCase); |
| 105 | + if (pattern.IsMatch("CRLF") || pattern.IsMatch("Windows")) |
| 106 | + { |
| 107 | + yield return new CompletionResult("\"`r`n\"", "CRLF", CompletionResultType.ParameterValue, "Windows (CRLF)"); |
| 108 | + } |
| 109 | + |
| 110 | + if (pattern.IsMatch("LF") || pattern.IsMatch("Unix") || pattern.IsMatch("Linux")) |
| 111 | + { |
| 112 | + yield return new CompletionResult("\"`n\"", "LF", CompletionResultType.ParameterValue, "UNIX (LF)"); |
| 113 | + } |
| 114 | + } |
| 115 | + } |
78 | 116 | } |
0 commit comments