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

2019-01-16 00:16发布

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?

17条回答
Luminary・发光体
2楼-- · 2019-01-16 00:25

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)

enter image description here

查看更多
做个烂人
3楼-- · 2019-01-16 00:25

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'

查看更多
Viruses.
4楼-- · 2019-01-16 00:28

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.

查看更多
萌系小妹纸
5楼-- · 2019-01-16 00:31

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
查看更多
贼婆χ
6楼-- · 2019-01-16 00:31

Make sure to put (move) the atom into Application directory.enter image description here

查看更多
来,给爷笑一个
7楼-- · 2019-01-16 00:35

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

as

alias atom='open -a "Atom"'

and from terminal just call

atom filename.whatever

查看更多
登录 后发表回答