@shell-shock/plugin-completions 0.1.14 → 0.2.1
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/dist/components/bash-command.cjs +101 -25
- package/dist/components/bash-command.d.cts +2 -2
- package/dist/components/bash-command.d.cts.map +1 -1
- package/dist/components/bash-command.d.mts +2 -2
- package/dist/components/bash-command.d.mts.map +1 -1
- package/dist/components/bash-command.mjs +101 -25
- package/dist/components/bash-command.mjs.map +1 -1
- package/dist/components/fish-command.cjs +402 -0
- package/dist/components/fish-command.d.cts +10 -0
- package/dist/components/fish-command.d.cts.map +1 -0
- package/dist/components/fish-command.d.mts +10 -0
- package/dist/components/fish-command.d.mts.map +1 -0
- package/dist/components/fish-command.mjs +403 -0
- package/dist/components/fish-command.mjs.map +1 -0
- package/dist/components/index.cjs +4 -0
- package/dist/components/index.d.cts +3 -1
- package/dist/components/index.d.mts +3 -1
- package/dist/components/index.mjs +3 -1
- package/dist/components/powershell-command.cjs +418 -0
- package/dist/components/powershell-command.d.cts +10 -0
- package/dist/components/powershell-command.d.cts.map +1 -0
- package/dist/components/powershell-command.d.mts +10 -0
- package/dist/components/powershell-command.d.mts.map +1 -0
- package/dist/components/powershell-command.mjs +419 -0
- package/dist/components/powershell-command.mjs.map +1 -0
- package/dist/components/zsh-command.cjs +213 -26
- package/dist/components/zsh-command.d.cts +2 -2
- package/dist/components/zsh-command.d.cts.map +1 -1
- package/dist/components/zsh-command.d.mts.map +1 -1
- package/dist/components/zsh-command.mjs +213 -26
- package/dist/components/zsh-command.mjs.map +1 -1
- package/dist/helpers/complete-command.cjs +14 -0
- package/dist/helpers/complete-command.d.cts +5 -0
- package/dist/helpers/complete-command.d.cts.map +1 -0
- package/dist/helpers/complete-command.d.mts +5 -0
- package/dist/helpers/complete-command.d.mts.map +1 -0
- package/dist/helpers/complete-command.mjs +14 -0
- package/dist/helpers/complete-command.mjs.map +1 -0
- package/dist/helpers/completion-directive-constants.cjs +15 -0
- package/dist/helpers/completion-directive-constants.d.cts +14 -0
- package/dist/helpers/completion-directive-constants.d.cts.map +1 -0
- package/dist/helpers/completion-directive-constants.d.mts +14 -0
- package/dist/helpers/completion-directive-constants.d.mts.map +1 -0
- package/dist/helpers/completion-directive-constants.mjs +15 -0
- package/dist/helpers/completion-directive-constants.mjs.map +1 -0
- package/dist/helpers/index.cjs +5 -0
- package/dist/helpers/index.d.cts +3 -0
- package/dist/helpers/index.d.mts +3 -0
- package/dist/helpers/index.mjs +4 -0
- package/dist/index.cjs +42 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +42 -5
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/plugin.d.cts +16 -3
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts +16 -3
- package/dist/types/plugin.d.mts.map +1 -1
- package/dist/types/shell-type.cjs +6 -1
- package/dist/types/shell-type.d.cts +1 -1
- package/dist/types/shell-type.d.mts +1 -1
- package/dist/types/shell-type.mjs +6 -1
- package/dist/types/shell-type.mjs.map +1 -1
- package/package.json +82 -11
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
const require_helpers_complete_command = require('../helpers/complete-command.cjs');
|
|
2
|
+
const require_helpers_completion_directive_constants = require('../helpers/completion-directive-constants.cjs');
|
|
3
|
+
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
|
+
let __shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
|
|
5
|
+
let __stryke_path = require("@stryke/path");
|
|
6
|
+
let __alloy_js_core = require("@alloy-js/core");
|
|
7
|
+
let __alloy_js_typescript = require("@alloy-js/typescript");
|
|
8
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
9
|
+
let __powerlines_plugin_alloy_core = require("@powerlines/plugin-alloy/core");
|
|
10
|
+
let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
|
|
11
|
+
let __powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
|
|
12
|
+
let __powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
|
|
13
|
+
let __stryke_string_format_snake_case = require("@stryke/string-format/snake-case");
|
|
14
|
+
|
|
15
|
+
//#region src/components/fish-command.tsx
|
|
16
|
+
/**
|
|
17
|
+
* The Fish Completions commands' handler wrapper for the Shell Shock project.
|
|
18
|
+
*/
|
|
19
|
+
function FishCompletionsCommand() {
|
|
20
|
+
const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
21
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.TypescriptFile, {
|
|
22
|
+
get path() {
|
|
23
|
+
return (0, __stryke_path.joinPaths)(context.entryPath, "completions", "fish", "command.ts");
|
|
24
|
+
},
|
|
25
|
+
imports: {
|
|
26
|
+
"node:os": ["os"],
|
|
27
|
+
"node:fs/promises": ["readFile", "writeFile"]
|
|
28
|
+
},
|
|
29
|
+
builtinImports: { "shell-shock:console": [
|
|
30
|
+
"colors",
|
|
31
|
+
"writeLine",
|
|
32
|
+
"success",
|
|
33
|
+
"warn",
|
|
34
|
+
"stripAnsi"
|
|
35
|
+
] },
|
|
36
|
+
get children() {
|
|
37
|
+
return [
|
|
38
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Options for the Fish completions command." }),
|
|
39
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
|
|
40
|
+
"export": true,
|
|
41
|
+
name: "FishCompletionsOptions",
|
|
42
|
+
get children() {
|
|
43
|
+
return [
|
|
44
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
45
|
+
heading: "The path to write the completion script to.",
|
|
46
|
+
get children() {
|
|
47
|
+
return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `If no extension is provided, the \`.fish\` extension will be used.` }), (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
|
|
48
|
+
get type() {
|
|
49
|
+
return __powerlines_deepkit_vendor_type.ReflectionKind.string;
|
|
50
|
+
},
|
|
51
|
+
get defaultValue() {
|
|
52
|
+
return `${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}-completions.fish`;
|
|
53
|
+
}
|
|
54
|
+
})];
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
|
|
58
|
+
name: "script",
|
|
59
|
+
optional: true,
|
|
60
|
+
type: "string | true"
|
|
61
|
+
}),
|
|
62
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
63
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
64
|
+
heading: "The Fish configuration file to append the completion script to.",
|
|
65
|
+
get children() {
|
|
66
|
+
return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `The generated completion script will be appended to the specified configuration file. Possible values for the Fish configuration file include: \\n- \`~/.config/fish/config.fish\`` }), (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
|
|
67
|
+
get type() {
|
|
68
|
+
return __powerlines_deepkit_vendor_type.ReflectionKind.string;
|
|
69
|
+
},
|
|
70
|
+
defaultValue: "~/.config/fish/config.fish"
|
|
71
|
+
})];
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript.InterfaceMember, {
|
|
75
|
+
name: "config",
|
|
76
|
+
optional: true,
|
|
77
|
+
type: "string | true"
|
|
78
|
+
})
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
83
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Handler logic for the \\`completions fish\\` command." }),
|
|
84
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
85
|
+
"export": true,
|
|
86
|
+
"default": true,
|
|
87
|
+
async: true,
|
|
88
|
+
name: "handler",
|
|
89
|
+
parameters: [{
|
|
90
|
+
name: "options",
|
|
91
|
+
type: "FishCompletionsOptions"
|
|
92
|
+
}],
|
|
93
|
+
get children() {
|
|
94
|
+
return [
|
|
95
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
96
|
+
"const": true,
|
|
97
|
+
name: "completions",
|
|
98
|
+
type: "string",
|
|
99
|
+
get initializer() {
|
|
100
|
+
return __alloy_js_core.code`# fish completion for ${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} -*- shell-script -*-
|
|
101
|
+
|
|
102
|
+
function __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug
|
|
103
|
+
set -l file "$BASH_COMP_DEBUG_FILE"
|
|
104
|
+
if test -n "$file"
|
|
105
|
+
echo "$argv" >> $file
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
function __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion
|
|
110
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Starting __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion"
|
|
111
|
+
|
|
112
|
+
# Extract all args except the last one
|
|
113
|
+
set -l args (commandline -opc)
|
|
114
|
+
# Extract the last arg and escape it in case it is a space or wildcard
|
|
115
|
+
set -l lastArg (string escape -- (commandline -ct))
|
|
116
|
+
|
|
117
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "args: $args"
|
|
118
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "last arg: $lastArg"
|
|
119
|
+
|
|
120
|
+
# Build the completion request command
|
|
121
|
+
set -l requestComp "${require_helpers_complete_command.exec} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg"
|
|
122
|
+
|
|
123
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Calling $requestComp"
|
|
124
|
+
set -l results (eval $requestComp 2> /dev/null)
|
|
125
|
+
|
|
126
|
+
# Some programs may output extra empty lines after the directive.
|
|
127
|
+
# Let's ignore them or else it will break completion.
|
|
128
|
+
# Ref: https://github.com/spf13/cobra/issues/1279
|
|
129
|
+
for line in $results[-1..1]
|
|
130
|
+
if test (string trim -- $line) = ""
|
|
131
|
+
# Found an empty line, remove it
|
|
132
|
+
set results $results[1..-2]
|
|
133
|
+
else
|
|
134
|
+
# Found non-empty line, we have our proper output
|
|
135
|
+
break
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
set -l comps $results[1..-2]
|
|
140
|
+
set -l directiveLine $results[-1]
|
|
141
|
+
|
|
142
|
+
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
|
143
|
+
# completions must be prefixed with the flag
|
|
144
|
+
set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
|
|
145
|
+
|
|
146
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Comps: $comps"
|
|
147
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "DirectiveLine: $directiveLine"
|
|
148
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "flagPrefix: $flagPrefix"
|
|
149
|
+
|
|
150
|
+
for comp in $comps
|
|
151
|
+
printf "%s%s\\n" "$flagPrefix" "$comp"
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
printf "%s\\n" "$directiveLine"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# This function limits calls to __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion, by caching the result
|
|
158
|
+
function __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once
|
|
159
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Starting __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once"
|
|
160
|
+
|
|
161
|
+
if test -n "$__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
162
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Seems like a valid result already exists, skipping __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion"
|
|
163
|
+
return 0
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
set --global __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result (__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion)
|
|
167
|
+
if test -z "$__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
168
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "No completions, probably due to a failure"
|
|
169
|
+
return 1
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Performed completions and set __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
173
|
+
return 0
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# This function is used to clear the cached result after completions are run
|
|
177
|
+
function __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_clear_perform_completion_once_result
|
|
178
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug ""
|
|
179
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "========= clearing previously set __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result variable =========="
|
|
180
|
+
set --erase __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result
|
|
181
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Successfully erased the variable __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
function __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_requires_order_preservation
|
|
185
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug ""
|
|
186
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "========= checking if order preservation is required =========="
|
|
187
|
+
|
|
188
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once
|
|
189
|
+
if test -z "$__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
190
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Error determining if order preservation is required"
|
|
191
|
+
return 1
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
set -l directive (string sub --start 2 $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result[-1])
|
|
195
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Directive is: $directive"
|
|
196
|
+
|
|
197
|
+
set -l shellCompDirectiveKeepOrder ${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveKeepOrder}
|
|
198
|
+
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
|
|
199
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Keeporder is: $keeporder"
|
|
200
|
+
|
|
201
|
+
if test $keeporder -ne 0
|
|
202
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "This does require order preservation"
|
|
203
|
+
return 0
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "This doesn't require order preservation"
|
|
207
|
+
return 1
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# This function does two things:
|
|
211
|
+
# - Obtain the completions and store them in the global __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results
|
|
212
|
+
# - Return false if file completion should be performed
|
|
213
|
+
function __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_prepare_completions
|
|
214
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug ""
|
|
215
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "========= starting completion logic =========="
|
|
216
|
+
|
|
217
|
+
# Start fresh
|
|
218
|
+
set --erase __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results
|
|
219
|
+
|
|
220
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once
|
|
221
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Completion results: $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
222
|
+
|
|
223
|
+
if test -z "$__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result"
|
|
224
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "No completion, probably due to a failure"
|
|
225
|
+
# Might as well do file completion, in case it helps
|
|
226
|
+
return 1
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
set -l directive (string sub --start 2 $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result[-1])
|
|
230
|
+
set --global __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_perform_completion_once_result[1..-2]
|
|
231
|
+
|
|
232
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Completions are: $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results"
|
|
233
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Directive is: $directive"
|
|
234
|
+
|
|
235
|
+
set -l shellCompDirectiveError ${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveError}
|
|
236
|
+
set -l shellCompDirectiveNoSpace ${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoSpace}
|
|
237
|
+
set -l shellCompDirectiveNoFileComp ${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoFileComp}
|
|
238
|
+
set -l shellCompDirectiveFilterFileExt ${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveFilterFileExt}
|
|
239
|
+
set -l shellCompDirectiveFilterDirs ${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveFilterDirs}
|
|
240
|
+
if test -z "$directive"
|
|
241
|
+
set directive 0
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
|
245
|
+
if test $compErr -eq 1
|
|
246
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Received error directive: aborting."
|
|
247
|
+
# Might as well do file completion, in case it helps
|
|
248
|
+
return 1
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
|
252
|
+
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
|
253
|
+
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
|
254
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "File extension filtering or directory filtering not supported"
|
|
255
|
+
# Do full file completion instead
|
|
256
|
+
return 1
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
|
260
|
+
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
|
261
|
+
|
|
262
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "nospace: $nospace, nofiles: $nofiles"
|
|
263
|
+
|
|
264
|
+
# If we want to prevent a space, or if file completion is NOT disabled,
|
|
265
|
+
# we need to count the number of valid completions.
|
|
266
|
+
# To do so, we will filter on prefix as the completions we have received
|
|
267
|
+
# may not already be filtered so as to allow fish to match on different
|
|
268
|
+
# criteria than the prefix.
|
|
269
|
+
if test $nospace -ne 0; or test $nofiles -eq 0
|
|
270
|
+
set -l prefix (commandline -t | string escape --style=regex)
|
|
271
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "prefix: $prefix"
|
|
272
|
+
|
|
273
|
+
set -l completions (string match -r -- "^$prefix.*" $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results)
|
|
274
|
+
set --global __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results $completions
|
|
275
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Filtered completions are: $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results"
|
|
276
|
+
|
|
277
|
+
# Important not to quote the variable for count to work
|
|
278
|
+
set -l numComps (count $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results)
|
|
279
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "numComps: $numComps"
|
|
280
|
+
|
|
281
|
+
if test $numComps -eq 1; and test $nospace -ne 0
|
|
282
|
+
# We must first split on \\t to get rid of the descriptions to be
|
|
283
|
+
# able to check what the actual completion will be.
|
|
284
|
+
# We don't need descriptions anyway since there is only a single
|
|
285
|
+
# real completion which the shell will expand immediately.
|
|
286
|
+
set -l split (string split --max 1 "\\t" $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results[1])
|
|
287
|
+
|
|
288
|
+
# Fish won't add a space if the completion ends with any
|
|
289
|
+
# of the following characters: @=/:.,
|
|
290
|
+
set -l lastChar (string sub -s -1 -- $split)
|
|
291
|
+
if not string match -r -q "[@=/:.,]" -- "$lastChar"
|
|
292
|
+
# In other cases, to support the "nospace" directive we trick the shell
|
|
293
|
+
# by outputting an extra, longer completion.
|
|
294
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Adding second completion to perform nospace directive"
|
|
295
|
+
set --global __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results $split[1] $split[1].
|
|
296
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Completions are now: $__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results"
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
if test $numComps -eq 0; and test $nofiles -eq 0
|
|
301
|
+
# To be consistent with bash and zsh, we only trigger file
|
|
302
|
+
# completion when there are no other completions
|
|
303
|
+
__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Requesting file completion"
|
|
304
|
+
return 1
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
return 0
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
|
312
|
+
# so we can properly delete any completions provided by another script.
|
|
313
|
+
# Only do this if the program can be found, or else fish may print some errors; besides,
|
|
314
|
+
# the existing completions will only be loaded if the program can be found.
|
|
315
|
+
if type -q "${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}"
|
|
316
|
+
# The space after the program name is essential to trigger completion for the program
|
|
317
|
+
# and not completion of the program name itself.
|
|
318
|
+
# Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
|
319
|
+
complete --do-complete "${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} " > /dev/null 2>&1
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# Remove any pre-existing completions for the program since we will be handling all of them.
|
|
323
|
+
complete -c ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} -e
|
|
324
|
+
# This will get called after the two calls below and clear the cached result
|
|
325
|
+
complete -c ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} -n '__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_clear_perform_completion_once_result'
|
|
326
|
+
# The call to __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_prepare_completions will setup __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results
|
|
327
|
+
# which provides the program's completion choices.
|
|
328
|
+
# If this doesn't require order preservation, we don't use the -k flag
|
|
329
|
+
complete -c ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} -n 'not __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_requires_order_preservation && __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_prepare_completions' -f -a '$__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results'
|
|
330
|
+
# Otherwise we use the -k flag
|
|
331
|
+
complete -k -c ${(0, __shell_shock_core_plugin_utils.getAppBin)(context)} -n '__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_requires_order_preservation && __${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_prepare_completions' -f -a '$__${(0, __stryke_string_format_snake_case.snakeCase)((0, __shell_shock_core_plugin_utils.getAppBin)(context))}_comp_results'
|
|
332
|
+
\`);`;
|
|
333
|
+
}
|
|
334
|
+
}),
|
|
335
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
336
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
|
|
337
|
+
condition: __alloy_js_core.code`options.config`,
|
|
338
|
+
get children() {
|
|
339
|
+
return [
|
|
340
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
341
|
+
"let": true,
|
|
342
|
+
name: "configFilePath",
|
|
343
|
+
type: "string",
|
|
344
|
+
initializer: __alloy_js_core.code`options.config === true ? "~/.config/fish/config.fish" : options.config`
|
|
345
|
+
}),
|
|
346
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
347
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
|
|
348
|
+
condition: __alloy_js_core.code`configFilePath.startsWith("~")`,
|
|
349
|
+
children: __alloy_js_core.code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
|
|
350
|
+
}),
|
|
351
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
352
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
353
|
+
"let": true,
|
|
354
|
+
name: "configFileContent",
|
|
355
|
+
type: "string",
|
|
356
|
+
initializer: __alloy_js_core.code`"";`
|
|
357
|
+
}),
|
|
358
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
359
|
+
(0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`try {
|
|
360
|
+
configFileContent = await readFile(configFilePath, "utf8");
|
|
361
|
+
} catch (error) {
|
|
362
|
+
if (error.code === "ENOENT") {
|
|
363
|
+
// If the file doesn't exist, we can create it later when writing the completion script.
|
|
364
|
+
warn(\`Configuration file \${colors.bold(configFilePath)} does not exist. It will be created when the completion script is written.\`);
|
|
365
|
+
} else {
|
|
366
|
+
return { error };
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
await writeFile(configFilePath, \`\${configFileContent}\\n\\n\${stripAnsi(completions)}\`);
|
|
371
|
+
|
|
372
|
+
success(\`${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} Fish completion script has been generated and appended to \${colors.bold(configFilePath)}. Please restart your terminal or run \`source \${configFilePath}\` to apply the changes.\`); `)
|
|
373
|
+
];
|
|
374
|
+
}
|
|
375
|
+
}),
|
|
376
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
377
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
|
|
378
|
+
condition: __alloy_js_core.code`options.script`,
|
|
379
|
+
get children() {
|
|
380
|
+
return __alloy_js_core.code`const outputPath = options.script === true ? "${(0, __shell_shock_core_plugin_utils.getAppBin)(context)}-completions.fish" : options.script;
|
|
381
|
+
await writeFile(outputPath, stripAnsi(completions));
|
|
382
|
+
|
|
383
|
+
success(\`${(0, __shell_shock_core_plugin_utils.getAppTitle)(context)} Fish completion script has been generated at \${colors.bold(outputPath)}.\`);`;
|
|
384
|
+
}
|
|
385
|
+
}),
|
|
386
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core.Spacing, {}),
|
|
387
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
|
|
388
|
+
condition: __alloy_js_core.code`!options.config && !options.script`,
|
|
389
|
+
children: __alloy_js_core.code`writeLine(" ------------------------------------------------- ");
|
|
390
|
+
writeLine(completions);
|
|
391
|
+
writeLine(" ------------------------------------------------- ");`
|
|
392
|
+
})
|
|
393
|
+
];
|
|
394
|
+
}
|
|
395
|
+
})
|
|
396
|
+
];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
//#endregion
|
|
402
|
+
exports.FishCompletionsCommand = FishCompletionsCommand;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _alloy_js_core0 from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/components/fish-command.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Fish Completions commands' handler wrapper for the Shell Shock project.
|
|
6
|
+
*/
|
|
7
|
+
declare function FishCompletionsCommand(): _alloy_js_core0.Children;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { FishCompletionsCommand };
|
|
10
|
+
//# sourceMappingURL=fish-command.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fish-command.d.cts","names":[],"sources":["../../src/components/fish-command.tsx"],"sourcesContent":[],"mappings":";;;;;;AA+CgB,iBAAA,sBAAA,CAAA,CAAsB,EAAA,eAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _alloy_js_core1 from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/components/fish-command.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Fish Completions commands' handler wrapper for the Shell Shock project.
|
|
6
|
+
*/
|
|
7
|
+
declare function FishCompletionsCommand(): _alloy_js_core1.Children;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { FishCompletionsCommand };
|
|
10
|
+
//# sourceMappingURL=fish-command.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fish-command.d.mts","names":[],"sources":["../../src/components/fish-command.tsx"],"sourcesContent":[],"mappings":";;;;;;AA+CgB,iBAAA,sBAAA,CAAA,CAAsB,EAAA,eAAA,CAAA,QAAA"}
|