From e777e76c2e523ce241542261e51be9a284935b8a Mon Sep 17 00:00:00 2001 From: Maxwell Brown Date: Sun, 26 Nov 2023 07:45:48 -0500 Subject: [PATCH] handle all parent names for zsh completions --- src/internal/command.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/internal/command.ts b/src/internal/command.ts index b2211d8..bbaf95f 100644 --- a/src/internal/command.ts +++ b/src/internal/command.ts @@ -1330,7 +1330,7 @@ const getZshSubcommandCases = ( } case "Subcommands": { const nextSubcommands = getImmediateSubcommands(self.child as Instruction) - const parentName = Array.from(getNamesInternal(self.parent as Instruction))[0] + const parentNames = Array.from(getNamesInternal(self.parent as Instruction)) const parentLines = getZshSubcommandCases( self.parent as Instruction, parentCommands, @@ -1338,15 +1338,16 @@ const getZshSubcommandCases = ( ) const childCases = getZshSubcommandCases( self.child as Instruction, - ReadonlyArray.append(parentCommands, parentName), + ReadonlyArray.appendAll(parentCommands, parentNames), subcommands ) const hyphenName = pipe( - ReadonlyArray.append(parentCommands, parentName), + ReadonlyArray.appendAll(parentCommands, parentNames), ReadonlyArray.join("-") ) const childLines = pipe( - [ + parentNames, + ReadonlyArray.flatMap((parentName) => [ "case $state in", ` (${parentName})`, ` words=($line[1] "\${words[@]}")`, @@ -1357,7 +1358,7 @@ const getZshSubcommandCases = ( " esac", " ;;", "esac" - ], + ]), ReadonlyArray.appendAll( ReadonlyArray.isEmptyReadonlyArray(parentCommands) ? ReadonlyArray.empty()