Skip to content

Commit

Permalink
[cli] Expand bash-like homedir shortcuts (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars authored Sep 19, 2017
1 parent b63ee8d commit 1eb7b9c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/@sanity/cli/src/commands/init/gatherInput.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'os'
import path from 'path'
import fsp from 'fs-promise'
import validateNpmPackageName from 'validate-npm-package-name'
Expand Down Expand Up @@ -106,8 +107,22 @@ function pathIsEmpty(dir) {
})
}

function expandHome(filePath) {
if (filePath.charCodeAt(0) === 126 /* ~ */) {
if (filePath.charCodeAt(1) === 43 /* + */) {
return path.join(process.cwd(), filePath.slice(2))
}

const home = os.homedir()
return home ? path.join(home, filePath.slice(1)) : filePath
}

return filePath
}

function absolutify(dir) {
return path.isAbsolute(dir)
? dir
: path.resolve(process.cwd(), dir)
const pathName = expandHome(dir)
return path.isAbsolute(pathName)
? pathName
: path.resolve(process.cwd(), pathName)
}

0 comments on commit 1eb7b9c

Please sign in to comment.