How to open Atom editor from command line in OS X?

2019-01-16 00:27发布

问题:

I have the Atom editor and was wondering how you can open a file or folder from the terminal in Atom. I am using a Mac. I am looking for a way to do this:

atom . (opens folder)

atom file.js (opens file)

atom (opens editor)

Is this possible and how do I set it up?

回答1:

When Atom installs it automatically creates a symlink in your /usr/local/bin. However in case it hasn't, you can create it yourself on your Mac

ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom

Now you can use atom folder_name to open a folder and atom file_name to open a file. Hope this helps.



回答2:

With the Atom editor open, in the menu bar:

Click Atom >> Install Shell Commands

You should expect to see:

Potentially restart your terminal. (I did just out of habit, not sure if you need to)



回答3:

For Windows 7 x64 with default Atom installation add this to your PATH

%USERPROFILE%\AppData\Local\atom\app-1.4.0\resources\cli

and restart any running consoles

(if you don't find Atom there - right-click Atom icon and navigate to Target)



回答4:

Roll your own with @Clockworks solution, or in Atom, choose the menu option Atom > Install Shell Commands. This creates two symlinks in /usr/local/bin

apm -> /Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/apm
atom -> /Applications/Atom.app/Contents/Resources/app/atom.sh

The atom command lets you do exactly what you're asking. apmis the command line package manager.



回答5:

The symlink solution for this stopped working for me in zsh today. I ended up creating an alias in my .zshrc file instead:

alias atom='sh /Applications/Atom.app/Contents/Resources/app/atom.sh'



回答6:

Open the application by name:

open -a 'Atom' FILENAME


回答7:

For Windows10 and new release of atom i solved the problem by adding in my ENV VARIABLE on the "PATH" row

%USERPROFILE%\AppData\Local\atom\bin


回答8:

In addition to @sbedulin (Greeting, lovely Windows users!)

The general path on Windows should be

%USERPROFILE%\AppData\Local\atom\bin

If you are using a bash emulator like babun. You'd better checkout the shell files, which only available in the real app folders

/c/User/<username>/AppData/Local/atom/app-<version>/resources/cli/apm.sh # or atom.sh


回答9:

Iv'e noticed this recently with all new macs here at my office. Atom will be installed via an image for the developers but we found the Atom is never in the Application folder.

When doing a ls on the /usr/local/bin folder the path for atom will show something like "/private/var/folders/cs" . To resolve this, we just located atom.app and copied it into the application folder, then ran the system link commands provided by nwinkler which resoled the issue. Developers can now open atom from the command line with "atom" or open the current projects from their working director with "atom ."



回答10:

Another simple solution is to add /usr/local/bin to your PATH. I had the same issue, I installed shell commands (see shaheenery's response) the symlinks already existed and pointing to the correct destination (see thomax's response), however I would still get 'not found'. I'm using Korn Shell btw.

Here's what I did:

  1. Open your ~/.profile using your choice of editor (in my case $ emacs ~/.kshrc)
  2. Add this line: export PATH="/usr/local/bin:${PATH}"
  3. Save and exit
  4. Restart terminal or source ~/.profile
  5. Test $ atom -h


回答11:

Upgrading Atom appears to break command line functionality on the occasion. Looks like in my case it created two versions of the application instead of overwriting them. Occurs because the new file structure doesn't match file paths created by "Atom -> Install Shell Commands". In order fix the issue you'll need to do the following.

  1. Move "Atom X" from Documents into Applications (why it ended up in here, I have no idea)
  2. Rename "Atom X" to "Atom"
  3. Might need to restart your terminal and Atom

After that everything should work just like it did before. Hopefully this saves someone 30 minutes of poking around.



回答12:

On macOS you can add it to your ~/.bash_profile

as

alias atom='open -a "Atom"'

and from terminal just call

atom filename.whatever



回答13:

Make sure to put (move) the atom into Application directory.



回答14:

add path(:/usr/local/bin/) in profile.

mac: $home/.bash_profile

export PATH=$GOPATH/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:$PATH



回答15:

I am on mingw bash, so I have created ~.profile file with following: alias atom='~/AppData/Local/atom/bin/atom'



回答16:

With conemu on windows 10 I couldn't call atom from console even after I added %USERPROFILE%\AppData\Local\atom\bin to PATH in environment variables. I just added

alias atom="C:/Users/me/AppData/local/atom/app-1.12.7/atom"

to my .bashrc file.



回答17:

I had problems due to atom being unable to write its logfile when starting from the commandline. This cured it.

sudo chmod 777 ~/.atom/nohup.out