@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,273 +0,0 @@
|
|
|
1
|
-
import { exec } from "../helpers/complete-command.mjs";
|
|
2
|
-
import { CompletionDirective } from "../helpers/completion-directive-constants.mjs";
|
|
3
|
-
import "../helpers/index.mjs";
|
|
4
|
-
import { createComponent, memo } from "@alloy-js/core/jsx-runtime";
|
|
5
|
-
import { getAppBin, getAppTitle } from "@shell-shock/core/plugin-utils";
|
|
6
|
-
import { joinPaths } from "@stryke/path";
|
|
7
|
-
import { code } from "@alloy-js/core";
|
|
8
|
-
import { FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
|
|
9
|
-
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
10
|
-
import { Spacing } from "@powerlines/plugin-alloy/core";
|
|
11
|
-
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
|
|
12
|
-
import { InterfaceMember, TypescriptFile } from "@powerlines/plugin-alloy/typescript";
|
|
13
|
-
import { TSDoc, TSDocDefaultValue, TSDocRemarks } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
|
|
14
|
-
import { snakeCase } from "@stryke/string-format/snake-case";
|
|
15
|
-
|
|
16
|
-
//#region src/components/bash-command.tsx
|
|
17
|
-
/**
|
|
18
|
-
* The Bash Completions commands' handler wrapper for the Shell Shock project.
|
|
19
|
-
*/
|
|
20
|
-
function BashCompletionsCommand() {
|
|
21
|
-
const context = usePowerlines();
|
|
22
|
-
return createComponent(TypescriptFile, {
|
|
23
|
-
get path() {
|
|
24
|
-
return joinPaths(context.entryPath, "completions", "bash", "command.ts");
|
|
25
|
-
},
|
|
26
|
-
imports: {
|
|
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
|
-
] },
|
|
37
|
-
get children() {
|
|
38
|
-
return [
|
|
39
|
-
createComponent(TSDoc, { heading: "Options for the Bash completions command." }),
|
|
40
|
-
createComponent(InterfaceDeclaration, {
|
|
41
|
-
"export": true,
|
|
42
|
-
name: "BashCompletionsOptions",
|
|
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 \`.bash\` extension will be used.` }), createComponent(TSDocDefaultValue, {
|
|
49
|
-
get type() {
|
|
50
|
-
return ReflectionKind.string;
|
|
51
|
-
},
|
|
52
|
-
get defaultValue() {
|
|
53
|
-
return `${getAppBin(context)}-completions.bash`;
|
|
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 Bash 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 Bash configuration file include: \\n- \`~/.bashrc\` \\n- \`~/.bash_profile\`` }), createComponent(TSDocDefaultValue, {
|
|
68
|
-
get type() {
|
|
69
|
-
return ReflectionKind.string;
|
|
70
|
-
},
|
|
71
|
-
defaultValue: "~/.bashrc"
|
|
72
|
-
})];
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
75
|
-
createComponent(InterfaceMember, {
|
|
76
|
-
name: "config",
|
|
77
|
-
optional: true,
|
|
78
|
-
type: "string | true"
|
|
79
|
-
})
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
}),
|
|
83
|
-
createComponent(Spacing, {}),
|
|
84
|
-
createComponent(TSDoc, { heading: "Handler logic for the \\`completions bash\\` command." }),
|
|
85
|
-
createComponent(FunctionDeclaration, {
|
|
86
|
-
"export": true,
|
|
87
|
-
"default": true,
|
|
88
|
-
async: true,
|
|
89
|
-
name: "handler",
|
|
90
|
-
parameters: [{
|
|
91
|
-
name: "options",
|
|
92
|
-
type: "BashCompletionsOptions"
|
|
93
|
-
}],
|
|
94
|
-
get children() {
|
|
95
|
-
return [
|
|
96
|
-
createComponent(VarDeclaration, {
|
|
97
|
-
"const": true,
|
|
98
|
-
name: "completions",
|
|
99
|
-
type: "string",
|
|
100
|
-
get initializer() {
|
|
101
|
-
return code`# bash completion for ${getAppTitle(context)}
|
|
102
|
-
|
|
103
|
-
# Define shell completion directives
|
|
104
|
-
readonly ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}
|
|
105
|
-
readonly ShellCompDirectiveNoSpace=${CompletionDirective.CompletionDirectiveNoSpace}
|
|
106
|
-
readonly ShellCompDirectiveNoFileComp=${CompletionDirective.CompletionDirectiveNoFileComp}
|
|
107
|
-
readonly ShellCompDirectiveFilterFileExt=${CompletionDirective.CompletionDirectiveFilterFileExt}
|
|
108
|
-
readonly ShellCompDirectiveFilterDirs=${CompletionDirective.CompletionDirectiveFilterDirs}
|
|
109
|
-
readonly ShellCompDirectiveKeepOrder=${CompletionDirective.CompletionDirectiveKeepOrder}
|
|
110
|
-
|
|
111
|
-
# Function to debug completion
|
|
112
|
-
__${snakeCase(getAppBin(context))}_debug() {
|
|
113
|
-
if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
|
|
114
|
-
echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
|
|
115
|
-
fi
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
# Function to handle completions
|
|
119
|
-
__${snakeCase(getAppBin(context))}_complete() {
|
|
120
|
-
local cur prev words cword
|
|
121
|
-
_get_comp_words_by_ref -n "=:" cur prev words cword
|
|
122
|
-
|
|
123
|
-
local requestComp out directive
|
|
124
|
-
|
|
125
|
-
# Build the command to get completions
|
|
126
|
-
requestComp="${exec} complete -- \${words[@]:1}"
|
|
127
|
-
|
|
128
|
-
# Add an empty parameter if the last parameter is complete
|
|
129
|
-
if [[ -z "$cur" ]]; then
|
|
130
|
-
requestComp="$requestComp ''"
|
|
131
|
-
fi
|
|
132
|
-
|
|
133
|
-
# Get completions from the program
|
|
134
|
-
out=$(eval "$requestComp" 2>/dev/null)
|
|
135
|
-
|
|
136
|
-
# Extract directive if present
|
|
137
|
-
directive=0
|
|
138
|
-
if [[ "$out" == *:* ]]; then
|
|
139
|
-
directive=\${out##*:}
|
|
140
|
-
out=\${out%:*}
|
|
141
|
-
fi
|
|
142
|
-
|
|
143
|
-
# Process completions based on directive
|
|
144
|
-
if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then
|
|
145
|
-
# Error, no completion
|
|
146
|
-
return
|
|
147
|
-
fi
|
|
148
|
-
|
|
149
|
-
# Apply directives
|
|
150
|
-
if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then
|
|
151
|
-
compopt -o nospace
|
|
152
|
-
fi
|
|
153
|
-
if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then
|
|
154
|
-
compopt -o nosort
|
|
155
|
-
fi
|
|
156
|
-
if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then
|
|
157
|
-
compopt +o default
|
|
158
|
-
fi
|
|
159
|
-
|
|
160
|
-
# Handle file extension filtering
|
|
161
|
-
if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then
|
|
162
|
-
local filter=""
|
|
163
|
-
for ext in $out; do
|
|
164
|
-
filter="$filter|$ext"
|
|
165
|
-
done
|
|
166
|
-
filter="\\.($filter)"
|
|
167
|
-
compopt -o filenames
|
|
168
|
-
COMPREPLY=( $(compgen -f -X "!$filter" -- "$cur") )
|
|
169
|
-
return
|
|
170
|
-
fi
|
|
171
|
-
|
|
172
|
-
# Handle directory filtering
|
|
173
|
-
if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then
|
|
174
|
-
compopt -o dirnames
|
|
175
|
-
COMPREPLY=( $(compgen -d -- "$cur") )
|
|
176
|
-
return
|
|
177
|
-
fi
|
|
178
|
-
|
|
179
|
-
# Process completions
|
|
180
|
-
local IFS=$'\\n'
|
|
181
|
-
local tab=$(printf '\\t')
|
|
182
|
-
|
|
183
|
-
# Parse completions with descriptions
|
|
184
|
-
local completions=()
|
|
185
|
-
while read -r comp; do
|
|
186
|
-
if [[ "$comp" == *$tab* ]]; then
|
|
187
|
-
# Split completion and description
|
|
188
|
-
local value=\${comp%%$tab*}
|
|
189
|
-
local desc=\${comp#*$tab}
|
|
190
|
-
completions+=("$value")
|
|
191
|
-
else
|
|
192
|
-
completions+=("$comp")
|
|
193
|
-
fi
|
|
194
|
-
done <<< "$out"
|
|
195
|
-
|
|
196
|
-
# Return completions
|
|
197
|
-
COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
# Register completion function
|
|
201
|
-
complete -F __${snakeCase(getAppBin(context))}_complete ${getAppBin(context)}
|
|
202
|
-
\`); `;
|
|
203
|
-
}
|
|
204
|
-
}),
|
|
205
|
-
createComponent(Spacing, {}),
|
|
206
|
-
createComponent(IfStatement, {
|
|
207
|
-
condition: code`options.config`,
|
|
208
|
-
get children() {
|
|
209
|
-
return [
|
|
210
|
-
createComponent(VarDeclaration, {
|
|
211
|
-
"let": true,
|
|
212
|
-
name: "configFilePath",
|
|
213
|
-
type: "string",
|
|
214
|
-
initializer: code`options.config === true ? "~/.bashrc" : options.config`
|
|
215
|
-
}),
|
|
216
|
-
createComponent(Spacing, {}),
|
|
217
|
-
createComponent(IfStatement, {
|
|
218
|
-
condition: code`configFilePath.startsWith("~")`,
|
|
219
|
-
children: code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
|
|
220
|
-
}),
|
|
221
|
-
createComponent(Spacing, {}),
|
|
222
|
-
createComponent(VarDeclaration, {
|
|
223
|
-
"let": true,
|
|
224
|
-
name: "configFileContent",
|
|
225
|
-
type: "string",
|
|
226
|
-
initializer: code`"";`
|
|
227
|
-
}),
|
|
228
|
-
createComponent(Spacing, {}),
|
|
229
|
-
memo(() => code`try {
|
|
230
|
-
configFileContent = await readFile(configFilePath, "utf8");
|
|
231
|
-
} catch (error) {
|
|
232
|
-
if (error.code === "ENOENT") {
|
|
233
|
-
// If the file doesn't exist, we can create it later when writing the completion script.
|
|
234
|
-
warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
|
|
235
|
-
} else {
|
|
236
|
-
return { error };
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
await writeFile(configFilePath, \`\${configFileContent}\\n\\n\${stripAnsi(completions)}\`);
|
|
241
|
-
|
|
242
|
-
success(\`${getAppTitle(context)} Bash completion script has been generated and appended to \${colors.bold(configFilePath)}. Please restart your terminal or run \`source \${configFilePath}\` to apply the changes.\`); `)
|
|
243
|
-
];
|
|
244
|
-
}
|
|
245
|
-
}),
|
|
246
|
-
createComponent(Spacing, {}),
|
|
247
|
-
createComponent(IfStatement, {
|
|
248
|
-
condition: code`options.script`,
|
|
249
|
-
get children() {
|
|
250
|
-
return code`const outputPath = options.script === true ? "${getAppBin(context)}-completions.bash" : options.script;
|
|
251
|
-
await writeFile(outputPath, stripAnsi(completions));
|
|
252
|
-
|
|
253
|
-
success(\`${getAppTitle(context)} Bash completion script has been generated at \${colors.bold(outputPath)}.\`);`;
|
|
254
|
-
}
|
|
255
|
-
}),
|
|
256
|
-
createComponent(Spacing, {}),
|
|
257
|
-
createComponent(IfStatement, {
|
|
258
|
-
condition: code`!options.config && !options.script`,
|
|
259
|
-
children: code`writeLine(" ------------------------------------------------- ");
|
|
260
|
-
writeLine(completions);
|
|
261
|
-
writeLine(" ------------------------------------------------- ");`
|
|
262
|
-
})
|
|
263
|
-
];
|
|
264
|
-
}
|
|
265
|
-
})
|
|
266
|
-
];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
//#endregion
|
|
272
|
-
export { BashCompletionsCommand };
|
|
273
|
-
//# sourceMappingURL=bash-command.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash-command.mjs","names":[],"sources":["../../src/components/bash-command.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 } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n IfStatement,\n InterfaceDeclaration,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport {\n InterfaceMember,\n TypescriptFile\n} from \"@powerlines/plugin-alloy/typescript\";\nimport {\n TSDoc,\n TSDocDefaultValue,\n TSDocRemarks\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppBin, getAppTitle } from \"@shell-shock/core/plugin-utils\";\nimport { joinPaths } from \"@stryke/path\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport { CompletionDirective } from \"../helpers\";\nimport { exec } from \"../helpers/complete-command\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Bash Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function BashCompletionsCommand() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n return (\n <TypescriptFile\n path={joinPaths(context.entryPath, \"completions\", \"bash\", \"command.ts\")}\n imports={{\n \"node:os\": [\"os\"],\n \"node:fs/promises\": [\"readFile\", \"writeFile\"]\n }}\n builtinImports={{\n \"shell-shock:console\": [\n \"colors\",\n \"writeLine\",\n \"success\",\n \"warn\",\n \"stripAnsi\"\n ]\n }}>\n <TSDoc heading=\"Options for the Bash completions command.\" />\n <InterfaceDeclaration export name=\"BashCompletionsOptions\">\n <TSDoc heading=\"The path to write the completion script to.\">\n <TSDocRemarks>{`If no extension is provided, the \\`.bash\\` extension will be used.`}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue={`${getAppBin(context)}-completions.bash`}\n />\n </TSDoc>\n <InterfaceMember name=\"script\" optional type=\"string | true\" />\n <Spacing />\n <TSDoc heading=\"The Bash configuration file to append the completion script to.\">\n <TSDocRemarks>{`The generated completion script will be appended to the specified configuration file. Possible values for the Bash configuration file include: \\\\n- \\`~/.bashrc\\` \\\\n- \\`~/.bash_profile\\``}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue=\"~/.bashrc\"\n />\n </TSDoc>\n <InterfaceMember name=\"config\" optional type=\"string | true\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Handler logic for the \\`completions bash\\` command.\"></TSDoc>\n <FunctionDeclaration\n export\n default\n async\n name=\"handler\"\n parameters={[{ name: \"options\", type: \"BashCompletionsOptions\" }]}>\n <VarDeclaration\n const\n name=\"completions\"\n type=\"string\"\n initializer={code`# bash completion for ${getAppTitle(context)}\n\n# Define shell completion directives\nreadonly ShellCompDirectiveError=${CompletionDirective.CompletionDirectiveError}\nreadonly ShellCompDirectiveNoSpace=${\n CompletionDirective.CompletionDirectiveNoSpace\n }\nreadonly ShellCompDirectiveNoFileComp=${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\nreadonly ShellCompDirectiveFilterFileExt=${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\nreadonly ShellCompDirectiveFilterDirs=${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\nreadonly ShellCompDirectiveKeepOrder=${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n\n# Function to debug completion\n__${snakeCase(getAppBin(context))}_debug() {\n if [[ -n \\${BASH_COMP_DEBUG_FILE:-} ]]; then\n echo \"$*\" >> \"\\${BASH_COMP_DEBUG_FILE}\"\n fi\n}\n\n# Function to handle completions\n__${snakeCase(getAppBin(context))}_complete() {\n local cur prev words cword\n _get_comp_words_by_ref -n \"=:\" cur prev words cword\n\n local requestComp out directive\n\n # Build the command to get completions\n requestComp=\"${exec} complete -- \\${words[@]:1}\"\n\n # Add an empty parameter if the last parameter is complete\n if [[ -z \"$cur\" ]]; then\n requestComp=\"$requestComp ''\"\n fi\n\n # Get completions from the program\n out=$(eval \"$requestComp\" 2>/dev/null)\n\n # Extract directive if present\n directive=0\n if [[ \"$out\" == *:* ]]; then\n directive=\\${out##*:}\n out=\\${out%:*}\n fi\n\n # Process completions based on directive\n if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then\n # Error, no completion\n return\n fi\n\n # Apply directives\n if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then\n compopt -o nospace\n fi\n if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then\n compopt -o nosort\n fi\n if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then\n compopt +o default\n fi\n\n # Handle file extension filtering\n if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then\n local filter=\"\"\n for ext in $out; do\n filter=\"$filter|$ext\"\n done\n filter=\"\\\\.($filter)\"\n compopt -o filenames\n COMPREPLY=( $(compgen -f -X \"!$filter\" -- \"$cur\") )\n return\n fi\n\n # Handle directory filtering\n if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then\n compopt -o dirnames\n COMPREPLY=( $(compgen -d -- \"$cur\") )\n return\n fi\n\n # Process completions\n local IFS=$'\\\\n'\n local tab=$(printf '\\\\t')\n\n # Parse completions with descriptions\n local completions=()\n while read -r comp; do\n if [[ \"$comp\" == *$tab* ]]; then\n # Split completion and description\n local value=\\${comp%%$tab*}\n local desc=\\${comp#*$tab}\n completions+=(\"$value\")\n else\n completions+=(\"$comp\")\n fi\n done <<< \"$out\"\n\n # Return completions\n COMPREPLY=( $(compgen -W \"\\${completions[*]}\" -- \"$cur\") )\n}\n\n# Register completion function\ncomplete -F __${snakeCase(getAppBin(context))}_complete ${getAppBin(context)}\n\\`); `}\n />\n <Spacing />\n <IfStatement condition={code`options.config`}>\n <VarDeclaration\n let\n name=\"configFilePath\"\n type=\"string\"\n initializer={code`options.config === true ? \"~/.bashrc\" : options.config`}\n />\n <Spacing />\n <IfStatement condition={code`configFilePath.startsWith(\"~\")`}>\n {code`configFilePath = join(os.homedir(), configFilePath.replace(\"~\", \"\")); `}\n </IfStatement>\n <Spacing />\n <VarDeclaration\n let\n name=\"configFileContent\"\n type=\"string\"\n initializer={code`\"\";`}\n />\n <Spacing />\n {code`try {\n configFileContent = await readFile(configFilePath, \"utf8\");\n } catch (error) {\n if (error.code === \"ENOENT\") {\n // If the file doesn't exist, we can create it later when writing the completion script.\n warn(\\`Configuration file \\${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\\`);\n } else {\n return { error };\n }\n }\n\n await writeFile(configFilePath, \\`\\${configFileContent}\\\\n\\\\n\\${stripAnsi(completions)}\\`);\n\n success(\\`${getAppTitle(context)} Bash completion script has been generated and appended to \\${colors.bold(configFilePath)}. Please restart your terminal or run \\`source \\${configFilePath}\\` to apply the changes.\\`); `}\n </IfStatement>\n <Spacing />\n <IfStatement condition={code`options.script`}>\n {code`const outputPath = options.script === true ? \"${getAppBin(context)}-completions.bash\" : options.script;\n await writeFile(outputPath, stripAnsi(completions));\n\n success(\\`${getAppTitle(context)} Bash completion script has been generated at \\${colors.bold(outputPath)}.\\`);`}\n </IfStatement>\n <Spacing />\n <IfStatement condition={code`!options.config && !options.script`}>\n {code`writeLine(\" ------------------------------------------------- \");\n writeLine(completions);\n writeLine(\" ------------------------------------------------- \");`}\n </IfStatement>\n </FunctionDeclaration>\n </TypescriptFile>\n );\n}\n"],"mappings":"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"}
|