Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 563e326

Browse files
committed
fix: allow Nixster to be used from within an environment shell
1 parent dcdb25b commit 563e326

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

package-lock.json

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/mkdirp": "^0.5.2",
4343
"@types/sprintf-js": "^1.1.1",
4444
"@types/stream-to-promise": "^2.2.0",
45+
"@types/tmp": "0.0.33",
4546
"@types/yargs": "^12.0.5",
4647
"all-contributors-cli": "^5.7.0",
4748
"jest": "^23.6.0",
@@ -64,6 +65,7 @@
6465
"mkdirp": "^0.5.1",
6566
"node-pty": "^0.8.0",
6667
"sprintf-js": "^1.1.2",
68+
"tmp": "0.0.33",
6769
"yargs": "^12.0.5"
6870
}
6971
}

src/Environment.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import mkdirp from 'mkdirp'
99
import * as pty from 'node-pty'
1010
// @ts-ignore
1111
import spawn from 'await-spawn'
12+
import tmp from 'tmp'
1213
import yaml from 'js-yaml'
1314

1415
import * as nix from './nix'
@@ -341,13 +342,31 @@ export default class Environment {
341342
*/
342343
async enter (command: string = '', pure: boolean = true) {
343344
const shellName = os.platform() === 'win32' ? 'powershell.exe' : 'bash'
344-
const shellArgs = ['--noprofile', '--norc']
345+
const shellArgs = ['--noprofile']
345346

347+
// Path to the shell executable. We need to do this
348+
// because the environment may not actually have any shell
349+
// in it, in which case, when using `pure` a shell won't be available.
346350
let shellPath = await spawn('which', [shellName])
347351
shellPath = shellPath.toString().trim()
352+
353+
// Inject Nixster into the environment as an alias so we can use it
354+
// there without polluting the environment with additional binaries.
355+
// During development you'll need to use ---pure=false so that
356+
// node is available to run Nixster. In production, when a user
357+
// has installed a binary, this shouldn't be necessary
358+
let nixsterPath = await spawn('which', ['nixster'])
359+
const tempRcFile = tmp.fileSync()
360+
fs.writeFileSync(tempRcFile.name, `alias nixster="${nixsterPath.toString().trim()}"\n`)
361+
shellArgs.push('--rcfile', tempRcFile.name)
348362

363+
// Environment variables
349364
let vars = await this.vars(pure)
350365
vars = Object.assign(vars, {
366+
// Let Nixster know which environment we're in.
367+
NIXSTER_ENV: this.name,
368+
// Customise the bash prompt so that the user know that they are in
369+
// a Nixster environment and which one.
351370
PS1: '☆ ' + chalk.green.bold(this.name) + ':' + chalk.blue('\\w') + '$ '
352371
})
353372

src/cli.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ yargs
9191
type: 'array'
9292
})
9393
.option('removes', {
94-
describe: 'Remove packages from environment',
94+
describe: 'Remove packages to environment',
9595
alias: 'r',
9696
type: 'array'
9797
})
@@ -430,7 +430,7 @@ function output (value: any, argv: any = {}, prettifier?: (value: any) => string
430430
* Add output options to a command.
431431
*
432432
* The aim of this approach is to have a consistent
433-
* and convenient way for users to be able to specify
433+
* and convieient way for users to be able to specify
434434
* the output format across commands.
435435
*
436436
* Formats can be specified explicitly e.g.
@@ -483,7 +483,7 @@ function outputOptions (yargs: any) {
483483
* Create a diagnostic message for the user
484484
*
485485
* @param message Message to display
486-
* @param emoji Emoji to prefix the display
486+
* @param emoji Emjoi to prefix the display
487487
*/
488488
function diag (message: string, emoji: string) {
489489
if (process.stderr.isTTY && emoji) process.stderr.write(emoji + ' ')

0 commit comments

Comments
 (0)