Last active
December 28, 2015 23:19
-
-
Save huebs/7578032 to your computer and use it in GitHub Desktop.
The bash .profile I use for OS X development. Some commands require Homebrew, Node.js, and/or Heroku Toolbelt. Should only be used as an example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
## | |
## Title: Mac OS X Bash Profile | |
## Description: The bash .profile I use for OS X development. Some commands | |
## require Homebrew and Node. Should only be used as an example. | |
## Revison: 23 | |
## Last Updated: Thursday, February 12, 2015 | |
## Author: Ben Huebscher <ben@hubtech.tv> | |
## | |
############################################ | |
### GET PHP ROOT DIRECTORY FROM HOMEBREW ### | |
############################################ | |
PHP_ROOT=$(brew --prefix homebrew/php/php55) | |
###################################### | |
### DEFINE DEFAULT EXECUTABLE PATH ### | |
###################################### | |
# Prepend Local Binaries | |
if [ -d /usr/local/sbin ]; then | |
PATH="/usr/local/sbin:$PATH" | |
fi | |
if [ -d /usr/local/bin ]; then | |
PATH="/usr/local/bin:$PATH" | |
fi | |
# Append User Binaries | |
if [ -d "$HOME/.bin" ]; then | |
PATH="$PATH:$HOME/.bin" | |
fi | |
if [ -d "$HOME/bin" ]; then | |
PATH="$PATH:$HOME/bin" | |
fi | |
# Append PHP Binaries | |
if [ -d "$PHP_ROOT/bin" ]; then | |
PATH="$PATH:$PHP_ROOT/bin" | |
fi | |
# Append Node's Binaries | |
if [ -d /usr/local/share/npm/bin ]; then | |
PATH="$PATH:/usr/local/share/npm/bin" | |
fi | |
# Append RVM's Binaries | |
if [ -d "$HOME/.rvm/bin" ]; then | |
PATH="$PATH:$HOME/.rvm/bin" | |
# Load RVM into the shell session *as a function* | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" | |
fi | |
export PATH | |
################################### | |
### DEFINE DEFAULT TEXT EDITORS ### | |
################################### | |
if [ -x `which mate` ]; then | |
export EDITOR="`which mate` -w" | |
export GIT_EDITOR="`which mate` --name 'Git Commit Message' -w -l 1" | |
fi | |
######################################################### | |
### CONFIGURE DEFAULT HOMEBREW CASK INSTALL DIRECTORY ### | |
######################################################### | |
export HOMEBREW_CASK_OPTS="--appdir=/Applications" | |
###################### | |
### PROMPT STYLING ### | |
###################### | |
# Set Default Prompt | |
export PS1=">: " | |
# Command for changing prompt style | |
function prompt () { | |
local option="${1}" | |
case ${option} in | |
1) export PS1="\e[0;37m>: \e[0m" | |
;; | |
2) export PS1="\e[0;37m\w/\e[0m\e[0;31m > \e[0m" | |
;; | |
3) export PS1="\e[0;37m\W\e[0m\e[0;31m > \e[0m" | |
;; | |
*) export PS1=">: " | |
;; | |
esac | |
} | |
####################### | |
### COMMAND ALIASES ### | |
####################### | |
# Locations Shortcuts | |
alias home="cd ~" | |
alias dev="cd ~/Development" | |
alias documents="cd ~/Documents" | |
alias doc=documents | |
alias desktop="cd ~/Desktop" | |
alias sites="cd ~/Sites" | |
alias web=sites | |
# Dropbox Location Shortcuts | |
alias dropbox="cd ~/Dropbox" | |
alias devbox="cd ~/Dropbox/Development" | |
# Alternative Basic Commands | |
alias symlink="ln -s" | |
alias symln=symlink | |
alias move="mv" | |
alias copy="cp" | |
alias makedir="mkdir" | |
alias remove="rm" | |
alias removed="rmdir" | |
# ls Command Shortcuts | |
# | |
# Default Options: -l Multi-line output | |
# -A Show hidden files | |
# -G Colorize output | |
# -h Use KB, MB, GB for Sizes | |
# -p Print a '/' after directory names | |
ln_base="ls -lAGhp" | |
alias ll="$ln_base" # Sort by Name | |
alias lt="${ln_base}t" # Sort by Modification Time | |
alias lb="${ln_base}S" # Sort by Size | |
# Textmate Shortcuts | |
alias textmate="mate" | |
alias tm=textmate | |
# Apache Control Shortcut | |
alias apache="sudo apachectl" | |
# Reboot Server | |
alias restart-server="sudo apachectl stop && mysql.server stop && mysql.server start && sudo apachectl start" | |
alias start-server="mysql.server start;sudo apachectl start" | |
alias stop-server="sudo apachectl stop;mysql.server stop" | |
alias start-ftp="sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist" | |
alias stop-ftp="sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist" | |
# Shortcut to move up directory tree. Defaults to 1 level. | |
# Number of levels (integer) can be optionally passed as an argument. | |
function up { | |
if [ -z $1 ]; then | |
cd .. | |
elif [[ "$1"=~"^[0-9]+$" ]]; then | |
local loop=0 | |
while [ $loop -lt $1 ]; do | |
cd .. | |
local loop=$(($loop+1)) | |
done | |
else | |
die "[ERROR] Integer expected." | |
fi | |
pwd | |
} | |
# Shortcut to open the current working directory in a new Finder window | |
alias show="open ." | |
alias reveal=show | |
# Shortcut to open user's bash profile file | |
alias editprofile="mate ~/.profile" | |
alias editbash=editprofile | |
# Shortcut for opening php's config directory in textmate | |
alias phpconf="mate /usr/local/etc/php/5.5" | |
alias phpini="mate /usr/local/etc/php/5.5/p" | |
# Shortcut for configuring a directory to be used for web development (provide directory as first argument) | |
function swebdir { | |
local dir=$1 | |
if [ -z "$dir" ]; then | |
dir="." | |
fi | |
if [ -d $dir ]; then | |
local user=`id -un` | |
local group=`id -gn` | |
local www_user=`ps axo user,group,comm | egrep '(apache|httpd)' | grep -v ^root | uniq | cut -d\ -f 1` | |
sudo chmod -R +a "$www_user allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity" $dir | |
sudo chown -R $user:$group $dir | |
else | |
die "[ERROR] $dir is not a directory." | |
fi | |
} | |
########################## | |
### SYSTEM MAINTENANCE ### | |
########################## | |
# Shortcut to remove all .DS_Store in the current directory and all its child directories. | |
alias remove-ds-store="find . -name '.DS_Store' -depth -exec rm {} \;" | |
alias rmds=remove-ds-store | |
# Shortcut to remove all .DS_Store files from the file system. | |
# Must be run as a super user, password required. | |
alias remove-all-ds-store="sudo find / -name '.DS_Store' -depth -exec rm {} \;" | |
# Shortcut to rebuild the Launch Database | |
alias rebuildldb="echo '[INFO] Rebuilding Launch Database...'; \ | |
/System/Library/Frameworks/CoreServices.framework\ | |
/Versions/A/Frameworks/LaunchServices.framework\ | |
/Versions/A/Support/lsregister \ | |
-dump -kill -r \ | |
-domain local \ | |
-domain user \ | |
-domain system; \ | |
echo '[INFO] Database has been rebuilt. Force quitting Finder...'; \ | |
killall Finder; \ | |
echo '[INFO] Rebuild complete. Finder will now relaunch automatically.'" | |
# Shortcut to flush the DNS cache | |
alias flushdns="dscacheutil -flushcache; \ | |
sudo killall -HUP mDNSResponder" | |
# Alternative Aliases | |
alias rebuildlaunchdatabase=rebuildldb | |
alias rebuild-launch-database=rebuildldb | |
alias rebuilddb=rebuildldb | |
alias rebuild=rebuildldb | |
alias rbldb=rebuildldb | |
# Routine for automatically updating Homebrew, upgrading any outdated packages, and cleaning out the chace | |
function rebrew { | |
echo "[INFO] Updating Homebrew..." | |
brew update | |
echo "[INFO] Upgrading Outdated Packages..." | |
brew upgrade | |
echo "[INFO] Cleaning Up..." | |
brew cleanup | |
echo "[INFO] Finished Updating Homebrew." | |
} | |
# Routine for running common update commands. | |
function fullsystemupdate { | |
echo "[INFO] Performing Full System Update..." | |
# Update Homebrew | |
rebrew | |
# Update Composer | |
echo "[INFO] Updating Composer..." | |
composer self-update | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Composer updated successfully." | |
else | |
echo "[ERROR] Composer failed to update." | |
fi | |
# Update Pear | |
echo "[INFO] Updating Pear Extensions..." | |
pear update-channels && pear upgrade | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Pear Extensions updated successfully." | |
else | |
echo "[ERROR] Pear Extensions failed to update." | |
fi | |
# Update Ruby | |
echo "[INFO] Updating Ruby Gems..." | |
gem update --system && gem update | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Ruby Gems updated successfully." | |
else | |
echo "[ERROR] Ruby Gems failed to update." | |
fi | |
# Update Node | |
echo "[INFO] Updating Global Node Packages..." | |
npm update -g | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Node Packages updated successfully." | |
else | |
echo "[ERROR] Node Packages failed to update." | |
fi | |
echo "[INFO] Finished Full System Update" | |
} | |
# Alternative Aliases | |
alias full-system-update=fullsystemupdate | |
alias updateall=fullsystemupdate | |
alias update-all=fullsystemupdate | |
alias updatesystem=fullsystemupdate | |
alias update-system=fullsystemupdate | |
alias systemupdate=fullsystemupdate | |
alias system-update=fullsystemupdate | |
# Routines for isntalling PHING via PEAR and link it to /usr/local/bin/phing | |
function linkphing { | |
local php_root=`brew --prefix homebrew/php/php55` | |
local phing_link_path="/usr/local/bin/phing" | |
local phing_path="$php_root/bin/phing" | |
if [ -e $phing_link_path ]; then | |
if [ -L $phing_link_path ]; then | |
echo "[INFO] Phing already symlinked to $phing_link_path." | |
return 0 | |
else | |
echo "[ERROR] Phing could not be installed because a file already exists at $phing_link_path." | |
return 1 | |
fi | |
else | |
ln -s $phing_path $phing_link_path | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Phing has been symlinked to $phing_link_path." | |
return 0 | |
else | |
echo "[ERROR] Failed to symlink phing to $phing_link_path." | |
return 2 | |
fi | |
fi | |
} | |
function installphing { | |
if [ -x `which phing` ]; then | |
echo "[INFO] Phing already installed." | |
linkphing | |
return $? | |
fi | |
echo "[INFO] Configuring Pear..." | |
chmod -R ug+w $PHP_ROOT/lib/php | |
pear config-set php_ini /usr/local/etc/php/5.5/php.ini | |
pear config-set preferred_state alpha | |
echo "[INFO] Adding Pear channels..." | |
pear channel-discover pear.phing.info | |
pear channel-discover bartlett.laurent-laville.org | |
pear channel-discover pear.phpunit.de | |
pear channel-discover pear.pdepend.org | |
pear channel-discover pear.phpmd.org | |
pear channel-discover pear.phpdoc.org | |
pear channel-discover pear.symfony.com | |
pear channel-discover pear.netpirates.net | |
echo "[INFO] Installing PHING (with all dependencies)..." | |
pear install --alldeps phing/phing | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Phing successfully installed." | |
linkphing | |
return $? | |
else | |
echo "[ERROR] Failed to install Phing." | |
return 3 | |
fi | |
} | |
# Routines for uninstall Phing and Removing its symlinked | |
function unlinkphing { | |
if [ -e /usr/local/bin/phing ] && [ -L /usr/local/bin/phing ]; then | |
echo "[INFO] Removing Phing symlink..." | |
rm /usr/local/bin/phing | |
if [ $? -ne 0 ]; then | |
echo "[ERROR] Failed to remove symlink." | |
return 4 | |
fi | |
else | |
echo "[ERROR] Failed to find symlink." | |
return 5 | |
fi | |
} | |
function uninstallphing { | |
if [ -x `which phing` ]; then | |
echo "[INFO] Uninstalling Phing..." | |
pear uninstall phing/phing | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Phing successfully removed." | |
unlinkphing | |
return $? | |
else | |
echo "[ERROR] Failed to install Phing." | |
return 6 | |
fi | |
else | |
echo "[ERROR] Phing not currently installed." | |
return 7 | |
fi | |
} | |
# Routine to install Homebrew if it hasn't already been | |
# Read about Homebrew here: http://brew.sh | |
function homebrewme { | |
if [ -x `which brew` ]; then | |
echo "[INFO] Homebrew is already installed." | |
else | |
echo "[INFO] Homebrew not found." | |
echo "[INFO] Installing Homebrew..." | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
if [ $? -eq 0 ]; then | |
echo "[INFO] Homebrew installation complete." | |
else | |
echo "[ERROR] Homebrew installation failed." | |
return 1 | |
fi | |
fi | |
} | |
# Shortcut to Reset The Current Git Repository to the previous commit | |
# Primary used to abort a merge that isn't working | |
alias gitabort="git reset --hard HEAD"; | |
############### | |
### PRIVATE ### | |
############### | |
# This loads a second set of bash commands that need to be kept private for security reasons | |
if [ -f ~/.bash_private ]; then | |
. ~/.bash_private | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment