Skip to content

Commit ff7b5f7

Browse files
authored
Add homebrew install script (#236)
1 parent 8478773 commit ff7b5f7

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
!/tools/
1919
!/setup/
2020
!/chocolatey/
21+
!/homebrew/
2122

2223
# Temporary files generated during testing
2324
/test/temp

homebrew/install.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
NVS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
4+
5+
# Set environment variables
6+
export HOME=~
7+
export NVS_HOME=~/.nvs
8+
9+
# Run install script
10+
\. $NVS_DIR/nvs.sh install

lib/install.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,32 @@ function getShellProfile() {
145145
}
146146

147147
function installToShellProfile(profileFile) {
148+
let rootPathAbs = path.resolve(__dirname, '..');
149+
let homePathAbs = path.resolve(settings.home);
150+
151+
let rootPath = nvsUse.homePath(rootPathAbs).replace('~', '$HOME');
148152
let homePath = nvsUse.homePath(settings.home).replace('~', '$HOME');
149153
if (homePath.endsWith('/') || homePath.endsWith('\\')) {
150154
homePath = homePath.substr(0, homePath.length - 1);
151155
}
152156

157+
if (rootPathAbs === homePathAbs) {
158+
rootPath = '$NVS_HOME';
159+
}
160+
153161
const installLines = isMingwBash
154162
? [
155163
'function setupNvs {',
156164
' export NVS_HOME="' + homePath + '";',
157-
' [ -s "$NVS_HOME/nvs.sh" ] && source "$NVS_HOME/nvs.sh" >> /dev/null;',
165+
' [ -s "' + rootPath + '/nvs.sh" ] && source "' + rootPath + '/nvs.sh" >> /dev/null;',
158166
' return 0;',
159167
'}',
160168
'setupNvs',
161169
]
162170
// normal POSIX shell
163171
: [
164172
'export NVS_HOME="' + homePath + '"',
165-
'[ -s "$NVS_HOME/nvs.sh" ] && . "$NVS_HOME/nvs.sh"',
173+
'[ -s "' + rootPath + '/nvs.sh" ] && . "' + rootPath + '/nvs.sh"',
166174
];
167175

168176
if (!profileFile) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nvs",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "Node Version Switcher",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)