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?
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.
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)
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. apm
is the command line package manager.
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'
On macOS you can add it to your ~/.bash_profile
as
alias atom='open -a "Atom"'
and from terminal just call
atom filename.whatever
Open the application by name:
open -a 'Atom' FILENAME
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
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
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 ."
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:
- Open your ~/.profile using your choice of editor (in my case
$ emacs ~/.kshrc
) - Add this line:
export PATH="/usr/local/bin:${PATH}"
- Save and exit
- Restart terminal or
source ~/.profile
- Test
$ atom -h
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.
- Move "Atom X" from Documents into Applications (why it ended up in here, I have no idea)
- Rename "Atom X" to "Atom"
- 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.
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.
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
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
I am on mingw bash, so I have created ~.profile file with following: alias atom='~/AppData/Local/atom/bin/atom'
来源:https://stackoverflow.com/questions/22390709/how-to-open-atom-editor-from-command-line-in-os-x