Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a configuration setting for a PATH prefix #98

Closed
wants to merge 3 commits into from

Conversation

erran
Copy link
Collaborator

@erran erran commented Apr 13, 2014

Related to #5, #75, and #93. Adds ability to "shim" the path by prepending a configuration setting if available. Essentially adds a package specific for users to configure their PATHs for this plugin only. It could be extended to pull in other env related parts though.

Configuration:
configuration

Running Ruby with and without a path prefix:
path_shim

@erran erran mentioned this pull request Apr 13, 2014
@awmartin
Copy link

Plus one to this pull request.

# Prepend the user defined path
path_prefix = atom.config.get('script.path_prefix')
if path_prefix
process.env.PATH = [path_prefix, process.env.PATH].join(':')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a built in that makes sure to pick the right separator for the OS in use?

I've been noticing more and more Win32 related items in Atom internals, so we should be prepped for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to prepend path_prefix to process.env.PATH every single time run executes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform specific delimiter is path.delimiter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to prepend path_prefix to process.env.PATH every single time run executes.

I'll look into changing this when I have a minute to site and hack away at this.

The platform specific delimiter is path.delimiter.

I didn't think to look into using a path delimiter vs. :. Assuming *nix is bad though. 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.delimiter is a bit of a misnomer, as it means the delimiter for the environment variable for path not the directory delimiter. 😅

It will use : on *.nix and ; on Windows.

@rgbkrk
Copy link
Member

rgbkrk commented Apr 16, 2014

I'm currently a bigger fan of setting your $PATH by opening Atom from the command line or using the init script to add to the path explicitly.

I don't like the idea of putting in side effects that would affect other modules.

@erran
Copy link
Collaborator Author

erran commented Apr 17, 2014

@rgbkrk The reason I opted for this approach is that the init script will set it for all atom package configurations vs. scoping it to modules in atom-script.

I thought on this last night and think the best solution have a field in the config.cson that mapped to a settings item on the main settings page. As far as I know that's not (yet) possible though.

@erran
Copy link
Collaborator Author

erran commented Apr 17, 2014

💩 I just realized what you were saying, process.env.PATH would implicitly affect other modules as well. 👎 Closing until there's a better solution. The init script route is definitely the best way right now though.

@erran erran closed this Apr 17, 2014
@erran
Copy link
Collaborator Author

erran commented Apr 17, 2014

This definitely is something that doesn't belong in atom-script. Regardless, below are a few immediate findings.

Turns out if you add a key under editor/core the main settings page will register that on window reload (or closing and restarting atom):

# ~/.atom/config.cson
'core':
  'PATH': '/Users/ecarey/.rbenv/shims:/usr/local/share/npm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin'
  ...
  'projectHome': '/Users/ecarey/repositories'

screen shot 2014-04-17 at 09 12 57

# ~/.atom/init.coffee
path = atom.config.get('core.PATH')
if path
  process.env.PATH = path

A few possible difficulties with this method:

  • Reloading windows, how would that work?
  • How does this affect launching from the command line?
  • Should we use a PATH_PREFIX instead and prepend it on init?

@erran erran deleted the configuration branch April 17, 2014 14:24
@rgbkrk
Copy link
Member

rgbkrk commented Apr 17, 2014

I like this core approach. Maybe bring it up on the Atom forums and the core devs will pitch in?

This is affecting so many packages.

@ioquatix
Copy link

I don't really know if this is helpful but I ended up working around this issue in one of my packages by grabbing all environment variables from the login shell, something a bit like this ended up in the final code:

https://github.com/ioquatix/script-runner/blob/master/examples/environment.coffee

It's interesting to consider whether or not there should be any way to customize this or not. In my package, I do this every time I need to run a script, so that if the user changes anything (e.g. rvm) they'd get the updated settings.

@allenkonstanz
Copy link

Mac OS X 10.10.3 solution.

I work around this issue this way:

1- open file .atom/init.coffee and add the code :

fs = require('fs')

#Import ENV from zsh config.
fs.readFile process.env.HOME+"/.zshrc", "utf8", (err, zshFile) ->
  envPaths = []
  for l in zshFile.split('\n')
    if l.substring(0,11) is 'export PATH'
      e = l.split('=').splice(-1)[0]
      e = e.replace(':$PATH','').replace(/"/g,'')
      if ':' in e
        for x in e.split(':')
          envPaths.push(x)
      else
        envPaths.push(e)
  process.env.PATH = envPaths.join(':')

2- open the file .zshrc and add the code (with the path of your groovy/grails included[that's was the case for me adapt to your needs]):

export PATH=$PATH:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin/grails/bin:/usr/local/bin/groovy/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

3- DONE! Now you don't need to open Atom through the terminal to execute atom-script, you can open atom normally now.

@rgbkrk
Copy link
Member

rgbkrk commented Jul 2, 2015

@ioquatix That's pretty neat! Would this correctly pick up any new virtualenvs? It seems like it's only picking up the currently defined variables.

@ioquatix
Copy link

ioquatix commented Jul 3, 2015

@rgbkrk It should do. The functionality was extracted into a npm module: https://www.npmjs.com/package/shell-environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants