@shell-shock/plugin-completions 0.2.23 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/bash-config-command.cjs +132 -0
- package/dist/components/bash-config-command.d.cts +10 -0
- package/dist/components/bash-config-command.d.cts.map +1 -0
- package/dist/components/bash-config-command.d.mts +10 -0
- package/dist/components/bash-config-command.d.mts.map +1 -0
- package/dist/components/bash-config-command.mjs +132 -0
- package/dist/components/bash-config-command.mjs.map +1 -0
- package/dist/components/bash-script-command.cjs +106 -0
- package/dist/components/bash-script-command.d.cts +10 -0
- package/dist/components/bash-script-command.d.cts.map +1 -0
- package/dist/components/bash-script-command.d.mts +10 -0
- package/dist/components/bash-script-command.d.mts.map +1 -0
- package/dist/components/bash-script-command.mjs +106 -0
- package/dist/components/bash-script-command.mjs.map +1 -0
- package/dist/components/bash-shared.cjs +172 -0
- package/dist/components/bash-shared.d.cts +10 -0
- package/dist/components/bash-shared.d.cts.map +1 -0
- package/dist/components/bash-shared.d.mts +10 -0
- package/dist/components/bash-shared.d.mts.map +1 -0
- package/dist/components/bash-shared.mjs +172 -0
- package/dist/components/bash-shared.mjs.map +1 -0
- package/dist/components/fish-config-command.cjs +132 -0
- package/dist/components/fish-config-command.d.cts +10 -0
- package/dist/components/fish-config-command.d.cts.map +1 -0
- package/dist/components/fish-config-command.d.mts +10 -0
- package/dist/components/fish-config-command.d.mts.map +1 -0
- package/dist/components/fish-config-command.mjs +132 -0
- package/dist/components/fish-config-command.mjs.map +1 -0
- package/dist/components/fish-script-command.cjs +106 -0
- package/dist/components/fish-script-command.d.cts +10 -0
- package/dist/components/fish-script-command.d.cts.map +1 -0
- package/dist/components/fish-script-command.d.mts +10 -0
- package/dist/components/fish-script-command.d.mts.map +1 -0
- package/dist/components/fish-script-command.mjs +106 -0
- package/dist/components/fish-script-command.mjs.map +1 -0
- package/dist/components/fish-shared.cjs +303 -0
- package/dist/components/fish-shared.d.cts +10 -0
- package/dist/components/fish-shared.d.cts.map +1 -0
- package/dist/components/fish-shared.d.mts +10 -0
- package/dist/components/fish-shared.d.mts.map +1 -0
- package/dist/components/fish-shared.mjs +303 -0
- package/dist/components/fish-shared.mjs.map +1 -0
- package/dist/components/index.cjs +24 -8
- package/dist/components/index.d.cts +13 -5
- package/dist/components/index.d.mts +13 -5
- package/dist/components/index.mjs +13 -5
- package/dist/components/powershell-config-command.cjs +128 -0
- package/dist/components/powershell-config-command.d.cts +7 -0
- package/dist/components/powershell-config-command.d.cts.map +1 -0
- package/dist/components/powershell-config-command.d.mts +7 -0
- package/dist/components/powershell-config-command.d.mts.map +1 -0
- package/dist/components/powershell-config-command.mjs +128 -0
- package/dist/components/powershell-config-command.mjs.map +1 -0
- package/dist/components/powershell-script-command.cjs +106 -0
- package/dist/components/powershell-script-command.d.cts +10 -0
- package/dist/components/powershell-script-command.d.cts.map +1 -0
- package/dist/components/powershell-script-command.d.mts +10 -0
- package/dist/components/powershell-script-command.d.mts.map +1 -0
- package/dist/components/powershell-script-command.mjs +106 -0
- package/dist/components/powershell-script-command.mjs.map +1 -0
- package/dist/components/powershell-shared.cjs +319 -0
- package/dist/components/powershell-shared.d.cts +10 -0
- package/dist/components/powershell-shared.d.cts.map +1 -0
- package/dist/components/powershell-shared.d.mts +10 -0
- package/dist/components/powershell-shared.d.mts.map +1 -0
- package/dist/components/{powershell-command.mjs → powershell-shared.mjs} +81 -181
- package/dist/components/powershell-shared.mjs.map +1 -0
- package/dist/components/zsh-config-command.cjs +132 -0
- package/dist/components/zsh-config-command.d.cts +10 -0
- package/dist/components/zsh-config-command.d.cts.map +1 -0
- package/dist/components/zsh-config-command.d.mts +10 -0
- package/dist/components/zsh-config-command.d.mts.map +1 -0
- package/dist/components/zsh-config-command.mjs +132 -0
- package/dist/components/zsh-config-command.mjs.map +1 -0
- package/dist/components/zsh-script-command.cjs +111 -0
- package/dist/components/zsh-script-command.d.cts +10 -0
- package/dist/components/zsh-script-command.d.cts.map +1 -0
- package/dist/components/zsh-script-command.d.mts +10 -0
- package/dist/components/zsh-script-command.d.mts.map +1 -0
- package/dist/components/zsh-script-command.mjs +111 -0
- package/dist/components/zsh-script-command.mjs.map +1 -0
- package/dist/components/zsh-shared.cjs +281 -0
- package/dist/components/zsh-shared.d.cts +10 -0
- package/dist/components/zsh-shared.d.cts.map +1 -0
- package/dist/components/zsh-shared.d.mts +10 -0
- package/dist/components/zsh-shared.d.mts.map +1 -0
- package/dist/components/zsh-shared.mjs +281 -0
- package/dist/components/zsh-shared.mjs.map +1 -0
- package/dist/helpers/complete-command.cjs +2 -7
- package/dist/helpers/complete-command.d.cts +2 -2
- package/dist/helpers/complete-command.d.cts.map +1 -1
- package/dist/helpers/complete-command.d.mts +2 -2
- package/dist/helpers/complete-command.d.mts.map +1 -1
- package/dist/helpers/complete-command.mjs +2 -7
- package/dist/helpers/complete-command.mjs.map +1 -1
- package/dist/helpers/index.cjs +1 -1
- package/dist/helpers/index.d.cts +2 -2
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/index.cjs +245 -59
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +246 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +148 -37
- package/dist/components/bash-command.cjs +0 -273
- package/dist/components/bash-command.d.cts +0 -10
- package/dist/components/bash-command.d.cts.map +0 -1
- package/dist/components/bash-command.d.mts +0 -10
- package/dist/components/bash-command.d.mts.map +0 -1
- package/dist/components/bash-command.mjs +0 -273
- package/dist/components/bash-command.mjs.map +0 -1
- package/dist/components/fish-command.cjs +0 -403
- package/dist/components/fish-command.d.cts +0 -10
- package/dist/components/fish-command.d.cts.map +0 -1
- package/dist/components/fish-command.d.mts +0 -10
- package/dist/components/fish-command.d.mts.map +0 -1
- package/dist/components/fish-command.mjs +0 -403
- package/dist/components/fish-command.mjs.map +0 -1
- package/dist/components/powershell-command.cjs +0 -419
- package/dist/components/powershell-command.d.cts +0 -10
- package/dist/components/powershell-command.d.cts.map +0 -1
- package/dist/components/powershell-command.d.mts +0 -10
- package/dist/components/powershell-command.d.mts.map +0 -1
- package/dist/components/powershell-command.mjs.map +0 -1
- package/dist/components/zsh-command.cjs +0 -384
- package/dist/components/zsh-command.d.cts +0 -10
- package/dist/components/zsh-command.d.cts.map +0 -1
- package/dist/components/zsh-command.d.mts +0 -10
- package/dist/components/zsh-command.d.mts.map +0 -1
- package/dist/components/zsh-command.mjs +0 -384
- package/dist/components/zsh-command.mjs.map +0 -1
|
@@ -1,117 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EXEC_COMMAND } from "../helpers/complete-command.mjs";
|
|
2
2
|
import { CompletionDirective } from "../helpers/completion-directive-constants.mjs";
|
|
3
|
-
import
|
|
3
|
+
import "../helpers/index.mjs";
|
|
4
|
+
import { createComponent } from "@alloy-js/core/jsx-runtime";
|
|
4
5
|
import { getAppBin, getAppTitle } from "@shell-shock/core/plugin-utils";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
|
|
8
|
-
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
6
|
+
import { code, computed } from "@alloy-js/core";
|
|
7
|
+
import { VarDeclaration } from "@alloy-js/typescript";
|
|
9
8
|
import { Spacing } from "@powerlines/plugin-alloy/core";
|
|
10
9
|
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { snakeCase } from "@stryke/string-format/snake-case";
|
|
10
|
+
import { TypescriptFile } from "@powerlines/plugin-alloy/typescript";
|
|
11
|
+
import { joinPaths } from "@stryke/path";
|
|
14
12
|
import { camelCase } from "@stryke/string-format/camel-case";
|
|
15
13
|
|
|
16
|
-
//#region src/components/powershell-
|
|
14
|
+
//#region src/components/powershell-shared.tsx
|
|
17
15
|
/**
|
|
18
|
-
* The PowerShell Completions
|
|
16
|
+
* The PowerShell Completions generation for the Shell Shock project.
|
|
19
17
|
*/
|
|
20
|
-
function
|
|
18
|
+
function PowerShellCompletionsShared() {
|
|
21
19
|
const context = usePowerlines();
|
|
20
|
+
const bin = computed(() => getAppBin(context));
|
|
21
|
+
const name = computed(() => camelCase(bin.value));
|
|
22
22
|
return createComponent(TypescriptFile, {
|
|
23
23
|
get path() {
|
|
24
|
-
return joinPaths(context.entryPath, "completions", "powershell", "
|
|
24
|
+
return joinPaths(context.entryPath, "completions", "powershell", "shared.ts");
|
|
25
25
|
},
|
|
26
|
-
|
|
27
|
-
"node:os": ["os"],
|
|
28
|
-
"node:fs/promises": ["readFile", "writeFile"]
|
|
29
|
-
},
|
|
30
|
-
builtinImports: { "shell-shock:console": [
|
|
31
|
-
"colors",
|
|
32
|
-
"writeLine",
|
|
33
|
-
"success",
|
|
34
|
-
"warn",
|
|
35
|
-
"stripAnsi"
|
|
36
|
-
] },
|
|
26
|
+
builtinImports: { console: ["colors"] },
|
|
37
27
|
get children() {
|
|
38
28
|
return [
|
|
39
|
-
createComponent(TSDoc, { heading: "Options for the PowerShell completions command." }),
|
|
40
|
-
createComponent(InterfaceDeclaration, {
|
|
41
|
-
"export": true,
|
|
42
|
-
name: "PowerShellCompletionsOptions",
|
|
43
|
-
get children() {
|
|
44
|
-
return [
|
|
45
|
-
createComponent(TSDoc, {
|
|
46
|
-
heading: "The path to write the completion script to.",
|
|
47
|
-
get children() {
|
|
48
|
-
return [createComponent(TSDocRemarks, { children: `If no extension is provided, the \`.ps1\` extension will be used.` }), createComponent(TSDocDefaultValue, {
|
|
49
|
-
get type() {
|
|
50
|
-
return ReflectionKind.string;
|
|
51
|
-
},
|
|
52
|
-
get defaultValue() {
|
|
53
|
-
return `${getAppBin(context)}-completions.ps1`;
|
|
54
|
-
}
|
|
55
|
-
})];
|
|
56
|
-
}
|
|
57
|
-
}),
|
|
58
|
-
createComponent(InterfaceMember, {
|
|
59
|
-
name: "script",
|
|
60
|
-
optional: true,
|
|
61
|
-
type: "string | true"
|
|
62
|
-
}),
|
|
63
|
-
createComponent(Spacing, {}),
|
|
64
|
-
createComponent(TSDoc, {
|
|
65
|
-
heading: "The PowerShell configuration file to append the completion script to.",
|
|
66
|
-
get children() {
|
|
67
|
-
return [createComponent(TSDocRemarks, { children: `The generated completion script will be appended to the specified configuration file. Possible values for the PowerShell configuration file include: \\n- \`~/.config/powershell/Microsoft.PowerShell_profile.ps1\`` }), createComponent(TSDocDefaultValue, {
|
|
68
|
-
get type() {
|
|
69
|
-
return ReflectionKind.string;
|
|
70
|
-
},
|
|
71
|
-
defaultValue: "~/.config/powershell/Microsoft.PowerShell_profile.ps1"
|
|
72
|
-
})];
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
75
|
-
createComponent(InterfaceMember, {
|
|
76
|
-
name: "config",
|
|
77
|
-
optional: true,
|
|
78
|
-
type: "string | true"
|
|
79
|
-
})
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
}),
|
|
83
29
|
createComponent(Spacing, {}),
|
|
84
|
-
createComponent(
|
|
85
|
-
|
|
30
|
+
createComponent(VarDeclaration, {
|
|
31
|
+
"const": true,
|
|
86
32
|
"export": true,
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
parameters: [{
|
|
91
|
-
name: "options",
|
|
92
|
-
type: "PowerShellCompletionsOptions"
|
|
93
|
-
}],
|
|
94
|
-
get children() {
|
|
95
|
-
return [
|
|
96
|
-
createComponent(VarDeclaration, {
|
|
97
|
-
"const": true,
|
|
98
|
-
name: "completions",
|
|
99
|
-
type: "string",
|
|
100
|
-
get initializer() {
|
|
101
|
-
return code`# powershell completion for ${getAppTitle(context)} -*- shell-script -*-
|
|
33
|
+
name: "SHELL_COMPLETIONS",
|
|
34
|
+
get initializer() {
|
|
35
|
+
return code` \`# powershell completion for ${getAppTitle(context)}
|
|
102
36
|
|
|
103
37
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
104
|
-
function __${
|
|
38
|
+
function __${name.value}_debug {
|
|
105
39
|
if ($env:BASH_COMP_DEBUG_FILE) {
|
|
106
40
|
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
|
|
107
41
|
}
|
|
108
42
|
}
|
|
109
43
|
|
|
110
|
-
filter __${
|
|
111
|
-
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','
|
|
44
|
+
filter __${name.value}_escapeStringWithSpecialChars {
|
|
45
|
+
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\\\`$&'
|
|
112
46
|
}
|
|
113
47
|
|
|
114
|
-
[scriptblock]$__${
|
|
48
|
+
[scriptblock]$__${name.value}CompleterBlock = {
|
|
115
49
|
param(
|
|
116
50
|
$WordToComplete,
|
|
117
51
|
$CommandAst,
|
|
@@ -122,9 +56,9 @@ function PowerShellCompletionsCommand() {
|
|
|
122
56
|
$Command = $CommandAst.CommandElements
|
|
123
57
|
$Command = "$Command"
|
|
124
58
|
|
|
125
|
-
__${
|
|
126
|
-
__${
|
|
127
|
-
__${
|
|
59
|
+
__${name.value}_debug ""
|
|
60
|
+
__${name.value}_debug "========= starting completion logic =========="
|
|
61
|
+
__${name.value}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
|
|
128
62
|
|
|
129
63
|
# The user could have moved the cursor backwards on the command-line.
|
|
130
64
|
# We need to trigger completion from the $CursorPosition location, so we need
|
|
@@ -134,7 +68,7 @@ function PowerShellCompletionsCommand() {
|
|
|
134
68
|
if ($Command.Length -gt $CursorPosition) {
|
|
135
69
|
$Command = $Command.Substring(0, $CursorPosition)
|
|
136
70
|
}
|
|
137
|
-
__${
|
|
71
|
+
__${name.value}_debug "Truncated command: $Command"
|
|
138
72
|
|
|
139
73
|
$ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}
|
|
140
74
|
$ShellCompDirectiveNoSpace=${CompletionDirective.CompletionDirectiveNoSpace}
|
|
@@ -148,10 +82,10 @@ function PowerShellCompletionsCommand() {
|
|
|
148
82
|
$Program, $Arguments = $Command.Split(" ", 2)
|
|
149
83
|
|
|
150
84
|
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
|
|
151
|
-
__${
|
|
85
|
+
__${name.value}_debug "QuotedArgs: $QuotedArgs"
|
|
152
86
|
|
|
153
|
-
$RequestComp = "& ${
|
|
154
|
-
__${
|
|
87
|
+
$RequestComp = "& ${EXEC_COMMAND} complete '--' $QuotedArgs"
|
|
88
|
+
__${name.value}_debug "RequestComp: $RequestComp"
|
|
155
89
|
|
|
156
90
|
# we cannot use $WordToComplete because it
|
|
157
91
|
# has the wrong values if the cursor was moved
|
|
@@ -159,13 +93,13 @@ function PowerShellCompletionsCommand() {
|
|
|
159
93
|
if ($WordToComplete -ne "" ) {
|
|
160
94
|
$WordToComplete = $Arguments.Split(" ")[-1]
|
|
161
95
|
}
|
|
162
|
-
__${
|
|
96
|
+
__${name.value}_debug "New WordToComplete: $WordToComplete"
|
|
163
97
|
|
|
164
98
|
|
|
165
99
|
# Check for flag with equal sign
|
|
166
100
|
$IsEqualFlag = ($WordToComplete -Like "--*=*" )
|
|
167
101
|
if ( $IsEqualFlag ) {
|
|
168
|
-
__${
|
|
102
|
+
__${name.value}_debug "Completing equal sign flag"
|
|
169
103
|
# Remove the flag part
|
|
170
104
|
$Flag, $WordToComplete = $WordToComplete.Split("=", 2)
|
|
171
105
|
}
|
|
@@ -173,20 +107,20 @@ function PowerShellCompletionsCommand() {
|
|
|
173
107
|
if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
|
|
174
108
|
# If the last parameter is complete (there is a space following it)
|
|
175
109
|
# We add an extra empty parameter so we can indicate this to the go method.
|
|
176
|
-
__${
|
|
110
|
+
__${name.value}_debug "Adding extra empty parameter"
|
|
177
111
|
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
|
|
178
112
|
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
|
|
179
113
|
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
|
|
180
114
|
($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
|
|
181
115
|
(($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
|
|
182
116
|
$PSNativeCommandArgumentPassing -eq 'Legacy')) {
|
|
183
|
-
$RequestComp="$RequestComp" + '
|
|
117
|
+
$RequestComp="$RequestComp" + ' \\\`"\\\`"'
|
|
184
118
|
} else {
|
|
185
119
|
$RequestComp = "$RequestComp" + ' ""'
|
|
186
120
|
}
|
|
187
121
|
}
|
|
188
122
|
|
|
189
|
-
__${
|
|
123
|
+
__${name.value}_debug "Calling $RequestComp"
|
|
190
124
|
# First disable ActiveHelp which is not supported for Powershell
|
|
191
125
|
$env:ActiveHelp = 0
|
|
192
126
|
|
|
@@ -200,22 +134,22 @@ function PowerShellCompletionsCommand() {
|
|
|
200
134
|
# There is no directive specified
|
|
201
135
|
$Directive = 0
|
|
202
136
|
}
|
|
203
|
-
__${
|
|
137
|
+
__${name.value}_debug "The completion directive is: $Directive"
|
|
204
138
|
|
|
205
139
|
# remove directive (last element) from out
|
|
206
140
|
$Out = $Out | Where-Object { $_ -ne $Out[-1] }
|
|
207
|
-
__${
|
|
141
|
+
__${name.value}_debug "The completions are: $Out"
|
|
208
142
|
if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
|
|
209
143
|
# Error code. No completion.
|
|
210
|
-
__${
|
|
144
|
+
__${name.value}_debug "Received error from custom completion go code"
|
|
211
145
|
return
|
|
212
146
|
}
|
|
213
147
|
|
|
214
148
|
$Longest = 0
|
|
215
149
|
[Array]$Values = $Out | ForEach-Object {
|
|
216
150
|
# Split the output in name and description
|
|
217
|
-
$Name, $Description = $_.Split("
|
|
218
|
-
__${
|
|
151
|
+
$Name, $Description = $_.Split("\\\`t", 2)
|
|
152
|
+
__${name.value}_debug "Name: $Name Description: $Description"
|
|
219
153
|
|
|
220
154
|
# Look for the longest completion so that we can format things nicely
|
|
221
155
|
if ($Longest -lt $Name.Length) {
|
|
@@ -234,13 +168,13 @@ function PowerShellCompletionsCommand() {
|
|
|
234
168
|
$Space = " "
|
|
235
169
|
if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
|
|
236
170
|
# remove the space here
|
|
237
|
-
__${
|
|
171
|
+
__${name.value}_debug "ShellCompDirectiveNoSpace is called"
|
|
238
172
|
$Space = ""
|
|
239
173
|
}
|
|
240
174
|
|
|
241
175
|
if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
|
|
242
176
|
(($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
|
|
243
|
-
__${
|
|
177
|
+
__${name.value}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
|
|
244
178
|
|
|
245
179
|
# return here to prevent the completion of the extensions
|
|
246
180
|
return
|
|
@@ -252,7 +186,7 @@ function PowerShellCompletionsCommand() {
|
|
|
252
186
|
|
|
253
187
|
# Join the flag back if we have an equal sign flag
|
|
254
188
|
if ( $IsEqualFlag ) {
|
|
255
|
-
__${
|
|
189
|
+
__${name.value}_debug "Join the equal sign flag back to the completion value"
|
|
256
190
|
$_.Name = $Flag + "=" + $_.Name
|
|
257
191
|
}
|
|
258
192
|
}
|
|
@@ -263,7 +197,7 @@ function PowerShellCompletionsCommand() {
|
|
|
263
197
|
}
|
|
264
198
|
|
|
265
199
|
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
|
|
266
|
-
__${
|
|
200
|
+
__${name.value}_debug "ShellCompDirectiveNoFileComp is called"
|
|
267
201
|
|
|
268
202
|
if ($Values.Length -eq 0) {
|
|
269
203
|
# Just print an empty string here so the
|
|
@@ -277,7 +211,7 @@ function PowerShellCompletionsCommand() {
|
|
|
277
211
|
|
|
278
212
|
# Get the current mode
|
|
279
213
|
$Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
|
|
280
|
-
__${
|
|
214
|
+
__${name.value}_debug "Mode: $Mode"
|
|
281
215
|
|
|
282
216
|
$Values | ForEach-Object {
|
|
283
217
|
|
|
@@ -293,7 +227,7 @@ function PowerShellCompletionsCommand() {
|
|
|
293
227
|
# CompletionResult Arguments:
|
|
294
228
|
# 1) CompletionText text to be used as the auto completion result
|
|
295
229
|
# 2) ListItemText text to be displayed in the suggestion list
|
|
296
|
-
# 3) ResultType
|
|
230
|
+
# 3) ResultType type of completion result
|
|
297
231
|
# 4) ToolTip text for the tooltip with details about the object
|
|
298
232
|
|
|
299
233
|
switch ($Mode) {
|
|
@@ -302,10 +236,10 @@ function PowerShellCompletionsCommand() {
|
|
|
302
236
|
"Complete" {
|
|
303
237
|
|
|
304
238
|
if ($Values.Length -eq 1) {
|
|
305
|
-
__${
|
|
239
|
+
__${name.value}_debug "Only one completion left"
|
|
306
240
|
|
|
307
241
|
# insert space after value
|
|
308
|
-
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
242
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
309
243
|
|
|
310
244
|
} else {
|
|
311
245
|
# Add the proper number of spaces to align the descriptions
|
|
@@ -329,7 +263,7 @@ function PowerShellCompletionsCommand() {
|
|
|
329
263
|
# insert space after value
|
|
330
264
|
# MenuComplete will automatically show the ToolTip of
|
|
331
265
|
# the highlighted value at the bottom of the suggestions.
|
|
332
|
-
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
266
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
333
267
|
}
|
|
334
268
|
|
|
335
269
|
# TabCompleteNext and in case we get something unknown
|
|
@@ -337,77 +271,43 @@ function PowerShellCompletionsCommand() {
|
|
|
337
271
|
# Like MenuComplete but we don't want to add a space here because
|
|
338
272
|
# the user need to press space anyway to get the completion.
|
|
339
273
|
# Description will not be shown because that's not possible with TabCompleteNext
|
|
340
|
-
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
274
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name.value}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
341
275
|
}
|
|
342
276
|
}
|
|
343
|
-
|
|
344
277
|
}
|
|
345
278
|
}
|
|
346
279
|
|
|
347
|
-
Register-ArgumentCompleter -CommandName '${
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
createComponent(Spacing, {}),
|
|
363
|
-
createComponent(IfStatement, {
|
|
364
|
-
condition: code`configFilePath.startsWith("~")`,
|
|
365
|
-
children: code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
|
|
366
|
-
}),
|
|
367
|
-
createComponent(Spacing, {}),
|
|
368
|
-
createComponent(VarDeclaration, {
|
|
369
|
-
"let": true,
|
|
370
|
-
name: "configFileContent",
|
|
371
|
-
type: "string",
|
|
372
|
-
initializer: code`"";`
|
|
373
|
-
}),
|
|
374
|
-
createComponent(Spacing, {}),
|
|
375
|
-
memo(() => code`try {
|
|
376
|
-
configFileContent = await readFile(configFilePath, "utf8");
|
|
377
|
-
} catch (error) {
|
|
378
|
-
if (error.code === "ENOENT") {
|
|
379
|
-
// If the file doesn't exist, we can create it later when writing the completion script.
|
|
380
|
-
warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
|
|
381
|
-
} else {
|
|
382
|
-
return { error };
|
|
383
|
-
}
|
|
280
|
+
Register-ArgumentCompleter -CommandName '${bin.value}' -ScriptBlock $__${name.value}CompleterBlock
|
|
281
|
+
\`; `;
|
|
282
|
+
}
|
|
283
|
+
}),
|
|
284
|
+
createComponent(Spacing, {}),
|
|
285
|
+
createComponent(VarDeclaration, {
|
|
286
|
+
"export": true,
|
|
287
|
+
"const": true,
|
|
288
|
+
name: "SHELL_COMPLETIONS_DISPLAY",
|
|
289
|
+
initializer: code` SHELL_COMPLETIONS.split("\\n").map(line => {
|
|
290
|
+
if (!line.trim()) {
|
|
291
|
+
return "";
|
|
292
|
+
}
|
|
293
|
+
if (line.trim().startsWith("#")) {
|
|
294
|
+
return \`\${colors.dim(line)}\`;
|
|
384
295
|
}
|
|
385
296
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
}),
|
|
402
|
-
createComponent(Spacing, {}),
|
|
403
|
-
createComponent(IfStatement, {
|
|
404
|
-
condition: code`!options.config && !options.script`,
|
|
405
|
-
children: code`writeLine(" ------------------------------------------------- ");
|
|
406
|
-
writeLine(completions);
|
|
407
|
-
writeLine(" ------------------------------------------------- ");`
|
|
408
|
-
})
|
|
409
|
-
];
|
|
410
|
-
}
|
|
297
|
+
return colors.white(line).replaceAll(/(?<=\\\$(\\{|\\()).*(?=(\\}\\)))/g, colors.green("$&"))
|
|
298
|
+
.replaceAll(/\\".*\\"/g, colors.cyan("$&"))
|
|
299
|
+
.replaceAll(/(\\[|\\]|\\(|\\)|\\||<|>|\\$\\(|\\$?\\{|\\}|\\+|=|;|::new|::OutputEncoding|::UTF8)/g, colors.bold(colors.gray("$&")))
|
|
300
|
+
.replaceAll(/(switch|complete)\\s+/g, colors.green("$&"))
|
|
301
|
+
.replaceAll(/(?<=(switch|complete)\\s+)\\w/g, colors.bold(colors.greenBright("$&")))
|
|
302
|
+
.replaceAll(/(Get-PSReadLineKeyHandler|Where-Object|ExperimentalFeature|Console|ScriptBlock|Array|ForEach-Object|Register-ArgumentCompleter|System.Management.Automation.CompletionResult|$\\w+)\\s+/g, colors.red("$&"))
|
|
303
|
+
.replaceAll(/(?<=(Get-PSReadLineKeyHandler|Where-Object|ExperimentalFeature|Console|ScriptBlock|Array|ForEach-Object|Register-ArgumentCompleter|System.Management.Automation.CompletionResult|$\\w+)\\s+)\\w/g, colors.bold(colors.redBright("$&")))
|
|
304
|
+
.replaceAll(/while\\s+/g, colors.cyan("$&"))
|
|
305
|
+
.replaceAll(/(?<=while\\s+)\\w/g, colors.bold(colors.cyanBright("$&")))
|
|
306
|
+
.replaceAll(/(if|fi|else|elif|then|done)\\s+/g, colors.green("$&"))
|
|
307
|
+
.replaceAll(/\\$?__\\w/g, colors.bold(colors.magentaBright("$&")))
|
|
308
|
+
.replaceAll(/(?<=\\s)(-\\w|--\\w[\\w-]*)(?=\\s|$)/g, colors.bold(colors.magenta("$&")));
|
|
309
|
+
|
|
310
|
+
}).join("\\n"); `
|
|
411
311
|
})
|
|
412
312
|
];
|
|
413
313
|
}
|
|
@@ -415,5 +315,5 @@ Register-ArgumentCompleter -CommandName '${getAppBin(context)}' -ScriptBlock $__
|
|
|
415
315
|
}
|
|
416
316
|
|
|
417
317
|
//#endregion
|
|
418
|
-
export {
|
|
419
|
-
//# sourceMappingURL=powershell-
|
|
318
|
+
export { PowerShellCompletionsShared };
|
|
319
|
+
//# sourceMappingURL=powershell-shared.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"powershell-shared.mjs","names":[],"sources":["../../src/components/powershell-shared.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed } from \"@alloy-js/core\";\nimport { VarDeclaration } from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { TypescriptFile } from \"@powerlines/plugin-alloy/typescript\";\nimport { getAppBin, getAppTitle } from \"@shell-shock/core/plugin-utils\";\nimport { joinPaths } from \"@stryke/path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { CompletionDirective } from \"../helpers\";\nimport { EXEC_COMMAND } from \"../helpers/complete-command\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The PowerShell Completions generation for the Shell Shock project.\n */\nexport function PowerShellCompletionsShared() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n const bin = computed(() => getAppBin(context));\n const name = computed(() => camelCase(bin.value));\n\n return (\n <TypescriptFile\n path={joinPaths(\n context.entryPath,\n \"completions\",\n \"powershell\",\n \"shared.ts\"\n )}\n builtinImports={{\n console: [\"colors\"]\n }}>\n <Spacing />\n <VarDeclaration\n const\n export\n name=\"SHELL_COMPLETIONS\"\n initializer={code` \\`# powershell completion for ${getAppTitle(context)}\n\n [Console]::OutputEncoding = [System.Text.Encoding]::UTF8\n function __${name.value}_debug {\n if ($env:BASH_COMP_DEBUG_FILE) {\n \"$args\" | Out-File -Append -FilePath \"$env:BASH_COMP_DEBUG_FILE\"\n }\n }\n\n filter __${name.value}_escapeStringWithSpecialChars {\n $_ -replace '\\\\s|#|@|\\\\$|;|,|''|\\\\{|\\\\}|\\\\(|\\\\)|\"|\\\\||<|>|&','\\\\\\`$&'\n }\n\n[scriptblock]$__${name.value}CompleterBlock = {\n param(\n $WordToComplete,\n $CommandAst,\n $CursorPosition\n )\n\n # Get the current command-line and convert into a string\n $Command = $CommandAst.CommandElements\n $Command = \"$Command\"\n\n __${name.value}_debug \"\"\n __${name.value}_debug \"========= starting completion logic ==========\"\n __${name.value}_debug \"WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition\"\n\n # The user could have moved the cursor backwards on the command-line.\n # We need to trigger completion from the $CursorPosition location, so we need\n # to truncate the command-line ($Command) up to the $CursorPosition location.\n # Make sure the $Command is longer then the $CursorPosition before we truncate.\n # This happens because the $Command does not include the last space.\n if ($Command.Length -gt $CursorPosition) {\n $Command = $Command.Substring(0, $CursorPosition)\n }\n __${name.value}_debug \"Truncated command: $Command\"\n\n $ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}\n $ShellCompDirectiveNoSpace=${CompletionDirective.CompletionDirectiveNoSpace}\n $ShellCompDirectiveNoFileComp=${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\n $ShellCompDirectiveFilterFileExt=${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\n $ShellCompDirectiveFilterDirs=${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\n $ShellCompDirectiveKeepOrder=${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n\n # Prepare the command to request completions for the program.\n # Split the command at the first space to separate the program and arguments.\n $Program, $Arguments = $Command.Split(\" \", 2)\n\n $QuotedArgs = ($Arguments -split ' ' | ForEach-Object { \"'\" + ($_ -replace \"'\", \"''\") + \"'\" }) -join ' '\n __${name.value}_debug \"QuotedArgs: $QuotedArgs\"\n\n $RequestComp = \"& ${EXEC_COMMAND} complete '--' $QuotedArgs\"\n __${name.value}_debug \"RequestComp: $RequestComp\"\n\n # we cannot use $WordToComplete because it\n # has the wrong values if the cursor was moved\n # so use the last argument\n if ($WordToComplete -ne \"\" ) {\n $WordToComplete = $Arguments.Split(\" \")[-1]\n }\n __${name.value}_debug \"New WordToComplete: $WordToComplete\"\n\n\n # Check for flag with equal sign\n $IsEqualFlag = ($WordToComplete -Like \"--*=*\" )\n if ( $IsEqualFlag ) {\n __${name.value}_debug \"Completing equal sign flag\"\n # Remove the flag part\n $Flag, $WordToComplete = $WordToComplete.Split(\"=\", 2)\n }\n\n if ( $WordToComplete -eq \"\" -And ( -Not $IsEqualFlag )) {\n # If the last parameter is complete (there is a space following it)\n # We add an extra empty parameter so we can indicate this to the go method.\n __${name.value}_debug \"Adding extra empty parameter\"\n # PowerShell 7.2+ changed the way how the arguments are passed to executables,\n # so for pre-7.2 or when Legacy argument passing is enabled we need to use\n if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or\n ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled(\"PSNativeCommandArgumentPassing\")) -or\n (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled(\"PSNativeCommandArgumentPassing\")) -and\n $PSNativeCommandArgumentPassing -eq 'Legacy')) {\n $RequestComp=\"$RequestComp\" + ' \\\\\\`\"\\\\\\`\"'\n } else {\n $RequestComp = \"$RequestComp\" + ' \"\"'\n }\n }\n\n __${name.value}_debug \"Calling $RequestComp\"\n # First disable ActiveHelp which is not supported for Powershell\n $env:ActiveHelp = 0\n\n # call the command store the output in $out and redirect stderr and stdout to null\n # $Out is an array contains each line per element\n Invoke-Expression -OutVariable out \"$RequestComp\" 2>&1 | Out-Null\n\n # get directive from last line\n [int]$Directive = $Out[-1].TrimStart(':')\n if ($Directive -eq \"\") {\n # There is no directive specified\n $Directive = 0\n }\n __${name.value}_debug \"The completion directive is: $Directive\"\n\n # remove directive (last element) from out\n $Out = $Out | Where-Object { $_ -ne $Out[-1] }\n __${name.value}_debug \"The completions are: $Out\"\n if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {\n # Error code. No completion.\n __${name.value}_debug \"Received error from custom completion go code\"\n return\n }\n\n $Longest = 0\n [Array]$Values = $Out | ForEach-Object {\n # Split the output in name and description\n $Name, $Description = $_.Split(\"\\\\\\`t\", 2)\n __${name.value}_debug \"Name: $Name Description: $Description\"\n\n # Look for the longest completion so that we can format things nicely\n if ($Longest -lt $Name.Length) {\n $Longest = $Name.Length\n }\n\n # Set the description to a one space string if there is none set.\n # This is needed because the CompletionResult does not accept an empty string as argument\n if (-Not $Description) {\n $Description = \" \"\n }\n @{ Name = \"$Name\"; Description = \"$Description\" }\n }\n\n\n $Space = \" \"\n if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {\n # remove the space here\n __${name.value}_debug \"ShellCompDirectiveNoSpace is called\"\n $Space = \"\"\n }\n\n if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or\n (($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {\n __${\n name.value\n }_debug \"ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported\"\n\n # return here to prevent the completion of the extensions\n return\n }\n\n $Values = $Values | Where-Object {\n # filter the result\n $_.Name -like \"$WordToComplete*\"\n\n # Join the flag back if we have an equal sign flag\n if ( $IsEqualFlag ) {\n __${\n name.value\n }_debug \"Join the equal sign flag back to the completion value\"\n $_.Name = $Flag + \"=\" + $_.Name\n }\n }\n\n # we sort the values in ascending order by name if keep order isn't passed\n if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {\n $Values = $Values | Sort-Object -Property Name\n }\n\n if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {\n __${name.value}_debug \"ShellCompDirectiveNoFileComp is called\"\n\n if ($Values.Length -eq 0) {\n # Just print an empty string here so the\n # shell does not start to complete paths.\n # We cannot use CompletionResult here because\n # it does not accept an empty string as argument.\n \"\"\n return\n }\n }\n\n # Get the current mode\n $Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq \"Tab\" }).Function\n __${name.value}_debug \"Mode: $Mode\"\n\n $Values | ForEach-Object {\n\n # store temporary because switch will overwrite $_\n $comp = $_\n\n # PowerShell supports three different completion modes\n # - TabCompleteNext (default windows style - on each key press the next option is displayed)\n # - Complete (works like bash)\n # - MenuComplete (works like zsh)\n # You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>\n\n # CompletionResult Arguments:\n # 1) CompletionText text to be used as the auto completion result\n # 2) ListItemText text to be displayed in the suggestion list\n # 3) ResultType type of completion result\n # 4) ToolTip text for the tooltip with details about the object\n\n switch ($Mode) {\n\n # bash like\n \"Complete\" {\n\n if ($Values.Length -eq 1) {\n __${name.value}_debug \"Only one completion left\"\n\n # insert space after value\n [System.Management.Automation.CompletionResult]::new($($comp.Name | __${\n name.value\n }_escapeStringWithSpecialChars) + $Space, \"$($comp.Name)\", 'ParameterValue', \"$($comp.Description)\")\n\n } else {\n # Add the proper number of spaces to align the descriptions\n while($comp.Name.Length -lt $Longest) {\n $comp.Name = $comp.Name + \" \"\n }\n\n # Check for empty description and only add parentheses if needed\n if ($($comp.Description) -eq \" \" ) {\n $Description = \"\"\n } else {\n $Description = \" ($($comp.Description))\"\n }\n\n [System.Management.Automation.CompletionResult]::new(\"$($comp.Name)$Description\", \"$($comp.Name)$Description\", 'ParameterValue', \"$($comp.Description)\")\n }\n }\n\n # zsh like\n \"MenuComplete\" {\n # insert space after value\n # MenuComplete will automatically show the ToolTip of\n # the highlighted value at the bottom of the suggestions.\n [System.Management.Automation.CompletionResult]::new($($comp.Name | __${\n name.value\n }_escapeStringWithSpecialChars) + $Space, \"$($comp.Name)\", 'ParameterValue', \"$($comp.Description)\")\n }\n\n # TabCompleteNext and in case we get something unknown\n Default {\n # Like MenuComplete but we don't want to add a space here because\n # the user need to press space anyway to get the completion.\n # Description will not be shown because that's not possible with TabCompleteNext\n [System.Management.Automation.CompletionResult]::new($($comp.Name | __${\n name.value\n }_escapeStringWithSpecialChars), \"$($comp.Name)\", 'ParameterValue', \"$($comp.Description)\")\n }\n }\n }\n}\n\nRegister-ArgumentCompleter -CommandName '${bin.value}' -ScriptBlock $__${\n name.value\n }CompleterBlock\n\\`; `}\n />\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"SHELL_COMPLETIONS_DISPLAY\"\n initializer={code` SHELL_COMPLETIONS.split(\"\\\\n\").map(line => {\n if (!line.trim()) {\n return \"\";\n }\n if (line.trim().startsWith(\"#\")) {\n return \\`\\${colors.dim(line)}\\`;\n }\n\n return colors.white(line).replaceAll(/(?<=\\\\\\$(\\\\{|\\\\()).*(?=(\\\\}\\\\)))/g, colors.green(\"$&\"))\n .replaceAll(/\\\\\".*\\\\\"/g, colors.cyan(\"$&\"))\n .replaceAll(/(\\\\[|\\\\]|\\\\(|\\\\)|\\\\||<|>|\\\\$\\\\(|\\\\$?\\\\{|\\\\}|\\\\+|=|;|::new|::OutputEncoding|::UTF8)/g, colors.bold(colors.gray(\"$&\")))\n .replaceAll(/(switch|complete)\\\\s+/g, colors.green(\"$&\"))\n .replaceAll(/(?<=(switch|complete)\\\\s+)\\\\w/g, colors.bold(colors.greenBright(\"$&\")))\n .replaceAll(/(Get-PSReadLineKeyHandler|Where-Object|ExperimentalFeature|Console|ScriptBlock|Array|ForEach-Object|Register-ArgumentCompleter|System.Management.Automation.CompletionResult|$\\\\w+)\\\\s+/g, colors.red(\"$&\"))\n .replaceAll(/(?<=(Get-PSReadLineKeyHandler|Where-Object|ExperimentalFeature|Console|ScriptBlock|Array|ForEach-Object|Register-ArgumentCompleter|System.Management.Automation.CompletionResult|$\\\\w+)\\\\s+)\\\\w/g, colors.bold(colors.redBright(\"$&\")))\n .replaceAll(/while\\\\s+/g, colors.cyan(\"$&\"))\n .replaceAll(/(?<=while\\\\s+)\\\\w/g, colors.bold(colors.cyanBright(\"$&\")))\n .replaceAll(/(if|fi|else|elif|then|done)\\\\s+/g, colors.green(\"$&\"))\n .replaceAll(/\\\\$?__\\\\w/g, colors.bold(colors.magentaBright(\"$&\")))\n .replaceAll(/(?<=\\\\s)(-\\\\w|--\\\\w[\\\\w-]*)(?=\\\\s|$)/g, colors.bold(colors.magenta(\"$&\")));\n\n }).join(\"\\\\n\"); `}\n />\n </TypescriptFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,SAAgB,8BAAgB;;CAE9B,MAAM,MAAM,eAAe,UAAU,QAAQ,CAAC;CAC9C,MAAM,OAAO,eAAe,UAAU,IAAI,MAAM,CAAC;;EAEjD,IAAM,OAAC;AACJ,UAAA,UAAA,QAAA,WAAA,eAAA,cAAA,YAAA;;EAED,gBAAY,EACV,SAAG,CAAA,SAAY,EAChB;EACD,IAAI,WAAU;AACZ,UAAC;IAAA,gBAAA,SAAA,EAAA,CAAA;IAAA,gBAAA,gBAAA;KACD,SAAA;KACE,UAAU;KACV,MAAA;KACD,IAAA,cAAS;AACT,aAAA,IAAA,kCAAA,YAAA,QAAA,CAAA;;;iBAGO,KAAA,MAAA;;;;;;eAMA,KAAM,MAAM;;;;kBAIX,KAAK,MAAM;;;;;;;;;;;QAWpB,KAAO,MAAC;QACT,KAAQ,MAAG;QACX,KAAQ,MAAI;;;;;;;;;;QAUX,KAAK,MAAQ;;+BAES,oBAAc,yBAAc;iCACpD,oBAAA,2BAAA;oCACgC,oBAAkB,8BAAA;;oCAEvB,oBAAoB,8BAAwB;mCAC1C,oBAAoB,6BAA0B;;;;;;;QAO1E,KAAA,MAAA;;wBAED,aAAA;QACC,KAAA,MAAA;;;;;;;;QAQA,KAAA,MAAc;;;;;;YAMV,KAAO,MAAK;;;;;;;;;;;;;;;;;;;;;QAqBb,KAAE,MAAA;;;;;;;;;;;;;;QAcF,KAAC,MAAU;;;;QAIf,KAAO,MAAA;;;YAGD,KAAA,MAAa;;;;;;;;YAQX,KAAK,MAAM;;;;;;;;;;;;;;;;;;;YAmBb,KAAO,MAAC;;;;;;YAMd,KAAA,MAAA;;;;;;;;;;;;gBAYO,KAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkDW,KAAM,MAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;wFA2Bb,KAAA,MAAA;;;;;;;;;;;;;;2CAcO,IAAA,MAAA,oBAAA,KAAA,MAAA;;;KAGpB,CAAC;IAAE,gBAAY,SAAY,EAAK,CAAC;IAAE,gBAAkB,gBAAY;KAChE,UAAS;KACT,SAAS;KACT,MAAM;KACN,aAAI,IAAA;;;;;;;;;;;;;;;;;;;;;;KAsBL,CAAC;IAAA;;EAEL,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
3
|
+
let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
|
|
4
|
+
let _alloy_js_core = require("@alloy-js/core");
|
|
5
|
+
let _alloy_js_typescript = require("@alloy-js/typescript");
|
|
6
|
+
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
7
|
+
let _powerlines_plugin_alloy_core = require("@powerlines/plugin-alloy/core");
|
|
8
|
+
let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
|
|
9
|
+
let _powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
|
|
10
|
+
let _powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
|
|
11
|
+
let _stryke_path = require("@stryke/path");
|
|
12
|
+
|
|
13
|
+
//#region src/components/zsh-config-command.tsx
|
|
14
|
+
/**
|
|
15
|
+
* The Zsh Completions - Configuration command's handler wrapper for the Shell Shock project.
|
|
16
|
+
*/
|
|
17
|
+
function ZshConfigCompletionsCommand() {
|
|
18
|
+
const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
19
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.TypescriptFile, {
|
|
20
|
+
get path() {
|
|
21
|
+
return (0, _stryke_path.joinPaths)(context.entryPath, "completions", "zsh", "config", "command.ts");
|
|
22
|
+
},
|
|
23
|
+
imports: {
|
|
24
|
+
"node:os": "os",
|
|
25
|
+
"node:path": ["join"],
|
|
26
|
+
"node:fs/promises": ["readFile", "writeFile"],
|
|
27
|
+
"../shared": ["SHELL_COMPLETIONS", "SHELL_COMPLETIONS_DISPLAY"]
|
|
28
|
+
},
|
|
29
|
+
builtinImports: { "shell-shock:console": [
|
|
30
|
+
"colors",
|
|
31
|
+
"writeLine",
|
|
32
|
+
"success",
|
|
33
|
+
"warn"
|
|
34
|
+
] },
|
|
35
|
+
get children() {
|
|
36
|
+
return [
|
|
37
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Options for the Zsh Completions - Configuration command." }),
|
|
38
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
39
|
+
"export": true,
|
|
40
|
+
name: "ZshConfigCompletionsOptions",
|
|
41
|
+
get children() {
|
|
42
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
43
|
+
heading: "Should the generated completion script be written to console output instead of an actual file on disk? This is useful for debugging purposes or if you want to manually handle the output.",
|
|
44
|
+
get children() {
|
|
45
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
|
|
46
|
+
get type() {
|
|
47
|
+
return _powerlines_deepkit_vendor_type.ReflectionKind.boolean;
|
|
48
|
+
},
|
|
49
|
+
defaultValue: false
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.InterfaceMember, {
|
|
53
|
+
name: "display",
|
|
54
|
+
optional: true,
|
|
55
|
+
type: "boolean"
|
|
56
|
+
})];
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
60
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Handler logic for the \\`completions zsh config\\` command." }),
|
|
61
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
62
|
+
"export": true,
|
|
63
|
+
"default": true,
|
|
64
|
+
async: true,
|
|
65
|
+
name: "handler",
|
|
66
|
+
parameters: [{
|
|
67
|
+
name: "options",
|
|
68
|
+
type: "ZshConfigCompletionsOptions",
|
|
69
|
+
default: "{}"
|
|
70
|
+
}, {
|
|
71
|
+
name: "path",
|
|
72
|
+
type: "string",
|
|
73
|
+
default: `"~/.zshrc"`
|
|
74
|
+
}],
|
|
75
|
+
get children() {
|
|
76
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
77
|
+
condition: _alloy_js_core.code`options.display !== true`,
|
|
78
|
+
get children() {
|
|
79
|
+
return [
|
|
80
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
81
|
+
"let": true,
|
|
82
|
+
name: "configPath",
|
|
83
|
+
type: "string",
|
|
84
|
+
initializer: _alloy_js_core.code` path.includes(".") ? path : join(path, ".zshrc");`
|
|
85
|
+
}),
|
|
86
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
87
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
88
|
+
condition: _alloy_js_core.code`configPath.startsWith("~")`,
|
|
89
|
+
children: _alloy_js_core.code`configPath = join(os.homedir(), configPath.replace("~", "")); `
|
|
90
|
+
}),
|
|
91
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
92
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
93
|
+
"let": true,
|
|
94
|
+
name: "content",
|
|
95
|
+
type: "string",
|
|
96
|
+
initializer: _alloy_js_core.code`"";`
|
|
97
|
+
}),
|
|
98
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
99
|
+
(0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`try {
|
|
100
|
+
content = await readFile(configPath, "utf8");
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
103
|
+
// If the file doesn't exist, we can create it later when writing the completion script.
|
|
104
|
+
warn(\`Configuration file \${colors.bold(configPath)} does not exist. It will be created when the completion script is written.\`);
|
|
105
|
+
} else {
|
|
106
|
+
return { error };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await writeFile(configPath, \`\${content}\\n\\n### Begin - ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} Shell Completions ###\\n\\n\${SHELL_COMPLETIONS} \\n\\n### End - ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} Zsh Completions ###\`);
|
|
111
|
+
|
|
112
|
+
success(\`${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} shell completions have been applied to Zsh configuration file at \${colors.bold(configPath)}. Please restart your terminal or run \\\`source \${configPath}\\\` for the changes to take effect.\`); `)
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.ElseClause, { get children() {
|
|
116
|
+
return _alloy_js_core.code`writeLine(" ------------------------------------------------- ");
|
|
117
|
+
writeLine(\`### Begin - ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} Zsh Completions ###\`);
|
|
118
|
+
writeLine("");
|
|
119
|
+
SHELL_COMPLETIONS_DISPLAY.split("\\n").map(line => writeLine(line));
|
|
120
|
+
writeLine("");
|
|
121
|
+
writeLine(\`### End - ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} Zsh Completions ###\`);
|
|
122
|
+
writeLine(" ------------------------------------------------- ");`;
|
|
123
|
+
} })];
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
exports.ZshConfigCompletionsCommand = ZshConfigCompletionsCommand;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _$_alloy_js_core0 from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/components/zsh-config-command.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Zsh Completions - Configuration command's handler wrapper for the Shell Shock project.
|
|
6
|
+
*/
|
|
7
|
+
declare function ZshConfigCompletionsCommand(): _$_alloy_js_core0.Children;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ZshConfigCompletionsCommand };
|
|
10
|
+
//# sourceMappingURL=zsh-config-command.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh-config-command.d.cts","names":[],"sources":["../../src/components/zsh-config-command.tsx"],"mappings":";;;;;;iBA4CgB,2BAAA,CAAA,GAA2B,iBAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _$_alloy_js_core0 from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/components/zsh-config-command.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Zsh Completions - Configuration command's handler wrapper for the Shell Shock project.
|
|
6
|
+
*/
|
|
7
|
+
declare function ZshConfigCompletionsCommand(): _$_alloy_js_core0.Children;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ZshConfigCompletionsCommand };
|
|
10
|
+
//# sourceMappingURL=zsh-config-command.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh-config-command.d.mts","names":[],"sources":["../../src/components/zsh-config-command.tsx"],"mappings":";;;;;;iBA4CgB,2BAAA,CAAA,GAA2B,iBAAA,CAAA,QAAA"}
|