@@ -134,33 +134,37 @@ const setupWindowsPath = async function () {
134134 )
135135}
136136
137- const getInitContent = ( incFilePath ) => `
137+ const CONTENT_COMMENT = `
138138# The next line updates PATH for Netlify's Git Credential Helper.
139- if [ -f '${ incFilePath } ' ]; then source '${ incFilePath } '; fi
140139`
141140
141+ const getInitContent = ( shell , incFilePath ) => {
142+ if ( shell === 'fish' ) {
143+ return `${ CONTENT_COMMENT } test -f '${ incFilePath } ' && source '${ incFilePath } '
144+ `
145+ }
146+
147+ return `${ CONTENT_COMMENT } if [ -f '${ incFilePath } ' ]; then source '${ incFilePath } '; fi
148+ `
149+ }
150+
142151const setupUnixPath = async ( ) => {
143152 if ( isBinInPath ( ) ) {
144153 return true
145154 }
146155
147- const { shell, incFilePath, configFile } = shellVariables ( )
148- const initContent = getInitContent ( incFilePath )
156+ const { shell, incFilePath, configFile } = getShellInfo ( )
149157
150- switch ( shell ) {
151- case 'bash' :
152- case 'zsh' : {
153- return await Promise . all ( [
154- await copyFileAsync ( `${ __dirname } /scripts/${ shell } .sh` , incFilePath ) ,
155- await writeConfig ( configFile , initContent ) ,
156- ] )
157- }
158- default : {
159- const error = `Unable to set credential helper in PATH. We don't how to set the path for ${ shell } shell.
158+ if ( configFile === undefined ) {
159+ const error = `Unable to set credential helper in PATH. We don't how to set the path for ${ shell } shell.
160160Set the helper path in your environment PATH: ${ getBinPath ( ) } `
161- throw new Error ( error )
162- }
161+ throw new Error ( error )
163162 }
163+
164+ return await Promise . all ( [
165+ await copyFileAsync ( `${ __dirname } /scripts/${ shell } .sh` , incFilePath ) ,
166+ await writeConfig ( configFile , getInitContent ( shell , incFilePath ) ) ,
167+ ] )
164168}
165169
166170const writeConfig = async function ( name , initContent ) {
@@ -253,9 +257,10 @@ const getLegacyBinPath = function () {
253257const CONFIG_FILES = {
254258 bash : '.bashrc' ,
255259 zsh : '.zshrc' ,
260+ fish : '.config/fish/config.fish' ,
256261}
257262
258- const shellVariables = function ( ) {
263+ const getShellInfo = function ( ) {
259264 const shellEnv = process . env . SHELL
260265 if ( ! shellEnv ) {
261266 throw new Error ( 'Unable to detect SHELL type, make sure the variable is defined in your environment' )
@@ -271,12 +276,12 @@ const shellVariables = function () {
271276
272277const cleanupShell = async function ( ) {
273278 try {
274- const { configFile, incFilePath } = shellVariables ( )
279+ const { configFile, shell , incFilePath } = getShellInfo ( )
275280 if ( configFile === undefined ) {
276281 return
277282 }
278283
279- await removeConfig ( configFile , getInitContent ( incFilePath ) )
284+ await removeConfig ( configFile , getInitContent ( shell , incFilePath ) )
280285 } catch ( _ ) { }
281286}
282287
@@ -299,4 +304,4 @@ const removeConfig = async function (name, toRemove) {
299304 return await writeFileAsync ( configPath , content . replace ( toRemove , '' ) )
300305}
301306
302- module . exports = { installPlatform, isBinInPath, shellVariables , uninstall }
307+ module . exports = { installPlatform, isBinInPath, getShellInfo , uninstall }
0 commit comments