@shell-shock/plugin-completions 0.2.2 → 0.2.6
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/_virtual/_rolldown/runtime.mjs +3 -0
- package/dist/components/bash-command.cjs +59 -58
- 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.map +1 -1
- package/dist/components/fish-command.cjs +124 -123
- package/dist/components/fish-command.d.cts.map +1 -1
- package/dist/components/fish-command.d.mts +2 -2
- package/dist/components/fish-command.d.mts.map +1 -1
- package/dist/components/fish-command.mjs.map +1 -1
- package/dist/components/index.cjs +1 -0
- package/dist/components/powershell-command.cjs +82 -81
- package/dist/components/powershell-command.d.cts +2 -2
- package/dist/components/powershell-command.d.cts.map +1 -1
- package/dist/components/powershell-command.d.mts.map +1 -1
- package/dist/components/powershell-command.mjs +1 -1
- package/dist/components/powershell-command.mjs.map +1 -1
- package/dist/components/zsh-command.cjs +91 -90
- 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.map +1 -1
- package/dist/helpers/complete-command.cjs +1 -0
- package/dist/helpers/complete-command.d.cts.map +1 -1
- package/dist/helpers/complete-command.d.mts.map +1 -1
- package/dist/helpers/complete-command.mjs.map +1 -1
- package/dist/helpers/completion-directive-constants.cjs +1 -0
- package/dist/helpers/completion-directive-constants.d.cts.map +1 -1
- package/dist/helpers/completion-directive-constants.d.mts.map +1 -1
- package/dist/helpers/completion-directive-constants.mjs.map +1 -1
- package/dist/helpers/index.cjs +1 -0
- package/dist/index.cjs +22 -23
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.cjs +1 -0
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts.map +1 -1
- package/dist/types/shell-type.cjs +1 -0
- package/dist/types/shell-type.d.cts.map +1 -1
- package/dist/types/shell-type.d.mts.map +1 -1
- package/dist/types/shell-type.mjs.map +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fish-command.mjs","names":["code","FunctionDeclaration","IfStatement","InterfaceDeclaration","VarDeclaration","ReflectionKind","Spacing","usePowerlines","InterfaceMember","TypescriptFile","TSDoc","TSDocDefaultValue","TSDocRemarks","getAppBin","getAppTitle","joinPaths","snakeCase","exec","CompletionDirective","FishCompletionsCommand","context","_$createComponent","path","entryPath","imports","builtinImports","children","heading","name","type","string","defaultValue","optional","async","parameters","initializer","CompletionDirectiveKeepOrder","CompletionDirectiveError","CompletionDirectiveNoSpace","CompletionDirectiveNoFileComp","CompletionDirectiveFilterFileExt","CompletionDirectiveFilterDirs","condition","_$memo"],"sources":["../../src/components/fish-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 { exec } from \"../helpers/complete-command\";\nimport { CompletionDirective } from \"../helpers/completion-directive-constants\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Fish Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function FishCompletionsCommand() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n return (\n <TypescriptFile\n path={joinPaths(context.entryPath, \"completions\", \"fish\", \"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 Fish completions command.\" />\n <InterfaceDeclaration export name=\"FishCompletionsOptions\">\n <TSDoc heading=\"The path to write the completion script to.\">\n <TSDocRemarks>{`If no extension is provided, the \\`.fish\\` extension will be used.`}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue={`${getAppBin(context)}-completions.fish`}\n />\n </TSDoc>\n <InterfaceMember name=\"script\" optional type=\"string | true\" />\n <Spacing />\n <TSDoc heading=\"The Fish 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 Fish configuration file include: \\\\n- \\`~/.config/fish/config.fish\\``}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue=\"~/.config/fish/config.fish\"\n />\n </TSDoc>\n <InterfaceMember name=\"config\" optional type=\"string | true\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Handler logic for the \\`completions fish\\` command.\"></TSDoc>\n <FunctionDeclaration\n export\n default\n async\n name=\"handler\"\n parameters={[{ name: \"options\", type: \"FishCompletionsOptions\" }]}>\n <VarDeclaration\n const\n name=\"completions\"\n type=\"string\"\n initializer={code`# fish completion for ${getAppTitle(\n context\n )} -*- shell-script -*-\n\nfunction __${snakeCase(getAppBin(context))}_debug\n set -l file \"$BASH_COMP_DEBUG_FILE\"\n if test -n \"$file\"\n echo \"$argv\" >> $file\n end\nend\n\nfunction __${snakeCase(getAppBin(context))}_perform_completion\n __${snakeCase(getAppBin(context))}_debug \"Starting __${snakeCase(getAppBin(context))}_perform_completion\"\n\n # Extract all args except the last one\n set -l args (commandline -opc)\n # Extract the last arg and escape it in case it is a space or wildcard\n set -l lastArg (string escape -- (commandline -ct))\n\n __${snakeCase(getAppBin(context))}_debug \"args: $args\"\n __${snakeCase(getAppBin(context))}_debug \"last arg: $lastArg\"\n\n # Build the completion request command\n set -l requestComp \"${exec} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg\"\n\n __${snakeCase(getAppBin(context))}_debug \"Calling $requestComp\"\n set -l results (eval $requestComp 2> /dev/null)\n\n # Some programs may output extra empty lines after the directive.\n # Let's ignore them or else it will break completion.\n # Ref: https://github.com/spf13/cobra/issues/1279\n for line in $results[-1..1]\n if test (string trim -- $line) = \"\"\n # Found an empty line, remove it\n set results $results[1..-2]\n else\n # Found non-empty line, we have our proper output\n break\n end\n end\n\n set -l comps $results[1..-2]\n set -l directiveLine $results[-1]\n\n # For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)\n # completions must be prefixed with the flag\n set -l flagPrefix (string match -r -- '-.*=' \"$lastArg\")\n\n __${snakeCase(getAppBin(context))}_debug \"Comps: $comps\"\n __${snakeCase(getAppBin(context))}_debug \"DirectiveLine: $directiveLine\"\n __${snakeCase(getAppBin(context))}_debug \"flagPrefix: $flagPrefix\"\n\n for comp in $comps\n printf \"%s%s\\\\n\" \"$flagPrefix\" \"$comp\"\n end\n\n printf \"%s\\\\n\" \"$directiveLine\"\nend\n\n# This function limits calls to __${snakeCase(getAppBin(context))}_perform_completion, by caching the result\nfunction __${snakeCase(getAppBin(context))}_perform_completion_once\n __${snakeCase(getAppBin(context))}_debug \"Starting __${snakeCase(\n getAppBin(context)\n )}_perform_completion_once\"\n\n if test -n \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"Seems like a valid result already exists, skipping __${snakeCase(getAppBin(context))}_perform_completion\"\n return 0\n end\n\n set --global __${snakeCase(getAppBin(context))}_perform_completion_once_result (__${snakeCase(getAppBin(context))}_perform_completion)\n if test -z \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"No completions, probably due to a failure\"\n return 1\n end\n\n __${snakeCase(getAppBin(context))}_debug \"Performed completions and set __${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n return 0\nend\n\n# This function is used to clear the cached result after completions are run\nfunction __${snakeCase(getAppBin(context))}_clear_perform_completion_once_result\n __${snakeCase(getAppBin(context))}_debug \"\"\n __${snakeCase(getAppBin(context))}_debug \"========= clearing previously set __${snakeCase(getAppBin(context))}_perform_completion_once_result variable ==========\"\n set --erase __${snakeCase(getAppBin(context))}_perform_completion_once_result\n __${snakeCase(getAppBin(context))}_debug \"Successfully erased the variable __${snakeCase(getAppBin(context))}_perform_completion_once_result\"\nend\n\nfunction __${snakeCase(getAppBin(context))}_requires_order_preservation\n __${snakeCase(getAppBin(context))}_debug \"\"\n __${snakeCase(getAppBin(context))}_debug \"========= checking if order preservation is required ==========\"\n\n __${snakeCase(getAppBin(context))}_perform_completion_once\n if test -z \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"Error determining if order preservation is required\"\n return 1\n end\n\n set -l directive (string sub --start 2 $__${snakeCase(\n getAppBin(context)\n )}_perform_completion_once_result[-1])\n __${snakeCase(getAppBin(context))}_debug \"Directive is: $directive\"\n\n set -l shellCompDirectiveKeepOrder ${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)\n __${snakeCase(getAppBin(context))}_debug \"Keeporder is: $keeporder\"\n\n if test $keeporder -ne 0\n __${snakeCase(getAppBin(context))}_debug \"This does require order preservation\"\n return 0\n end\n\n __${snakeCase(getAppBin(context))}_debug \"This doesn't require order preservation\"\n return 1\nend\n\n# This function does two things:\n# - Obtain the completions and store them in the global __${snakeCase(getAppBin(context))}_comp_results\n# - Return false if file completion should be performed\nfunction __${snakeCase(getAppBin(context))}_prepare_completions\n __${snakeCase(getAppBin(context))}_debug \"\"\n __${snakeCase(getAppBin(context))}_debug \"========= starting completion logic ==========\"\n\n # Start fresh\n set --erase __${snakeCase(getAppBin(context))}_comp_results\n\n __${snakeCase(getAppBin(context))}_perform_completion_once\n __${snakeCase(getAppBin(context))}_debug \"Completion results: $__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n\n if test -z \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"No completion, probably due to a failure\"\n # Might as well do file completion, in case it helps\n return 1\n end\n\n set -l directive (string sub --start 2 $__${snakeCase(getAppBin(context))}_perform_completion_once_result[-1])\n set --global __${snakeCase(getAppBin(context))}_comp_results $__${snakeCase(getAppBin(context))}_perform_completion_once_result[1..-2]\n\n __${snakeCase(getAppBin(context))}_debug \"Completions are: $__${snakeCase(getAppBin(context))}_comp_results\"\n __${snakeCase(getAppBin(context))}_debug \"Directive is: $directive\"\n\n set -l shellCompDirectiveError ${\n CompletionDirective.CompletionDirectiveError\n }\n set -l shellCompDirectiveNoSpace ${\n CompletionDirective.CompletionDirectiveNoSpace\n }\n set -l shellCompDirectiveNoFileComp ${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\n set -l shellCompDirectiveFilterFileExt ${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\n set -l shellCompDirectiveFilterDirs ${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\n if test -z \"$directive\"\n set directive 0\n end\n\n set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)\n if test $compErr -eq 1\n __${snakeCase(getAppBin(context))}_debug \"Received error directive: aborting.\"\n # Might as well do file completion, in case it helps\n return 1\n end\n\n set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)\n set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)\n if test $filefilter -eq 1; or test $dirfilter -eq 1\n __${snakeCase(getAppBin(context))}_debug \"File extension filtering or directory filtering not supported\"\n # Do full file completion instead\n return 1\n end\n\n set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)\n set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)\n\n __${snakeCase(getAppBin(context))}_debug \"nospace: $nospace, nofiles: $nofiles\"\n\n # If we want to prevent a space, or if file completion is NOT disabled,\n # we need to count the number of valid completions.\n # To do so, we will filter on prefix as the completions we have received\n # may not already be filtered so as to allow fish to match on different\n # criteria than the prefix.\n if test $nospace -ne 0; or test $nofiles -eq 0\n set -l prefix (commandline -t | string escape --style=regex)\n __${snakeCase(getAppBin(context))}_debug \"prefix: $prefix\"\n\n set -l completions (string match -r -- \"^$prefix.*\" $__${snakeCase(getAppBin(context))}_comp_results)\n set --global __${snakeCase(getAppBin(context))}_comp_results $completions\n __${snakeCase(getAppBin(context))}_debug \"Filtered completions are: $__${snakeCase(getAppBin(context))}_comp_results\"\n\n # Important not to quote the variable for count to work\n set -l numComps (count $__${snakeCase(getAppBin(context))}_comp_results)\n __${snakeCase(getAppBin(context))}_debug \"numComps: $numComps\"\n\n if test $numComps -eq 1; and test $nospace -ne 0\n # We must first split on \\\\t to get rid of the descriptions to be\n # able to check what the actual completion will be.\n # We don't need descriptions anyway since there is only a single\n # real completion which the shell will expand immediately.\n set -l split (string split --max 1 \"\\\\t\" $__${snakeCase(getAppBin(context))}_comp_results[1])\n\n # Fish won't add a space if the completion ends with any\n # of the following characters: @=/:.,\n set -l lastChar (string sub -s -1 -- $split)\n if not string match -r -q \"[@=/:.,]\" -- \"$lastChar\"\n # In other cases, to support the \"nospace\" directive we trick the shell\n # by outputting an extra, longer completion.\n __${snakeCase(getAppBin(context))}_debug \"Adding second completion to perform nospace directive\"\n set --global __${snakeCase(getAppBin(context))}_comp_results $split[1] $split[1].\n __${snakeCase(getAppBin(context))}_debug \"Completions are now: $__${snakeCase(getAppBin(context))}_comp_results\"\n end\n end\n\n if test $numComps -eq 0; and test $nofiles -eq 0\n # To be consistent with bash and zsh, we only trigger file\n # completion when there are no other completions\n __${snakeCase(getAppBin(context))}_debug \"Requesting file completion\"\n return 1\n end\n end\n\n return 0\nend\n\n# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves\n# so we can properly delete any completions provided by another script.\n# Only do this if the program can be found, or else fish may print some errors; besides,\n# the existing completions will only be loaded if the program can be found.\nif type -q \"${getAppBin(context)}\"\n # The space after the program name is essential to trigger completion for the program\n # and not completion of the program name itself.\n # Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.\n complete --do-complete \"${getAppBin(context)} \" > /dev/null 2>&1\nend\n\n# Remove any pre-existing completions for the program since we will be handling all of them.\ncomplete -c ${getAppBin(context)} -e\n# This will get called after the two calls below and clear the cached result\ncomplete -c ${getAppBin(context)} -n '__${snakeCase(getAppBin(context))}_clear_perform_completion_once_result'\n# The call to __${snakeCase(getAppBin(context))}_prepare_completions will setup __${snakeCase(getAppBin(context))}_comp_results\n# which provides the program's completion choices.\n# If this doesn't require order preservation, we don't use the -k flag\ncomplete -c ${getAppBin(\n context\n )} -n 'not __${snakeCase(getAppBin(context))}_requires_order_preservation && __${snakeCase(getAppBin(context))}_prepare_completions' -f -a '$__${snakeCase(getAppBin(context))}_comp_results'\n# Otherwise we use the -k flag\ncomplete -k -c ${getAppBin(context)} -n '__${snakeCase(\n getAppBin(context)\n )}_requires_order_preservation && __${snakeCase(\n getAppBin(context)\n )}_prepare_completions' -f -a '$__${snakeCase(\n getAppBin(context)\n )}_comp_results'\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 ? \"~/.config/fish/config.fish\" : 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)} Fish 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.fish\" : options.script;\n await writeFile(outputPath, stripAnsi(completions));\n\n success(\\`${getAppTitle(context)} Fish 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":";;;;;;;;;;;;;;;;;;AA+CA,SAAgBmB,yBAAyB;CACvC,MAAMC,UAAUb,eAAy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QAAQ,CAAA,0LAA0L;UAAA;;QAAA,CAAA;OAAAC,gBAE3Nf,SAAO,EAAA,CAAA;OAAAe,gBACPnB,aAAW;QAACwC,WAAW1C,IAAI;QAAgB,IAAA0B,WAAA;AAAA,gBACzC1B,IAAI,iDAAiDa,UAAUO,QAAQ,CAAA;;;sBAG5DN,YAAYM,QAAQ,CAAA;;QAAgF,CAAA;OAAAC,gBAEjHf,SAAO,EAAA,CAAA;OAAAe,gBACPnB,aAAW;QAACwC,WAAW1C,IAAI;QAAoC0B,UAC7D1B,IAAI;;;QAE6D,CAAA;OAAA;;KAAA,CAAA;IAAA;;EAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"fish-command.mjs","names":[],"sources":["../../src/components/fish-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 { exec } from \"../helpers/complete-command\";\nimport { CompletionDirective } from \"../helpers/completion-directive-constants\";\nimport type { CompletionsPluginContext } from \"../types/plugin\";\n\n/**\n * The Fish Completions commands' handler wrapper for the Shell Shock project.\n */\nexport function FishCompletionsCommand() {\n const context = usePowerlines<CompletionsPluginContext>();\n\n return (\n <TypescriptFile\n path={joinPaths(context.entryPath, \"completions\", \"fish\", \"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 Fish completions command.\" />\n <InterfaceDeclaration export name=\"FishCompletionsOptions\">\n <TSDoc heading=\"The path to write the completion script to.\">\n <TSDocRemarks>{`If no extension is provided, the \\`.fish\\` extension will be used.`}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue={`${getAppBin(context)}-completions.fish`}\n />\n </TSDoc>\n <InterfaceMember name=\"script\" optional type=\"string | true\" />\n <Spacing />\n <TSDoc heading=\"The Fish 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 Fish configuration file include: \\\\n- \\`~/.config/fish/config.fish\\``}</TSDocRemarks>\n <TSDocDefaultValue\n type={ReflectionKind.string}\n defaultValue=\"~/.config/fish/config.fish\"\n />\n </TSDoc>\n <InterfaceMember name=\"config\" optional type=\"string | true\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Handler logic for the \\`completions fish\\` command.\"></TSDoc>\n <FunctionDeclaration\n export\n default\n async\n name=\"handler\"\n parameters={[{ name: \"options\", type: \"FishCompletionsOptions\" }]}>\n <VarDeclaration\n const\n name=\"completions\"\n type=\"string\"\n initializer={code`# fish completion for ${getAppTitle(\n context\n )} -*- shell-script -*-\n\nfunction __${snakeCase(getAppBin(context))}_debug\n set -l file \"$BASH_COMP_DEBUG_FILE\"\n if test -n \"$file\"\n echo \"$argv\" >> $file\n end\nend\n\nfunction __${snakeCase(getAppBin(context))}_perform_completion\n __${snakeCase(getAppBin(context))}_debug \"Starting __${snakeCase(getAppBin(context))}_perform_completion\"\n\n # Extract all args except the last one\n set -l args (commandline -opc)\n # Extract the last arg and escape it in case it is a space or wildcard\n set -l lastArg (string escape -- (commandline -ct))\n\n __${snakeCase(getAppBin(context))}_debug \"args: $args\"\n __${snakeCase(getAppBin(context))}_debug \"last arg: $lastArg\"\n\n # Build the completion request command\n set -l requestComp \"${exec} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg\"\n\n __${snakeCase(getAppBin(context))}_debug \"Calling $requestComp\"\n set -l results (eval $requestComp 2> /dev/null)\n\n # Some programs may output extra empty lines after the directive.\n # Let's ignore them or else it will break completion.\n # Ref: https://github.com/spf13/cobra/issues/1279\n for line in $results[-1..1]\n if test (string trim -- $line) = \"\"\n # Found an empty line, remove it\n set results $results[1..-2]\n else\n # Found non-empty line, we have our proper output\n break\n end\n end\n\n set -l comps $results[1..-2]\n set -l directiveLine $results[-1]\n\n # For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)\n # completions must be prefixed with the flag\n set -l flagPrefix (string match -r -- '-.*=' \"$lastArg\")\n\n __${snakeCase(getAppBin(context))}_debug \"Comps: $comps\"\n __${snakeCase(getAppBin(context))}_debug \"DirectiveLine: $directiveLine\"\n __${snakeCase(getAppBin(context))}_debug \"flagPrefix: $flagPrefix\"\n\n for comp in $comps\n printf \"%s%s\\\\n\" \"$flagPrefix\" \"$comp\"\n end\n\n printf \"%s\\\\n\" \"$directiveLine\"\nend\n\n# This function limits calls to __${snakeCase(getAppBin(context))}_perform_completion, by caching the result\nfunction __${snakeCase(getAppBin(context))}_perform_completion_once\n __${snakeCase(getAppBin(context))}_debug \"Starting __${snakeCase(\n getAppBin(context)\n )}_perform_completion_once\"\n\n if test -n \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"Seems like a valid result already exists, skipping __${snakeCase(getAppBin(context))}_perform_completion\"\n return 0\n end\n\n set --global __${snakeCase(getAppBin(context))}_perform_completion_once_result (__${snakeCase(getAppBin(context))}_perform_completion)\n if test -z \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"No completions, probably due to a failure\"\n return 1\n end\n\n __${snakeCase(getAppBin(context))}_debug \"Performed completions and set __${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n return 0\nend\n\n# This function is used to clear the cached result after completions are run\nfunction __${snakeCase(getAppBin(context))}_clear_perform_completion_once_result\n __${snakeCase(getAppBin(context))}_debug \"\"\n __${snakeCase(getAppBin(context))}_debug \"========= clearing previously set __${snakeCase(getAppBin(context))}_perform_completion_once_result variable ==========\"\n set --erase __${snakeCase(getAppBin(context))}_perform_completion_once_result\n __${snakeCase(getAppBin(context))}_debug \"Successfully erased the variable __${snakeCase(getAppBin(context))}_perform_completion_once_result\"\nend\n\nfunction __${snakeCase(getAppBin(context))}_requires_order_preservation\n __${snakeCase(getAppBin(context))}_debug \"\"\n __${snakeCase(getAppBin(context))}_debug \"========= checking if order preservation is required ==========\"\n\n __${snakeCase(getAppBin(context))}_perform_completion_once\n if test -z \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"Error determining if order preservation is required\"\n return 1\n end\n\n set -l directive (string sub --start 2 $__${snakeCase(\n getAppBin(context)\n )}_perform_completion_once_result[-1])\n __${snakeCase(getAppBin(context))}_debug \"Directive is: $directive\"\n\n set -l shellCompDirectiveKeepOrder ${\n CompletionDirective.CompletionDirectiveKeepOrder\n }\n set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)\n __${snakeCase(getAppBin(context))}_debug \"Keeporder is: $keeporder\"\n\n if test $keeporder -ne 0\n __${snakeCase(getAppBin(context))}_debug \"This does require order preservation\"\n return 0\n end\n\n __${snakeCase(getAppBin(context))}_debug \"This doesn't require order preservation\"\n return 1\nend\n\n# This function does two things:\n# - Obtain the completions and store them in the global __${snakeCase(getAppBin(context))}_comp_results\n# - Return false if file completion should be performed\nfunction __${snakeCase(getAppBin(context))}_prepare_completions\n __${snakeCase(getAppBin(context))}_debug \"\"\n __${snakeCase(getAppBin(context))}_debug \"========= starting completion logic ==========\"\n\n # Start fresh\n set --erase __${snakeCase(getAppBin(context))}_comp_results\n\n __${snakeCase(getAppBin(context))}_perform_completion_once\n __${snakeCase(getAppBin(context))}_debug \"Completion results: $__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n\n if test -z \"$__${snakeCase(getAppBin(context))}_perform_completion_once_result\"\n __${snakeCase(getAppBin(context))}_debug \"No completion, probably due to a failure\"\n # Might as well do file completion, in case it helps\n return 1\n end\n\n set -l directive (string sub --start 2 $__${snakeCase(getAppBin(context))}_perform_completion_once_result[-1])\n set --global __${snakeCase(getAppBin(context))}_comp_results $__${snakeCase(getAppBin(context))}_perform_completion_once_result[1..-2]\n\n __${snakeCase(getAppBin(context))}_debug \"Completions are: $__${snakeCase(getAppBin(context))}_comp_results\"\n __${snakeCase(getAppBin(context))}_debug \"Directive is: $directive\"\n\n set -l shellCompDirectiveError ${\n CompletionDirective.CompletionDirectiveError\n }\n set -l shellCompDirectiveNoSpace ${\n CompletionDirective.CompletionDirectiveNoSpace\n }\n set -l shellCompDirectiveNoFileComp ${\n CompletionDirective.CompletionDirectiveNoFileComp\n }\n set -l shellCompDirectiveFilterFileExt ${\n CompletionDirective.CompletionDirectiveFilterFileExt\n }\n set -l shellCompDirectiveFilterDirs ${\n CompletionDirective.CompletionDirectiveFilterDirs\n }\n if test -z \"$directive\"\n set directive 0\n end\n\n set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)\n if test $compErr -eq 1\n __${snakeCase(getAppBin(context))}_debug \"Received error directive: aborting.\"\n # Might as well do file completion, in case it helps\n return 1\n end\n\n set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)\n set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)\n if test $filefilter -eq 1; or test $dirfilter -eq 1\n __${snakeCase(getAppBin(context))}_debug \"File extension filtering or directory filtering not supported\"\n # Do full file completion instead\n return 1\n end\n\n set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)\n set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)\n\n __${snakeCase(getAppBin(context))}_debug \"nospace: $nospace, nofiles: $nofiles\"\n\n # If we want to prevent a space, or if file completion is NOT disabled,\n # we need to count the number of valid completions.\n # To do so, we will filter on prefix as the completions we have received\n # may not already be filtered so as to allow fish to match on different\n # criteria than the prefix.\n if test $nospace -ne 0; or test $nofiles -eq 0\n set -l prefix (commandline -t | string escape --style=regex)\n __${snakeCase(getAppBin(context))}_debug \"prefix: $prefix\"\n\n set -l completions (string match -r -- \"^$prefix.*\" $__${snakeCase(getAppBin(context))}_comp_results)\n set --global __${snakeCase(getAppBin(context))}_comp_results $completions\n __${snakeCase(getAppBin(context))}_debug \"Filtered completions are: $__${snakeCase(getAppBin(context))}_comp_results\"\n\n # Important not to quote the variable for count to work\n set -l numComps (count $__${snakeCase(getAppBin(context))}_comp_results)\n __${snakeCase(getAppBin(context))}_debug \"numComps: $numComps\"\n\n if test $numComps -eq 1; and test $nospace -ne 0\n # We must first split on \\\\t to get rid of the descriptions to be\n # able to check what the actual completion will be.\n # We don't need descriptions anyway since there is only a single\n # real completion which the shell will expand immediately.\n set -l split (string split --max 1 \"\\\\t\" $__${snakeCase(getAppBin(context))}_comp_results[1])\n\n # Fish won't add a space if the completion ends with any\n # of the following characters: @=/:.,\n set -l lastChar (string sub -s -1 -- $split)\n if not string match -r -q \"[@=/:.,]\" -- \"$lastChar\"\n # In other cases, to support the \"nospace\" directive we trick the shell\n # by outputting an extra, longer completion.\n __${snakeCase(getAppBin(context))}_debug \"Adding second completion to perform nospace directive\"\n set --global __${snakeCase(getAppBin(context))}_comp_results $split[1] $split[1].\n __${snakeCase(getAppBin(context))}_debug \"Completions are now: $__${snakeCase(getAppBin(context))}_comp_results\"\n end\n end\n\n if test $numComps -eq 0; and test $nofiles -eq 0\n # To be consistent with bash and zsh, we only trigger file\n # completion when there are no other completions\n __${snakeCase(getAppBin(context))}_debug \"Requesting file completion\"\n return 1\n end\n end\n\n return 0\nend\n\n# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves\n# so we can properly delete any completions provided by another script.\n# Only do this if the program can be found, or else fish may print some errors; besides,\n# the existing completions will only be loaded if the program can be found.\nif type -q \"${getAppBin(context)}\"\n # The space after the program name is essential to trigger completion for the program\n # and not completion of the program name itself.\n # Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.\n complete --do-complete \"${getAppBin(context)} \" > /dev/null 2>&1\nend\n\n# Remove any pre-existing completions for the program since we will be handling all of them.\ncomplete -c ${getAppBin(context)} -e\n# This will get called after the two calls below and clear the cached result\ncomplete -c ${getAppBin(context)} -n '__${snakeCase(getAppBin(context))}_clear_perform_completion_once_result'\n# The call to __${snakeCase(getAppBin(context))}_prepare_completions will setup __${snakeCase(getAppBin(context))}_comp_results\n# which provides the program's completion choices.\n# If this doesn't require order preservation, we don't use the -k flag\ncomplete -c ${getAppBin(\n context\n )} -n 'not __${snakeCase(getAppBin(context))}_requires_order_preservation && __${snakeCase(getAppBin(context))}_prepare_completions' -f -a '$__${snakeCase(getAppBin(context))}_comp_results'\n# Otherwise we use the -k flag\ncomplete -k -c ${getAppBin(context)} -n '__${snakeCase(\n getAppBin(context)\n )}_requires_order_preservation && __${snakeCase(\n getAppBin(context)\n )}_prepare_completions' -f -a '$__${snakeCase(\n getAppBin(context)\n )}_comp_results'\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 ? \"~/.config/fish/config.fish\" : 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)} Fish 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.fish\" : options.script;\n await writeFile(outputPath, stripAnsi(completions));\n\n success(\\`${getAppTitle(context)} Fish 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":";;;;;;;;;;;;;;;;;;AAoCA,SAAS,yBAAwB;CACjC,MAAQ,UAAU,eAAwC;AAC1D,QAAS,gBAAkB,gBAAa;EACxC,IAAQ,OAAC;AACH,UAAO,UAAU,QAAE,WAAiB,eAAQ,QAAA,aAAA;;EAElD,SAAa;;GAEX,oBAAA,CAAA,YAAA,YAAA;GACC;EACD,gBAAA,EACI,uBAAU;GAAA;GAAwB;GAAC;GAAA;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;;KAEH,CAAC;IAAC;;EAEN,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
const require_components_bash_command = require('./bash-command.cjs');
|
|
2
3
|
const require_components_fish_command = require('./fish-command.cjs');
|
|
3
4
|
const require_components_powershell_command = require('./powershell-command.cjs');
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
const require_helpers_complete_command = require('../helpers/complete-command.cjs');
|
|
2
3
|
const require_helpers_completion_directive_constants = require('../helpers/completion-directive-constants.cjs');
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
let
|
|
11
|
-
let
|
|
12
|
-
let
|
|
13
|
-
let
|
|
14
|
-
let
|
|
4
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
5
|
+
let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
|
|
6
|
+
let _stryke_path = require("@stryke/path");
|
|
7
|
+
let _alloy_js_core = require("@alloy-js/core");
|
|
8
|
+
let _alloy_js_typescript = require("@alloy-js/typescript");
|
|
9
|
+
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
10
|
+
let _powerlines_plugin_alloy_core = require("@powerlines/plugin-alloy/core");
|
|
11
|
+
let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
|
|
12
|
+
let _powerlines_plugin_alloy_typescript = require("@powerlines/plugin-alloy/typescript");
|
|
13
|
+
let _powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
|
|
14
|
+
let _stryke_string_format_snake_case = require("@stryke/string-format/snake-case");
|
|
15
|
+
let _stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
15
16
|
|
|
16
17
|
//#region src/components/powershell-command.tsx
|
|
17
18
|
/**
|
|
18
19
|
* The PowerShell Completions commands' handler wrapper for the Shell Shock project.
|
|
19
20
|
*/
|
|
20
21
|
function PowerShellCompletionsCommand() {
|
|
21
|
-
const context = (0,
|
|
22
|
-
return (0,
|
|
22
|
+
const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
23
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.TypescriptFile, {
|
|
23
24
|
get path() {
|
|
24
|
-
return (0,
|
|
25
|
+
return (0, _stryke_path.joinPaths)(context.entryPath, "completions", "powershell", "command.ts");
|
|
25
26
|
},
|
|
26
27
|
imports: {
|
|
27
28
|
"node:os": ["os"],
|
|
@@ -36,43 +37,43 @@ function PowerShellCompletionsCommand() {
|
|
|
36
37
|
] },
|
|
37
38
|
get children() {
|
|
38
39
|
return [
|
|
39
|
-
(0,
|
|
40
|
-
(0,
|
|
40
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Options for the PowerShell completions command." }),
|
|
41
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
41
42
|
"export": true,
|
|
42
43
|
name: "PowerShellCompletionsOptions",
|
|
43
44
|
get children() {
|
|
44
45
|
return [
|
|
45
|
-
(0,
|
|
46
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
46
47
|
heading: "The path to write the completion script to.",
|
|
47
48
|
get children() {
|
|
48
|
-
return [(0,
|
|
49
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `If no extension is provided, the \`.ps1\` extension will be used.` }), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
|
|
49
50
|
get type() {
|
|
50
|
-
return
|
|
51
|
+
return _powerlines_deepkit_vendor_type.ReflectionKind.string;
|
|
51
52
|
},
|
|
52
53
|
get defaultValue() {
|
|
53
|
-
return `${(0,
|
|
54
|
+
return `${(0, _shell_shock_core_plugin_utils.getAppBin)(context)}-completions.ps1`;
|
|
54
55
|
}
|
|
55
56
|
})];
|
|
56
57
|
}
|
|
57
58
|
}),
|
|
58
|
-
(0,
|
|
59
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.InterfaceMember, {
|
|
59
60
|
name: "script",
|
|
60
61
|
optional: true,
|
|
61
62
|
type: "string | true"
|
|
62
63
|
}),
|
|
63
|
-
(0,
|
|
64
|
-
(0,
|
|
64
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
65
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
65
66
|
heading: "The PowerShell configuration file to append the completion script to.",
|
|
66
67
|
get children() {
|
|
67
|
-
return [(0,
|
|
68
|
+
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 PowerShell configuration file include: \\n- \`~/.config/powershell/Microsoft.PowerShell_profile.ps1\`` }), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
|
|
68
69
|
get type() {
|
|
69
|
-
return
|
|
70
|
+
return _powerlines_deepkit_vendor_type.ReflectionKind.string;
|
|
70
71
|
},
|
|
71
72
|
defaultValue: "~/.config/powershell/Microsoft.PowerShell_profile.ps1"
|
|
72
73
|
})];
|
|
73
74
|
}
|
|
74
75
|
}),
|
|
75
|
-
(0,
|
|
76
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript.InterfaceMember, {
|
|
76
77
|
name: "config",
|
|
77
78
|
optional: true,
|
|
78
79
|
type: "string | true"
|
|
@@ -80,9 +81,9 @@ function PowerShellCompletionsCommand() {
|
|
|
80
81
|
];
|
|
81
82
|
}
|
|
82
83
|
}),
|
|
83
|
-
(0,
|
|
84
|
-
(0,
|
|
85
|
-
(0,
|
|
84
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
85
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Handler logic for the \\`completions powershell\\` command." }),
|
|
86
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
86
87
|
"export": true,
|
|
87
88
|
"default": true,
|
|
88
89
|
async: true,
|
|
@@ -93,38 +94,38 @@ function PowerShellCompletionsCommand() {
|
|
|
93
94
|
}],
|
|
94
95
|
get children() {
|
|
95
96
|
return [
|
|
96
|
-
(0,
|
|
97
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
97
98
|
"const": true,
|
|
98
99
|
name: "completions",
|
|
99
100
|
type: "string",
|
|
100
101
|
get initializer() {
|
|
101
|
-
return
|
|
102
|
+
return _alloy_js_core.code`# powershell completion for ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} -*- shell-script -*-
|
|
102
103
|
|
|
103
104
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
104
|
-
function __${(0,
|
|
105
|
+
function __${(0, _stryke_string_format_snake_case.snakeCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug {
|
|
105
106
|
if ($env:BASH_COMP_DEBUG_FILE) {
|
|
106
107
|
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
filter __${(0,
|
|
111
|
+
filter __${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_escapeStringWithSpecialChars {
|
|
111
112
|
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
[scriptblock]$__${(0,
|
|
115
|
+
[scriptblock]$__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}CompleterBlock = {
|
|
115
116
|
param(
|
|
116
117
|
$WordToComplete,
|
|
117
118
|
$CommandAst,
|
|
118
119
|
$CursorPosition
|
|
119
120
|
)
|
|
120
121
|
|
|
121
|
-
# Get the current command
|
|
122
|
+
# Get the current command-line and convert into a string
|
|
122
123
|
$Command = $CommandAst.CommandElements
|
|
123
124
|
$Command = "$Command"
|
|
124
125
|
|
|
125
|
-
__${(0,
|
|
126
|
-
__${(0,
|
|
127
|
-
__${(0,
|
|
126
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug ""
|
|
127
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "========= starting completion logic =========="
|
|
128
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
|
|
128
129
|
|
|
129
130
|
# The user could have moved the cursor backwards on the command-line.
|
|
130
131
|
# We need to trigger completion from the $CursorPosition location, so we need
|
|
@@ -134,7 +135,7 @@ function PowerShellCompletionsCommand() {
|
|
|
134
135
|
if ($Command.Length -gt $CursorPosition) {
|
|
135
136
|
$Command = $Command.Substring(0, $CursorPosition)
|
|
136
137
|
}
|
|
137
|
-
__${(0,
|
|
138
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Truncated command: $Command"
|
|
138
139
|
|
|
139
140
|
$ShellCompDirectiveError=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveError}
|
|
140
141
|
$ShellCompDirectiveNoSpace=${require_helpers_completion_directive_constants.CompletionDirective.CompletionDirectiveNoSpace}
|
|
@@ -148,10 +149,10 @@ function PowerShellCompletionsCommand() {
|
|
|
148
149
|
$Program, $Arguments = $Command.Split(" ", 2)
|
|
149
150
|
|
|
150
151
|
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
|
|
151
|
-
__${(0,
|
|
152
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "QuotedArgs: $QuotedArgs"
|
|
152
153
|
|
|
153
154
|
$RequestComp = "& ${require_helpers_complete_command.exec} complete '--' $QuotedArgs"
|
|
154
|
-
__${(0,
|
|
155
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "RequestComp: $RequestComp"
|
|
155
156
|
|
|
156
157
|
# we cannot use $WordToComplete because it
|
|
157
158
|
# has the wrong values if the cursor was moved
|
|
@@ -159,13 +160,13 @@ function PowerShellCompletionsCommand() {
|
|
|
159
160
|
if ($WordToComplete -ne "" ) {
|
|
160
161
|
$WordToComplete = $Arguments.Split(" ")[-1]
|
|
161
162
|
}
|
|
162
|
-
__${(0,
|
|
163
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "New WordToComplete: $WordToComplete"
|
|
163
164
|
|
|
164
165
|
|
|
165
166
|
# Check for flag with equal sign
|
|
166
167
|
$IsEqualFlag = ($WordToComplete -Like "--*=*" )
|
|
167
168
|
if ( $IsEqualFlag ) {
|
|
168
|
-
__${(0,
|
|
169
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Completing equal sign flag"
|
|
169
170
|
# Remove the flag part
|
|
170
171
|
$Flag, $WordToComplete = $WordToComplete.Split("=", 2)
|
|
171
172
|
}
|
|
@@ -173,7 +174,7 @@ function PowerShellCompletionsCommand() {
|
|
|
173
174
|
if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
|
|
174
175
|
# If the last parameter is complete (there is a space following it)
|
|
175
176
|
# We add an extra empty parameter so we can indicate this to the go method.
|
|
176
|
-
__${(0,
|
|
177
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Adding extra empty parameter"
|
|
177
178
|
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
|
|
178
179
|
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
|
|
179
180
|
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
|
|
@@ -186,7 +187,7 @@ function PowerShellCompletionsCommand() {
|
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
__${(0,
|
|
190
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Calling $RequestComp"
|
|
190
191
|
# First disable ActiveHelp which is not supported for Powershell
|
|
191
192
|
$env:ActiveHelp = 0
|
|
192
193
|
|
|
@@ -200,14 +201,14 @@ function PowerShellCompletionsCommand() {
|
|
|
200
201
|
# There is no directive specified
|
|
201
202
|
$Directive = 0
|
|
202
203
|
}
|
|
203
|
-
__${(0,
|
|
204
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "The completion directive is: $Directive"
|
|
204
205
|
|
|
205
206
|
# remove directive (last element) from out
|
|
206
207
|
$Out = $Out | Where-Object { $_ -ne $Out[-1] }
|
|
207
|
-
__${(0,
|
|
208
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "The completions are: $Out"
|
|
208
209
|
if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
|
|
209
210
|
# Error code. No completion.
|
|
210
|
-
__${(0,
|
|
211
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Received error from custom completion go code"
|
|
211
212
|
return
|
|
212
213
|
}
|
|
213
214
|
|
|
@@ -215,7 +216,7 @@ function PowerShellCompletionsCommand() {
|
|
|
215
216
|
[Array]$Values = $Out | ForEach-Object {
|
|
216
217
|
# Split the output in name and description
|
|
217
218
|
$Name, $Description = $_.Split("\`t", 2)
|
|
218
|
-
__${(0,
|
|
219
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Name: $Name Description: $Description"
|
|
219
220
|
|
|
220
221
|
# Look for the longest completion so that we can format things nicely
|
|
221
222
|
if ($Longest -lt $Name.Length) {
|
|
@@ -234,13 +235,13 @@ function PowerShellCompletionsCommand() {
|
|
|
234
235
|
$Space = " "
|
|
235
236
|
if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
|
|
236
237
|
# remove the space here
|
|
237
|
-
__${(0,
|
|
238
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "ShellCompDirectiveNoSpace is called"
|
|
238
239
|
$Space = ""
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
|
|
242
243
|
(($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
|
|
243
|
-
__${(0,
|
|
244
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
|
|
244
245
|
|
|
245
246
|
# return here to prevent the completion of the extensions
|
|
246
247
|
return
|
|
@@ -252,7 +253,7 @@ function PowerShellCompletionsCommand() {
|
|
|
252
253
|
|
|
253
254
|
# Join the flag back if we have an equal sign flag
|
|
254
255
|
if ( $IsEqualFlag ) {
|
|
255
|
-
__${(0,
|
|
256
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Join the equal sign flag back to the completion value"
|
|
256
257
|
$_.Name = $Flag + "=" + $_.Name
|
|
257
258
|
}
|
|
258
259
|
}
|
|
@@ -263,7 +264,7 @@ function PowerShellCompletionsCommand() {
|
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
|
|
266
|
-
__${(0,
|
|
267
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "ShellCompDirectiveNoFileComp is called"
|
|
267
268
|
|
|
268
269
|
if ($Values.Length -eq 0) {
|
|
269
270
|
# Just print an empty string here so the
|
|
@@ -277,7 +278,7 @@ function PowerShellCompletionsCommand() {
|
|
|
277
278
|
|
|
278
279
|
# Get the current mode
|
|
279
280
|
$Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
|
|
280
|
-
__${(0,
|
|
281
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Mode: $Mode"
|
|
281
282
|
|
|
282
283
|
$Values | ForEach-Object {
|
|
283
284
|
|
|
@@ -302,7 +303,7 @@ function PowerShellCompletionsCommand() {
|
|
|
302
303
|
"Complete" {
|
|
303
304
|
|
|
304
305
|
if ($Values.Length -eq 1) {
|
|
305
|
-
__${(0,
|
|
306
|
+
__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}_debug "Only one completion left"
|
|
306
307
|
|
|
307
308
|
# insert space after value
|
|
308
309
|
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
@@ -344,35 +345,35 @@ function PowerShellCompletionsCommand() {
|
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
347
|
|
|
347
|
-
Register-ArgumentCompleter -CommandName '${(0,
|
|
348
|
+
Register-ArgumentCompleter -CommandName '${(0, _shell_shock_core_plugin_utils.getAppBin)(context)}' -ScriptBlock $__${(0, _stryke_string_format_camel_case.camelCase)((0, _shell_shock_core_plugin_utils.getAppBin)(context))}CompleterBlock
|
|
348
349
|
\`); `;
|
|
349
350
|
}
|
|
350
351
|
}),
|
|
351
|
-
(0,
|
|
352
|
-
(0,
|
|
353
|
-
condition:
|
|
352
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
353
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
354
|
+
condition: _alloy_js_core.code`options.config`,
|
|
354
355
|
get children() {
|
|
355
356
|
return [
|
|
356
|
-
(0,
|
|
357
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
357
358
|
"let": true,
|
|
358
359
|
name: "configFilePath",
|
|
359
360
|
type: "string",
|
|
360
|
-
initializer:
|
|
361
|
+
initializer: _alloy_js_core.code`options.config === true ? "~/.config/powershell/Microsoft.PowerShell_profile.ps1" : options.config`
|
|
361
362
|
}),
|
|
362
|
-
(0,
|
|
363
|
-
(0,
|
|
364
|
-
condition:
|
|
365
|
-
children:
|
|
363
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
364
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
365
|
+
condition: _alloy_js_core.code`configFilePath.startsWith("~")`,
|
|
366
|
+
children: _alloy_js_core.code`configFilePath = join(os.homedir(), configFilePath.replace("~", "")); `
|
|
366
367
|
}),
|
|
367
|
-
(0,
|
|
368
|
-
(0,
|
|
368
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
369
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
369
370
|
"let": true,
|
|
370
371
|
name: "configFileContent",
|
|
371
372
|
type: "string",
|
|
372
|
-
initializer:
|
|
373
|
+
initializer: _alloy_js_core.code`"";`
|
|
373
374
|
}),
|
|
374
|
-
(0,
|
|
375
|
-
(0,
|
|
375
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
376
|
+
(0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`try {
|
|
376
377
|
configFileContent = await readFile(configFilePath, "utf8");
|
|
377
378
|
} catch (error) {
|
|
378
379
|
if (error.code === "ENOENT") {
|
|
@@ -385,24 +386,24 @@ Register-ArgumentCompleter -CommandName '${(0, __shell_shock_core_plugin_utils.g
|
|
|
385
386
|
|
|
386
387
|
await writeFile(configFilePath, \`\${configFileContent}\\n\\n\${stripAnsi(completions)}\`);
|
|
387
388
|
|
|
388
|
-
success(\`${(0,
|
|
389
|
+
success(\`${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} PowerShell completion script has been generated and appended to \${colors.bold(configFilePath)}. Please restart your terminal or run \`source \${configFilePath}\` to apply the changes.\`); `)
|
|
389
390
|
];
|
|
390
391
|
}
|
|
391
392
|
}),
|
|
392
|
-
(0,
|
|
393
|
-
(0,
|
|
394
|
-
condition:
|
|
393
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
394
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
395
|
+
condition: _alloy_js_core.code`options.script`,
|
|
395
396
|
get children() {
|
|
396
|
-
return
|
|
397
|
+
return _alloy_js_core.code`const outputPath = options.script === true ? "${(0, _shell_shock_core_plugin_utils.getAppBin)(context)}-completions.powershell" : options.script;
|
|
397
398
|
await writeFile(outputPath, stripAnsi(completions));
|
|
398
399
|
|
|
399
|
-
success(\`${(0,
|
|
400
|
+
success(\`${(0, _shell_shock_core_plugin_utils.getAppTitle)(context)} PowerShell completion script has been generated at \${colors.bold(outputPath)}.\`);`;
|
|
400
401
|
}
|
|
401
402
|
}),
|
|
402
|
-
(0,
|
|
403
|
-
(0,
|
|
404
|
-
condition:
|
|
405
|
-
children:
|
|
403
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core.Spacing, {}),
|
|
404
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
405
|
+
condition: _alloy_js_core.code`!options.config && !options.script`,
|
|
406
|
+
children: _alloy_js_core.code`writeLine(" ------------------------------------------------- ");
|
|
406
407
|
writeLine(completions);
|
|
407
408
|
writeLine(" ------------------------------------------------- ");`
|
|
408
409
|
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _alloy_js_core0 from "@alloy-js/core";
|
|
2
2
|
|
|
3
3
|
//#region src/components/powershell-command.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The PowerShell Completions commands' handler wrapper for the Shell Shock project.
|
|
6
6
|
*/
|
|
7
|
-
declare function PowerShellCompletionsCommand():
|
|
7
|
+
declare function PowerShellCompletionsCommand(): _alloy_js_core0.Children;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { PowerShellCompletionsCommand };
|
|
10
10
|
//# sourceMappingURL=powershell-command.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powershell-command.d.cts","names":[],"sources":["../../src/components/powershell-command.tsx"],"
|
|
1
|
+
{"version":3,"file":"powershell-command.d.cts","names":[],"sources":["../../src/components/powershell-command.tsx"],"mappings":";;;;;;iBAgDgB,4BAAA,CAAA,GAA4B,eAAA,CAAA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powershell-command.d.mts","names":[],"sources":["../../src/components/powershell-command.tsx"],"
|
|
1
|
+
{"version":3,"file":"powershell-command.d.mts","names":[],"sources":["../../src/components/powershell-command.tsx"],"mappings":";;;;;;iBAgDgB,4BAAA,CAAA,GAA4B,eAAA,CAAA,QAAA"}
|
|
@@ -118,7 +118,7 @@ function PowerShellCompletionsCommand() {
|
|
|
118
118
|
$CursorPosition
|
|
119
119
|
)
|
|
120
120
|
|
|
121
|
-
# Get the current command
|
|
121
|
+
# Get the current command-line and convert into a string
|
|
122
122
|
$Command = $CommandAst.CommandElements
|
|
123
123
|
$Command = "$Command"
|
|
124
124
|
|