Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Respect ATOM_HOME env var for portability #5385

Merged
merged 20 commits into from Feb 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apm/package.json
Expand Up @@ -6,6 +6,6 @@
"url": "https://github.com/atom/atom.git"
},
"dependencies": {
"atom-package-manager": "0.134.0"
"atom-package-manager": "0.135.0"
}
}
8 changes: 4 additions & 4 deletions atom.sh
Expand Up @@ -75,9 +75,9 @@ elif [ $OS == 'Linux' ]; then
SCRIPT=$(readlink -f "$0")
USR_DIRECTORY=$(readlink -f $(dirname $SCRIPT)/..)
ATOM_PATH="$USR_DIRECTORY/share/atom/atom"
DOT_ATOM_DIR="$HOME/.atom"
ATOM_HOME="${ATOM_HOME:-$HOME/.atom}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't path.sep be used instead of / here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, but does it matter in an .sh file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, you're right - I spaced on the fact this is a shell script.


mkdir -p "$DOT_ATOM_DIR"
mkdir -p "$ATOM_HOME"

: ${TMPDIR:=/tmp}

Expand All @@ -88,9 +88,9 @@ elif [ $OS == 'Linux' ]; then
exit $?
else
(
nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$DOT_ATOM_DIR/nohup.out" 2>&1
nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1
if [ $? -ne 0 ]; then
cat "$DOT_ATOM_DIR/nohup.out"
cat "$ATOM_HOME/nohup.out"
exit $?
fi
) &
Expand Down
8 changes: 8 additions & 0 deletions docs/customizing-atom.md
Expand Up @@ -100,6 +100,14 @@ namespaces: `core` and `editor`.

You can open this file in an editor from the _Atom > Open Your Config_ menu.

### Custom Configuration Location

You can override the location that Atom stores configuration files and folders
in by setting the `ATOM_HOME` environment variable. The `ATOM_HOME` path will be
used instead of `~/.atom` when it is set.

This option can be useful when you want to make Atom portable across machines.

### Configuration Key Reference

- `core`
Expand Down
2 changes: 1 addition & 1 deletion src/6to5.coffee
Expand Up @@ -96,7 +96,7 @@ getCachePath = (sourceCode) ->

unless jsCacheDir?
to5Version = require('6to5-core/package.json').version
cacheDir = path.join(fs.absolute('~/.atom'), 'compile-cache')
cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache')
jsCacheDir = path.join(cacheDir, 'js', '6to5', create6to5VersionAndOptionsDigest(to5Version, defaultOptions))

path.join(jsCacheDir, "#{digest}.js")
Expand Down
5 changes: 1 addition & 4 deletions src/atom.coffee
Expand Up @@ -109,7 +109,7 @@ class Atom extends Model
#
# Returns the absolute path to ~/.atom
@getConfigDirPath: ->
@configDirPath ?= fs.absolute('~/.atom')
@configDirPath ?= process.env.ATOM_HOME

# Get the path to Atom's storage directory.
#
Expand Down Expand Up @@ -263,9 +263,6 @@ class Atom extends Model
# Make react.js faster
process.env.NODE_ENV ?= 'production' unless devMode

# Set Atom's home so packages don't have to guess it
process.env.ATOM_HOME = configDirPath

@config = new Config({configDirPath, resourcePath})
@keymaps = new KeymapManager({configDirPath, resourcePath})
@keymap = @keymaps # Deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/browser/atom-application.coffee
Expand Up @@ -416,7 +416,7 @@ class AtomApplication
PackageManager = require '../package-manager'
fs = require 'fs-plus'
@packages = new PackageManager
configDirPath: fs.absolute('~/.atom')
configDirPath: process.env.ATOM_HOME
devMode: devMode
resourcePath: @resourcePath

Expand Down
21 changes: 19 additions & 2 deletions src/browser/main.coffee
Expand Up @@ -14,6 +14,7 @@ process.on 'uncaughtException', (error={}) ->
nslog(error.stack) if error.stack?

start = ->
setupAtomHome()
if process.platform is 'win32'
SquirrelUpdate = require './squirrel-update'
squirrelCommand = process.argv[1]
Expand Down Expand Up @@ -73,6 +74,18 @@ setupCoffeeScript = ->
js = CoffeeScript.compile(coffee, filename: filePath)
module._compile(js, filePath)

setupAtomHome = ->
return if process.env.ATOM_HOME

if process.platform is 'win32'
home = process.env.USERPROFILE
else
home = process.env.HOME
atomHome = path.join(home, '.atom')
try
atomHome = fs.realpathSync(atomHome)
process.env.ATOM_HOME = atomHome

parseCommandLine = ->
version = app.getVersion()
options = optimist(process.argv[1..])
Expand All @@ -89,8 +102,12 @@ parseCommandLine = ->
opened or a new window if it hasn't.

Environment Variables:
ATOM_DEV_RESOURCE_PATH The path from which Atom loads source code in dev mode.
Defaults to `~/github/atom`.

ATOM_DEV_RESOURCE_PATH The path from which Atom loads source code in dev mode.
Defaults to `~/github/atom`.

ATOM_HOME The root path for all configuration files and folders.
Defaults to `~/.atom`.
"""
options.alias('d', 'dev').boolean('d').describe('d', 'Run in development mode.')
options.alias('f', 'foreground').boolean('f').describe('f', 'Keep the browser process in the foreground.')
Expand Down
2 changes: 1 addition & 1 deletion src/coffee-cache.coffee
Expand Up @@ -5,7 +5,7 @@ CoffeeScript = require 'coffee-script'
CSON = require 'season'
fs = require 'fs-plus'

cacheDir = path.join(fs.absolute('~/.atom'), 'compile-cache')
cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache')

stats =
hits: 0
Expand Down
8 changes: 1 addition & 7 deletions src/less-compile-cache.coffee
@@ -1,14 +1,10 @@
path = require 'path'
fs = require 'fs-plus'
LessCache = require 'less-cache'
{Subscriber} = require 'emissary'

# {LessCache} wrapper used by {ThemeManager} to read stylesheets.
module.exports =
class LessCompileCache
Subscriber.includeInto(this)

@cacheDir: path.join(require('./coffee-cache').cacheDir, 'less')
@cacheDir: path.join(process.env.ATOM_HOME, 'compile-cache', 'less')

constructor: ({resourcePath, importPaths}) ->
@lessSearchPaths = [
Expand All @@ -35,5 +31,3 @@ class LessCompileCache

cssForFile: (stylesheetPath, lessContent) ->
@cache.cssForFile(stylesheetPath, lessContent)

destroy: -> @unsubscribe()