@@ -9,19 +9,10 @@ import t, { type RootCommand } from './t';
99
1010const execPath = process . execPath ;
1111const processArgs = process . argv . slice ( 1 ) ;
12- const quotedExecPath = quoteIfNeeded ( execPath ) ;
13- const quotedProcessArgs = processArgs . map ( quoteIfNeeded ) ;
14- const quotedProcessExecArgs = process . execArgv . map ( quoteIfNeeded ) ;
15-
16- const x = `${ quotedExecPath } ${ quotedProcessExecArgs . join ( ' ' ) } ${ quotedProcessArgs [ 0 ] } ` ;
1712
1813// Regex to detect if an option takes a value (has <required> or [optional] parameters)
1914const VALUE_OPTION_RE = / < [ ^ > ] + > | \[ [ ^ \] ] + \] / ;
2015
21- function quoteIfNeeded ( path : string ) : string {
22- return path . includes ( ' ' ) ? `'${ path } '` : path ;
23- }
24-
2516export default async function tab (
2617 instance : CAC ,
2718 completionConfig ?: CompletionConfig
@@ -122,24 +113,27 @@ export default async function tab(
122113 }
123114
124115 instance . command ( 'complete [shell]' ) . action ( async ( shell , extra ) => {
116+ // invoke the cli by its program name so completion works regardless of how
117+ // the cli is launched (including compiled binaries). see the related issue #135
118+ const execCommand = instance . name ;
125119 switch ( shell ) {
126120 case 'zsh' : {
127- const script = zsh . generate ( instance . name , x ) ;
121+ const script = zsh . generate ( instance . name , execCommand ) ;
128122 console . log ( script ) ;
129123 break ;
130124 }
131125 case 'bash' : {
132- const script = bash . generate ( instance . name , x ) ;
126+ const script = bash . generate ( instance . name , execCommand ) ;
133127 console . log ( script ) ;
134128 break ;
135129 }
136130 case 'fish' : {
137- const script = fish . generate ( instance . name , x ) ;
131+ const script = fish . generate ( instance . name , execCommand ) ;
138132 console . log ( script ) ;
139133 break ;
140134 }
141135 case 'powershell' : {
142- const script = powershell . generate ( instance . name , x ) ;
136+ const script = powershell . generate ( instance . name , execCommand ) ;
143137 console . log ( script ) ;
144138 break ;
145139 }
0 commit comments