@@ -6,6 +6,8 @@ import type { LocalContext } from "./context";
6
6
import {
7
7
binBashCompleteModuleText ,
8
8
binBashCompleteScriptText ,
9
+ binFishCompleteModuleText ,
10
+ binFishCompleteScriptText ,
9
11
binCliModuleText ,
10
12
binCliScriptText ,
11
13
buildMultiCommandAppWithAutoCompleteText ,
@@ -40,6 +42,10 @@ function calculateBashCompletionCommand(command: string): string {
40
42
return `__${ command } _bash_complete` ;
41
43
}
42
44
45
+ function calculateFishCompletionCommand ( command : string ) : string {
46
+ return `__${ command } _fish_complete` ;
47
+ }
48
+
43
49
type PackageJsonTemplateValues = Pick < PackageJson . PackageJsonStandard , "name" > &
44
50
Required < Pick < PackageJson . PackageJsonStandard , "author" | "description" | "license" | "type" > > ;
45
51
@@ -82,7 +88,7 @@ function buildPackageJson(
82
88
} ;
83
89
}
84
90
85
- function addAutoCompleteBin ( packageJson : LocalPackageJson , bashCompleteCommandName : string ) : LocalPackageJson {
91
+ function addAutoCompleteBin ( packageJson : LocalPackageJson , bashCompleteCommandName : string , fishCompleteCommandName : string ) : LocalPackageJson {
86
92
return {
87
93
...packageJson ,
88
94
dependencies : {
@@ -92,11 +98,12 @@ function addAutoCompleteBin(packageJson: LocalPackageJson, bashCompleteCommandNa
92
98
bin : {
93
99
...( packageJson . bin as Record < string , string > ) ,
94
100
[ bashCompleteCommandName ] : "dist/bash-complete.js" ,
101
+ [ fishCompleteCommandName ] : "dist/fish-complete.js" ,
95
102
} ,
96
103
tsup : {
97
104
...packageJson . tsup ,
98
105
/* c8 ignore next */
99
- entry : [ ...( packageJson . tsup ?. entry ?? [ ] ) , "src/bin/bash-complete.ts" ] ,
106
+ entry : [ ...( packageJson . tsup ?. entry ?? [ ] ) , "src/bin/bash-complete.ts" , "src/bin/fish-complete.ts" ] ,
100
107
} ,
101
108
} ;
102
109
}
@@ -158,15 +165,16 @@ export default async function (this: LocalContext, flags: CreateProjectFlags, di
158
165
) ;
159
166
160
167
const bashCommandName = calculateBashCompletionCommand ( commandName ) ;
168
+ const fishCommandName = calculateFishCompletionCommand ( commandName ) ;
161
169
162
170
if ( flags . autoComplete ) {
163
- packageJson = addAutoCompleteBin ( packageJson , bashCommandName ) ;
171
+ packageJson = addAutoCompleteBin ( packageJson , bashCommandName , fishCommandName ) ;
164
172
if ( flags . template === "multi" ) {
165
173
packageJson = addPostinstallScript ( packageJson , `${ commandName } install` ) ;
166
174
} else {
167
175
packageJson = addPostinstallScript (
168
176
packageJson ,
169
- `npx @stricli/auto-complete@latest install ${ commandName } --bash ${ bashCommandName } ` ,
177
+ `npx @stricli/auto-complete@latest install ${ commandName } --bash ${ bashCommandName } --fish ${ fishCommandName } ` ,
170
178
) ;
171
179
}
172
180
await writeFile ( "src/context.ts" , localContextWithAutoCompleteText ) ;
@@ -209,5 +217,10 @@ export default async function (this: LocalContext, flags: CreateProjectFlags, di
209
217
"src/bin/bash-complete.ts" ,
210
218
flags . type === "module" ? binBashCompleteModuleText : binBashCompleteScriptText ,
211
219
) ;
220
+
221
+ await writeFile (
222
+ "src/bin/fish-complete.ts" ,
223
+ flags . type === "module" ? binFishCompleteModuleText : binFishCompleteScriptText ,
224
+ ) ;
212
225
}
213
226
}
0 commit comments