Skip to content

Instantly share code, notes, and snippets.

@dwin
Forked from josephspurrier/.bash_profile
Last active December 2, 2016 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwin/7a7a82e8e3f287b07823f07d78dbae36 to your computer and use it in GitHub Desktop.
Save dwin/7a7a82e8e3f287b07823f07d78dbae36 to your computer and use it in GitHub Desktop.
OS X Bash Profile
#################################################################################
#
# Bash Configurations and Aliases for OS X
#
# Latest: https://gist.github.com/00000
#
################################################################################
################################################################################
# Terminal
################################################################################
# Preferred iTerm2 Theme
# https://github.com/mbadolato/iTerm2-Color-Schemes/blob/master/schemes/NightLion%20v1.itermcolors
# Set colorized terminal prompt
# Prompt: Hostname:current_dir
export PS1="\[\033[36m\]\h\[\033[m\]:\[\033[32m\]\w\[\033[m\] "
################################################################################
# Filesystem
################################################################################
# List files with color
alias ls='ls -GFh'
# Default editor
# export EDITOR="/usr/bin/nano"
export EDITOR="/Applications/Sublime Text.app"
# Open folder in Sublime Text 3
# Pass: directory to open (. opens current directory)
# Usage: t3 [folder]
alias t3="open -a 'Sublime Text'"
# Open folder in Atom
# Open Finder for current directory
alias finder='open -a Finder ./'
# Modify cd to list folder contents when directory is changed
# Usage: cd
cd() { builtin cd "$@"; ls; }
# Traverse folders quicker
alias cd2='cd ../../' # Go back 2 directory levels
alias cd3='cd ../../../' # Go back 3 directory levels
alias cd4='cd ../../../../' # Go back 4 directory levels
alias cd5='cd ../../../../../' # Go back 5 directory levels
alias cd6='cd ../../../../../../' # Go back 6 directory levels
# Watch a file
# Pass: file to watch
# Usage: watch [string]
alias watch="less +F"
# Recursive list - easy to view individual folders
alias lsr1='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less'
# Recursive list - easy to view folders only
alias lsr2='find . -type d -not -path "*/\.*"'
# Recursive list - easy to view files only
alias lsr3='find . -type f -not -path "*/\.*"'
# Recursive list - easy to view folders and files
alias lsr4='find . -not -path "*/\.*"'
################################################################################
# Networking
################################################################################
# Internal IP
alias iip="ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{print \$2}'"
# External IP
alias eip="dig +short myip.opendns.com @resolver1.opendns.com"
# Gateway IP
alias gip="route get default | grep "gateway:" | awk '{print \$2}'"
# Flush DNS
alias flushdns='dscacheutil -flushcache'
################################################################################
# Security
################################################################################
# Don't add commands that start with a space to bash history
export HISTIGNORE=" *"
# Base64 encode
# Pass: string to encode
# Usage: b64e [string]
b64e() {
echo -n "$1" | base64
}
# Base64 decode
# Pass: string to decode
# Usage: b64d [string]
b64d() {
echo -n "$1" | base64 -D
echo ""
}
# Lock screen
alias lock='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
# Generate password
# Pass: length of password to generate
# Usage: pwg [int]
pwg() {
cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w $1 | head -n 1
}
# Current machine information
# Usage: ii
ii() {
echo -e "\nAdditional information:$NC " ; uname -a
echo -e "\nUsers logged on:$NC " ; w -h
echo -e "\nCurrent date :$NC " ; date
echo -e "\nMachine stats :$NC " ; uptime
echo -e "\nPublic facing IP Address :$NC " ;eip
#echo -e "\nDNS Configuration:$NC " ; scutil --dns
echo
}
################################################################################
# Miscellaneous
################################################################################
# Show path variables
alias path='echo -e ${PATH//:/\\n}'
# Reload .bash_profile
alias reload=". ~/.bash_profile; echo -e 'Profile reloaded.'"
# Start PHP webserver
# Pass: folder to serve
# Usage: phpw [folder]
alias phpw="php -S localhost:8080 -t"
# Extract any archive
# Pass: file to extract
# Usage: extract [file]
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
}
################################################################################
# Homebrew
################################################################################
# Mono Framework
export MONO_GAC_PREFIX="/usr/local"
# Add Brew bin sbin folder to path
# Ensure path is only added once when reloading
if [[ $PATH != *"/usr/local/sbin:"* ]]; then
export PATH=/usr/local/sbin:$PATH
fi
################################################################################
# Go
################################################################################
# Go workspace
export GOPATH=$HOME/Dev/golang
# Add Go bin folder to path
# Ensure path is only added once when reloading
if [[ $PATH != *":$GOPATH/bin"* ]]; then
export PATH=$PATH:$GOPATH/bin
fi
################################################################################
# Docker
################################################################################
# Start Docker
alias docker-init="source /Applications/Docker/Docker\ Quickstart\ Terminal.app/Contents/Resources/Scripts/start.sh"
# Set the evironment variables
# eval $(docker-machine env default)
################################################################################
# Reference
################################################################################
# BASH Examples: https://natelandau.com/my-mac-osx-bash_profile/
# iTerm2 Colors: https://github.com/mbadolato/iTerm2-Color-Schemes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment