From 0 to Terminal for Ember development
Facing the terminal for the first time can be overwhelming. You’re confronted with a solid colored window that doesn’t say much. Its cursor flashes desperately, asking you, “What are you waiting for? Do something useful!”. I know, it can be scary, but the Terminal has a beautiful soul ready to help you. In this article we’ll explore some tips that could help transform the Terminal experience from creepy to productive.
Note: Even if you’re a pro, you might find something useful in the last section of this article. Our friends shared some cool aliases that they use for Ember development, so scroll down.
Disclaimer: I’m not an expert on these topics, so there might be betters ways. If you have more tips or suggestions I should follow, please tell me! I’ve also marked notes (😬) about things that I do every day that might not be right for everyone but that have worked for me.
😬 I’m using OSX.
1. Use iTerm
Or just any other terminal emulator. These provide a lot of versatility and gives you more control over your windows. iTerm also introduces the concept of sessions, that hold a state of your tab/window which you can modify, store and recover. It is especially useful when the number of tasks you have to perform starts growing. You can also have panes within a single window, to keep things visible and arranged.
😬 Typically, I use two panes when I’m working on an Ember project: one with ember server running, and another one in which I use Ember generators and git things.
2. Oh my Zsh
Installing “Oh My Zsh” into your terminal will give you a bunch of helpful configurations and utilities. Remarkably, we get super handy git tracking that makes working with branches easier. There are other zsh frameworks that you may want to check out.
You can easily tell it’s much faster to understand what’s going on using Oh My Zsh compared to plain, default, bash.
3. Make iTerm open tabs in the same directory
Let’s say you’re working on a tab with your
ember server running but you want to run another Ember command. You probably want to open a tab and have the same working directory on that tab. By default, it’s going to open the new tab in your root directory. But you can tell it to do it as you want by changing the following setting under Preferences:
4. Super basic commands
So here’s the list of all the commands that I can actually remember:
Changes the current directory to the specified path.
Lists the files and folders of the specified path. If no path is passed, it lists the files and folders of the current directory.
😬 Drag and drop a file or folders from Finder into the terminal window to get its path.
5. Git Essentials
When you create an ember project using Ember CLI, you’ll notice that, by default, it initializes a git repository for you. A repository helps keep track of the changes made to a project, making collaboration and mistake-solving simpler. Github and Atlassian have some more info. Below are some essential git commands:
This command will output the info you need to know what’s going on with your repo at the moment. You’ll see which files are staged, which ones are modified, the branch in which you are and whether it’s up to date. You can also notice if you’re in the middle of a git process.
git add <file path>
This will stage the file that you indicate, so it’ll be saved on your next commit. If you’re confident that your changes on all the files are correct, you can also run git add -A (this will stage all modified files).
git commit -m “<message here>”
After you run this command, the state of the files you had staged will be saved to the repo.
6. Make Atom (or any text editor) your default Git editor
The time will come when you’ll have to edit git messages and tell git what you want by editing text files. By default, git will trigger vim—a console based text editor—but it’s probably not very friendly if you’re not familiar with it. So you can change it by running the following command [in Atom’s case]:
git config --global core.editor "atom --wait"
Of course, you need to have Atom installed. Github tells us how to setup things for other editors.
6. Handy Shortcuts
In terminal you can create aliases for commands you frequently use so they are easy to remember or just shorter to use. Some people from the community shared some of their aliases, and they are great.
First: A brief intro to aliases
If you just input an alias description in the terminal, it will be available for the current session only. When you open up the terminal again it will be gone. To avoid that, you can store the alias in the terminal configuration file. If you’re using ZSH as suggested here, run atom ~/.zshrc (you can replace atom for your editor’s command). Once there, append the aliases descriptions, save the file and close the editor. Voilá, aliases will be persistent now.
Marten Schilstra shared how he shortcuts ember server and ember test server:
To register these aliases you use the following descriptions:
alias es="ember server"
alias ets="ember test — server — no-launch"
Esteban Arango Medina showed us a super handy way to clear the cache for npm and bower, remove temporary directories from an ember project and re-installing npm and bower dependencies by just running:
To register this alias use:
alias ember-clean="npm cache clean && bower cache clean && rm -rf node_modules bower_components dist tmp && npm install && bower install"
ember t -s -f “my module”
You can also use the URL bar in chrome to filter with
&filter=my module. This is especially useful when you have many tests, running them all could take quite a while.
There’s much more to explore!
Terminal has a lot to offer. It’s all about getting used to the command line. After some days you’ll realize how you’re getting tasks done faster. In this article we’ve just reviewed some basic elements to help you boost your Terminal experience.
Big thanks to Alex LaFroscia for his help on this article!