Skip to content

Commit 47d4cee

Browse files
authored
feat(command-lm): add PATH configuration for fish shell (#1943)
1 parent 0db6674 commit 47d4cee

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/utils/lm/install.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,33 +134,29 @@ 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 = (incFilePath) => `${CONTENT_COMMENT}test -f '${incFilePath}' && source '${incFilePath}'`
142+
142143
const setupUnixPath = async () => {
143144
if (isBinInPath()) {
144145
return true
145146
}
146147

147-
const { shell, incFilePath, configFile } = shellVariables()
148-
const initContent = getInitContent(incFilePath)
148+
const { shell, incFilePath, configFile } = getShellInfo()
149149

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.
150+
if (configFile === undefined) {
151+
const error = `Unable to set credential helper in PATH. We don't how to set the path for ${shell} shell.
160152
Set the helper path in your environment PATH: ${getBinPath()}`
161-
throw new Error(error)
162-
}
153+
throw new Error(error)
163154
}
155+
156+
return await Promise.all([
157+
await copyFileAsync(`${__dirname}/scripts/${shell}.sh`, incFilePath),
158+
await writeConfig(configFile, getInitContent(incFilePath)),
159+
])
164160
}
165161

166162
const writeConfig = async function (name, initContent) {
@@ -253,9 +249,10 @@ const getLegacyBinPath = function () {
253249
const CONFIG_FILES = {
254250
bash: '.bashrc',
255251
zsh: '.zshrc',
252+
fish: '.config/fish/config.fish',
256253
}
257254

258-
const shellVariables = function () {
255+
const getShellInfo = function () {
259256
const shellEnv = process.env.SHELL
260257
if (!shellEnv) {
261258
throw new Error('Unable to detect SHELL type, make sure the variable is defined in your environment')
@@ -271,7 +268,7 @@ const shellVariables = function () {
271268

272269
const cleanupShell = async function () {
273270
try {
274-
const { configFile, incFilePath } = shellVariables()
271+
const { configFile, incFilePath } = getShellInfo()
275272
if (configFile === undefined) {
276273
return
277274
}
@@ -299,4 +296,4 @@ const removeConfig = async function (name, toRemove) {
299296
return await writeFileAsync(configPath, content.replace(toRemove, ''))
300297
}
301298

302-
module.exports = { installPlatform, isBinInPath, shellVariables, uninstall }
299+
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)