Skip to content

Commit 61b131a

Browse files
committed
feat(command-lm): add PATH configuration for fish shell
1 parent 0b6db33 commit 61b131a

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

src/utils/lm/install.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
142151
const 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.
160160
Set 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

166170
const writeConfig = async function (name, initContent) {
@@ -253,9 +257,10 @@ const getLegacyBinPath = function () {
253257
const 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

272277
const 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 }

src/utils/lm/scripts/fish.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env fish
2+
3+
set -U fish_user_paths (dirname (status --current-filename)) $fish_user_paths

src/utils/lm/ui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ const os = require('os')
33
const boxen = require('boxen')
44
const chalk = require('chalk')
55

6-
const { shellVariables, isBinInPath } = require('./install')
6+
const { getShellInfo, isBinInPath } = require('./install')
77

88
const printBanner = function (command, force) {
99
const print = force || !isBinInPath()
1010
const platform = os.platform()
1111

1212
if (print && platform !== 'win32') {
13-
const { incFilePath } = shellVariables()
13+
const { incFilePath } = getShellInfo()
1414
const banner = chalk.bold(
1515
`Run this command to use Netlify Large Media in your current shell\n\nsource ${incFilePath}`,
1616
)

0 commit comments

Comments
 (0)