Mac OSX Bash Profile Customizing

I realized that having some shortcuts in your Bash Profile can cut down on development time a good deal. Plus you don’t have to possibly look up some rarely used command if you can make an alias. ¬†While Googling for some new tricks I came across this blog post by Nathaniel Landau that had an incredibly comprehensive .bash_profile for OSX.

A ton of them are super helpful.


# open current directory in finder
alias f='open -a Finder ./'

# make new directory and cd into it
mcd () { mkdir -p "$1" && cd "$1"; }

# qfind: Quickly search for file
alias qfind="find . -name "

# ff: Find file under the current directory
ff () { /usr/bin/find . -name "$@" ; }

# ffs: Find file whose name starts with a given string
ffs () { /usr/bin/find . -name "$@"'*' ; }

# ffe: Find file whose name ends with a given string
ffe () { /usr/bin/find . -name '*'"$@" ; }

#delete pesky .DS_Store files recursively
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"

# extract: Extract most know archives with one command
# ---------------------------------------------------------
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}

 

A few I’ve came up with are


#copy current working directory to clipboard
alias cppwd="pwd | pbcopy"
# start a light httpd server from current directory for static html
alias lightserver="python -m SimpleHTTPServer 8080"

#If you use homebrew and postgres this can be helpful
#start postgres
alias startpg="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start"

#stop postgres
alias stoppg="pg_ctl -D /usr/local/var/postgres stop -s -m fast"
# view postgreslogs
alias postgreslogs="tail -F /usr/local/var/postgres/server.log"

There ended up being a few Git commands I run often so I shortened them up a bit.


alias gaa="git add --all"
# add the commit message as the argument
alias gcm="git commit -m $@" # gcm "commit message"
alias gpom="git push origin master"
alias gphm="git push heroku master"
#if you use GhostScript this will cause a conflict
alias gs="git status"

Those are just a few of them. When I have some spare time I am going to learn a little bit more about writing shell scripts. A friend has a problem at work she needs help with that involves searching through large amounts of PDF files for certain terms. The next post will probably be about that.

Leave a Reply

Your email address will not be published. Required fields are marked *