Skip to content

Instantly share code, notes, and snippets.

@sleepingkingstudios
Last active August 21, 2020 20:37
Show Gist options
  • Save sleepingkingstudios/53ba2d971650ac06ec84 to your computer and use it in GitHub Desktop.
Save sleepingkingstudios/53ba2d971650ac06ec84 to your computer and use it in GitHub Desktop.
Developing For Ruby and Rails
export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"
export PGDATA="/usr/local/var/postgres"
eval "$(rbenv init - zsh)"
alias ci="bundle exec rspec && bundle exec rubocop"
alias be="bundle exec"
alias bea="bundle exec appraisal"
alias loki="bundle exec thor"
alias osd="OVERMIND_PROCFILE=Procfile.dev overmind start"
alias git-delete-merged="git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d"
alias git-list-branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
alias kubrick="yes \"All work and no play makes Jack a dull boy.\""
alias mongod="mongod --config /usr/local/etc/mongod.conf"
alias rubocop-diff="git diff --name-only HEAD..master | grep -E \".erb|.haml|.rake|.rb\" | xargs bash -c 'for filename in \$*; do [ -e \"\$filename\" ] && echo \"\$filename\"; done' bash | xargs bash -c 'bundle exec rubocop \$*' bash"

Getting Started on OSX

Step By Step

Install XCode Developer Tools

Available from Apple.

Install Homebrew

Install Homebrew. See page for installation command/options, then run brew doctor.

Install Git

brew install git

Configure Git

Set your username and email.

git config --global user.name "Alan Bradley"
git config --global user.email "alan.bradley@example.com"

Set up a global .gitignore file in the user directory, and set some default ignored files.

git config --global core.excludesfile '~/.gitignore'

echo '.DS_Store' >> ~/.gitignore

Install and configure DiffMerge as the git merge tool.

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true

Prevent git from saving .orig backup files during merges.

git config --global mergetool.keepBackup false

Generate SSH key pair (see https://help.github.com/articles/connecting-to-github-with-ssh/).

Set Up Multiple Git Users

Need to set up multiple Git users (personal and company, etc)? Use aliases.

Generate separate SSH keys (see above) for each Git user, and add the relevant SSH keys to the GitHub accounts. You can test that each key is configured for the desired account by running:

ssh -T git@github.com -i ~/.ssh/incom_rsa

To use a different SSH key for a single command, use the GIT_SSH_COMMAND env variable. The -i option sets the desired SSH identity file, and -F tells it to ignore the git config (which might override the specified identity file). For example, to clone a repository using a desired key:

GIT_SSH_COMMAND="ssh -i ~/.ssh/incom_rsa -F /dev/null" git clone git@github.com:incom/example_repo.git

Finally, create aliases in your ~.bash-profile:

git-incom = "GIT_SSH_COMMAND='ssh -i ~/.ssh/incom_rsa -F /dev/null' git"
ssh-incom = "ssh -i ~/.ssh/incom_rsa"

Once you have created/cloned a repository, you can configure it to always use the alternate SSH key via the git config:

[core]
  sshCommand = ssh -i ~/.ssh/incom_rsa

Configure Bash

Add the following to .bash_profile:

Ensure configuration from .bashrc is included in the Terminal.

[ -r ~/.bashrc ] && . ~/.bashrc

List git branches by commit date, author, and last commit.

alias git-list-branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"

Delete all branches that have been merged into master.

alias git-delete-merged="git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d"

Print working directory and current git branch in bash cursor.

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

PS1='\n\[\033[32m\][\h \w]\[\033[00m\]$(parse_git_branch)\nbash> '

Install Homebrew Dependencies

Install dependencies below as needed.

Install MongoDB

brew tap mongodb/brew
brew install mongodb-community

Set the default database path in .bash_profile:

alias mongod="mongod --config /usr/local/etc/mongod.conf"

Install PostgreSQL

Install Postgres Mac App or via Homebrew:

brew install postgres

# Set the default database path in `.bash_profile`:
export PGDATA="/usr/local/var/postgres"

Install Redis

brew install redis

Install Ruby

Install RVM or rbenv. See page for installation command/options.

Other Software

Install the Heroku toolbelt.

Install SublimeText and add the PATH to the command line tool (in .bash_profile):

export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"

(Optional) Install Node.js

Install nvm. See page for installation command/options.

Install a Node.js runtime and set as default for new shells:

nvm alias default stable

Software

  • Apple Developer Tools home page

    Developer tools for macOS, including the XCode command line tools.

  • DiffMerge home page

    Visual merge tool software for Git.

  • Heroku Toolbelt home page

    Everything you need to get started using heroku.

  • Homebrew home page

    The missing package manager for OS X.

  • nvm GitHub

    Manage Node.js versions.

  • Postgres home page

    Native macOS application and command line tools for running Postgres.

  • rbenv Github

    Lightweight alternative to RVM.

  • RVM home page

    Manage ruby versions and gem sets.

  • SublimeText homepage

    Graphical text editor.

  • Yarn homepage

    JavaScript package manager.

// Settings in here override those in "Default/Preferences.sublime-settings",
// and are overridden in turn by syntax-specific settings.
{
"font_face": "Source Code Pro",
"font_size": 14,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"rulers": [79],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment