Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/utils/lm/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
Expand All @@ -271,7 +268,7 @@ const shellVariables = function () {

const cleanupShell = async function () {
try {
const { configFile, incFilePath } = shellVariables()
const { configFile, incFilePath } = getShellInfo()
if (configFile === undefined) {
return
}
Expand Down Expand Up @@ -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 }
3 changes: 3 additions & 0 deletions src/utils/lm/scripts/fish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env fish

set -U fish_user_paths (dirname (status --current-filename)) $fish_user_paths
4 changes: 2 additions & 2 deletions src/utils/lm/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
)
Expand Down