diff --git a/src/utils/lm/install.js b/src/utils/lm/install.js index 2614ec8fe42..70b0f40e14c 100644 --- a/src/utils/lm/install.js +++ b/src/utils/lm/install.js @@ -134,33 +134,29 @@ const setupWindowsPath = async function () { ) } -const getInitContent = (incFilePath) => ` +const CONTENT_COMMENT = ` # The next line updates PATH for Netlify's Git Credential Helper. -if [ -f '${incFilePath}' ]; then source '${incFilePath}'; fi ` +const getInitContent = (incFilePath) => `${CONTENT_COMMENT}test -f '${incFilePath}' && source '${incFilePath}'` + const setupUnixPath = async () => { if (isBinInPath()) { return true } - const { shell, incFilePath, configFile } = shellVariables() - const initContent = getInitContent(incFilePath) + const { shell, incFilePath, configFile } = getShellInfo() - switch (shell) { - case 'bash': - case 'zsh': { - return await Promise.all([ - await copyFileAsync(`${__dirname}/scripts/${shell}.sh`, incFilePath), - await writeConfig(configFile, initContent), - ]) - } - default: { - const error = `Unable to set credential helper in PATH. We don't how to set the path for ${shell} shell. + if (configFile === undefined) { + const error = `Unable to set credential helper in PATH. We don't how to set the path for ${shell} shell. Set the helper path in your environment PATH: ${getBinPath()}` - throw new Error(error) - } + throw new Error(error) } + + return await Promise.all([ + await copyFileAsync(`${__dirname}/scripts/${shell}.sh`, incFilePath), + await writeConfig(configFile, getInitContent(incFilePath)), + ]) } const writeConfig = async function (name, initContent) { @@ -253,9 +249,10 @@ const getLegacyBinPath = function () { const CONFIG_FILES = { bash: '.bashrc', zsh: '.zshrc', + fish: '.config/fish/config.fish', } -const shellVariables = function () { +const getShellInfo = function () { const shellEnv = process.env.SHELL if (!shellEnv) { throw new Error('Unable to detect SHELL type, make sure the variable is defined in your environment') @@ -271,7 +268,7 @@ const shellVariables = function () { const cleanupShell = async function () { try { - const { configFile, incFilePath } = shellVariables() + const { configFile, incFilePath } = getShellInfo() if (configFile === undefined) { return } @@ -299,4 +296,4 @@ const removeConfig = async function (name, toRemove) { return await writeFileAsync(configPath, content.replace(toRemove, '')) } -module.exports = { installPlatform, isBinInPath, shellVariables, uninstall } +module.exports = { installPlatform, isBinInPath, getShellInfo, uninstall } diff --git a/src/utils/lm/scripts/fish.sh b/src/utils/lm/scripts/fish.sh new file mode 100644 index 00000000000..123364798e2 --- /dev/null +++ b/src/utils/lm/scripts/fish.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env fish + +set -U fish_user_paths (dirname (status --current-filename)) $fish_user_paths diff --git a/src/utils/lm/ui.js b/src/utils/lm/ui.js index c41675d17b9..3efc53d825a 100644 --- a/src/utils/lm/ui.js +++ b/src/utils/lm/ui.js @@ -3,14 +3,14 @@ const os = require('os') const boxen = require('boxen') const chalk = require('chalk') -const { shellVariables, isBinInPath } = require('./install') +const { getShellInfo, isBinInPath } = require('./install') const printBanner = function (command, force) { const print = force || !isBinInPath() const platform = os.platform() if (print && platform !== 'win32') { - const { incFilePath } = shellVariables() + const { incFilePath } = getShellInfo() const banner = chalk.bold( `Run this command to use Netlify Large Media in your current shell\n\nsource ${incFilePath}`, )