Here are a few quick things to make working in Mac’s Terminal with Rails and Git a little better:
Some of these things involve downloading some stuff and then updating the .bash_profile or .bashrc. To open those, in terminal type:
open ~/.bashrc or
Aliases are shortcuts for things commonly typed into terminal: instead of
rails console, just use
rc and instead of
git push origin master, just
gpom. It’s nice to avoid typing the same things over and over again, especially if it’s easy to make a typo.
olm are two of my particular favorites.
No Homebrew needed here. Just setup aliases like these in .bashrc:
Ensure .bashrc is referenced in .bash_profile. At or near the top of .bash_profile include this line:
source ~/.bashrc # get my Bash aliases. Also, .bashrc is really picky about formatting, the alias needs to touch the equals sign which needs to touch the opening double quote.
Once this is updated, start a new terminal session or use
source ~/.bash_profile in the current session to make the new aliases available.
Quick jump between folders is a game-changer. From within one app, navigate directly to another non-linear folder or even another app without changing directory up and down multiple levels!
First, use Homebrew to install bash completion:
brew install bash-completion
Add the following code to .bash_profile:
And then in .bashrc:
In this example, PROJ_DIR will be the main folder (it could be anything). Then specify the subfolders, whatever those are. Restart terminal, and cd between app projects without navigating up and down directories one at a time. Folders within the sub folders will be available to quick jump to as well.
Display Git Branch
It’s nice to see which branch we’re working on. To display the current git branch in terminal, place this code in .bash_profile:
Git Tab Completion
Just like terminal will try to auto-compelete folder and file names with tab, we can add the same thing for git branch names. Just type the first few letters of a branch name and tab to complete it!
Install git-completion via curl command:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
Then add the following to .bashrc:
Restart terminal or re-source the .bash_profile. Not only does this work with regular typed out git commands, but it will work with aliases as well.