Giter VIP home page Giter VIP logo

fix-path's Introduction

fix-path

Fix the $PATH on macOS and Linux when run from a GUI app

Useful for Electron apps as GUI apps on macOS and Linux do not inherit the $PATH defined in your dotfiles (.bashrc/.bash_profile/.zshrc/etc).

Install

$ npm install fix-path

Usage

import fixPath from 'fix-path';

console.log(process.env.PATH);
//=> '/usr/bin'

fixPath();

console.log(process.env.PATH);
//=> '/usr/local/bin:/usr/bin'

Related

fix-path's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fix-path's Issues

ANSI codes appear in process.env.PATH after fix-path

I am using this in my vscode-yo plugin and noticed something strange. I upgraded some dotfiles of today and since then, the plugin wasn't showing any generators anymore. After investigating this, ANSI color codes where added in front of the path.

console.log(process.env.PATH.split(path.delimiter));
//=> [ '/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]

require('fix-path')();

console.log(process.env.PATH.split(path.delimiter));
//=> [ '\u001b(B\u001b[m/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]

After some more investigation, it seems that these lines in my dot-files trigger this behaviour.

if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
    export TERM='gnome-256color';
elif infocmp xterm-256color >/dev/null 2>&1; then
    export TERM='xterm-256color';
fi;

If I remove these lines, the ANSI code is not added.

Fix

A simple fix is strip-ansi

require('fix-path')();

console.log(stripAnsi(process.env.PATH).split(path.delimiter));
//=> [ '/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]

But maybe, this should be fixed somewhere deeper in the chain. After digging into with fix-path does, I came to this line 72 in shell-path/index.js. This is the line that returns the path with the ANSI color codes.

Module not found: Can't resolve 'node:os'

fix-path: 4.0.0
electron: 13.2.3
@craco/craco: 6.2.0

Hello, any idea what i'm doing wrong? My app fails to compile after add this package as a dep.

[0] Failed to compile.
[0] 
[0] ./node_modules/default-shell/index.js
[0] Module not found: Can't resolve 'node:os' in '[...]/node_modules/default-shell'

ES Module import error

Environment: Node v14

There is an import error after upgrading to v4.

ERROR: : Must use import to load ES Module.

Screenshot is also attached for reference:
image

No effect in PATH?

fix-path: v2.0.0
Electron: v1.1.1
Node: v6.2.0
System: Yosemite 10.10.5

code:

const fixPath = require('fix-path');
console.log('PATH before fix:');
console.log(process.env.PATH);
fixPath();
console.log('PATH after fix:');
console.log(process.env.PATH);

logs:

PATH before fix:
/usr/bin:/bin:/usr/sbin:/sbin
PATH after fix:
/usr/bin:/bin:/usr/sbin:/sbin

Get $PATH from the real shell

Just an idea:

var exec = require("child_process").execSync;
var userShell = String(exec("/bin/sh -c 'echo $SHELL'")).trim();
process.env.PATH = String(exec(userShell +" -c 'echo $PATH'")).trim();

This should work at least with bash and zsh and possibly other shells that take a -c argument.

Must use import to load ES Module

Any way to use this with require instead of import?
I tried using multiple variations of require('fix-path') but it won't work.
I'm unable to use import statement outside a module as it breaks all of my require related pieces.

Thank you!

Unexpected token error

I got unexpected token error in fix-path code.

This is the content of fix-path:

'use strict';
module.exports = () => {
    const env = process.env;

    if (process.platform === 'darwin') {
        return env.SHELL || '/bin/bash';
    }

    if (process.platform === 'win32') {
        return env.COMSPEC || 'cmd.exe';
    }

    return env.SHELL || '/bin/sh';
}();

When I removed last () , it didn't give invalid syntax error.

What could be wrong?

I installed nodejs via brew
$ node --version v5.10.1

Ubuntu Linux Also ?

Hi

This module has been great for our application - many thanks !

We've now got to build a Linux (Ubuntu) version and we're getting a similar path problem. I tried fix-path but it doesn't seem to work on Linux. Are there any plans to extend it out to Linux ?

Thanks

Ian

Path not being fixed

> echo $PATH
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/sbin:/Users/dave/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/deployd/bin:/usr/local/go/bin:/usr/local/MacGPG2/bin

Using Electron 0.30.2:

require('fix-path')()
var dialog = require('dialog')

dialog.showErrorBox("path", process.env.PATH)

screen shot 2015-07-31 at 18 50 39

It works fine on my Macbook Pro but fails to list all the paths on my Macbook Air (as shown above). They are both running Yosemite. I have also reproduced the same issue on a friends Macbook.

Any idea what could be going on here?

Webpack warning: Module not found: Error: Can't resolve 'spawn-sync'

WARNING in ./node_modules/shell-env/node_modules/cross-spawn/index.js 30:20-41
Module not found: Error: Can't resolve 'spawn-sync' in '/Volumes/Projects/record/app/node_modules/shell-env/node_modules/cross-spawn'
 @ ./node_modules/shell-env/node_modules/execa/index.js 7:19-41
 @ ./node_modules/shell-env/index.js 3:14-30
 @ ./node_modules/shell-path/index.js 3:17-37
 @ ./node_modules/fix-path/index.js 3:18-39
 @ ./app/main.dev.js 6:0-31 33:2-9

I think it may be the same issue as sindresorhus/shell-env#12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.