Last active
August 29, 2015 13:56
-
-
Save krry/9263628 to your computer and use it in GitHub Desktop.
the .bashrc that ain't afraid to bash
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
########################################################### | |
# | |
# CANSECO | |
# a World Series-class .bashrc file | |
# | |
# Canseco draws from a few others' shell profiles, namely: | |
# killfall's ===> https://github.com/killfall/terminal-piperita | |
# and another couple I can't place at the moment | |
# | |
########################################################### | |
echo "WELCOME TO CANSECO" | |
echo "a world-series-class bash experience" | |
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" | |
echo "" | |
# import git auto-completion script | |
echo "=> enabling git auto-completion via .git-completion.bash" | |
if [ -f ~/.git-completion.bash ]; then | |
source ~/.git-completion.bash | |
fi | |
# modify the PATH environment variable to enable a bunch of dev tools and package managers | |
echo "=> exporting the PATH environment variable to include all the bins" | |
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/heroku/bin:$HOME/Sites/lib:$HOME/local/node/bin:$HOME/.node/bin:./node_modules/.bin:/usr/local/go/bin:$HOME/npm/bin:$HOME/mongo/bin:$HOME/Sites/go/bin:$PATH" | |
# set the Go path so the Go tool is happy | |
echo "=> exporting the GOPATH" | |
export GOPATH="$HOME/Sites/go" | |
# set development environment variable | |
echo "=> exporting the NODE_ENV" | |
export NODE_ENV="development" | |
# set sublime text as your default editor | |
echo "=> setting SublimeText as the default editor" | |
export EDITOR='subl -w' | |
# symlink `subl` to sublime text with this command (only needed once) | |
# ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl | |
# set Github creds on the command line processes can use the Github API | |
echo "=> making Github account available to the environment" | |
export GITHUB_USERNAME="krry" | |
export GITHUB_PASSWORD="Git6kry222" | |
# set ls colors | |
echo "=> setting list colors" | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
# environment variables to set prompt format and color | |
echo "=> setting env colors for use in custom shell prompt" | |
export COLOR_BOLD="\[\e[1m\]" | |
export COLOR_DEFAULT="\[\e[0m\]" | |
export COLOR_BLUE="\[\e[34m\]" | |
export COLOR_GREEN="\[\e[32m\]" | |
export COLOR_YELLOW="\[\033[33;1m\]" | |
export COLOR_MAGENTA="\[\033[35m\]" | |
export COLOR_RED="\[\e[31m\]" | |
# make sure mongoDB is running | |
echo "=> making sure mongoDB is running" | |
if ! ps -ef | grep mongo[d] | |
then mongod --dbpath ~/mongo/db & | |
fi | |
# some functions to intelligently color parts of the prompt | |
# test if user is root and set user color appropriately | |
echo "=> setting color of user in shell prompt" | |
if [[ $(id -u) == 0 ]] | |
then | |
export PS1USERCOLOR="\[\033[31m\]" | |
else | |
export PS1USERCOLOR="\[\033[36m\]" | |
fi | |
# get current branch in git repo | |
echo "=> making current git branch available to shell prompt" | |
function parse_git_branch() { | |
BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') | |
if [ ! "${BRANCH}" == "" ] | |
then | |
STAT=$(parse_git_dirty) | |
echo "=> [${BRANCH}${STAT}]" | |
else | |
echo "=> " | |
fi | |
} | |
# get current status of git repo | |
echo "=> adding git repo status indicators to shell prompt" | |
function parse_git_dirty { | |
status=$(git status 2>&1 | tee) | |
dirty=$(echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "=> $?") | |
untracked=$(echo -n "${status}" 2> /dev/null | grep "untracked files:" &> /dev/null; echo "=> $?") | |
ahead=$(echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "=> $?") | |
newfile=$(echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "=> $?") | |
renamed=$(echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "=> $?") | |
deleted=$(echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "=> $?") | |
bits='' | |
if [ "${renamed}" == "0" ]; then | |
bits=">${bits}" | |
fi | |
if [ "${ahead}" == "0" ]; then | |
bits="*${bits}" | |
fi | |
if [ "${newfile}" == "0" ]; then | |
bits="+${bits}" | |
fi | |
if [ "${untracked}" == "0" ]; then | |
bits="?${bits}" | |
fi | |
if [ "${deleted}" == "0" ]; then | |
bits="x${bits}" | |
fi | |
if [ "${dirty}" == "0" ]; then | |
bits="!${bits}" | |
fi | |
if [ ! "${bits}" == "" ]; then | |
echo "=> ${bits}" | |
else | |
echo "=> " | |
fi | |
} | |
# format prompt for clear I/O difference, current directory, current user, and current machine | |
echo "=> setting up custom shell prompt" | |
export PS1="$COLOR_YELLOW<______________________________________________________________________________>\n$COLOR_YELLOW\t $PS1USERCOLOR\u$COLOR_DEFAULT@$COLOR_GREEN\h$COLOR_DEFAULT: $COLOR_YELLOW\w\n$COLOR_MAGENTA\`if type parse_git_branch > /dev/null 2>&1; then parse_git_branch; fi\`\`if [ \$? = 0 ]; then echo -e '$COLOR_YELLOW:$'; else echo -e '$COLOR_RED:X'; fi\` \[\033[m\]" | |
export CLICOLOR=1 | |
# opens up number of concurrent processes that can run in terminal to allow high dependency installs like Roots | |
echo "=> expanding concurrent process limit to enable high-dependency packages to install" | |
ulimit -n 10000 | |
# # load nvm shell ---- note you'll need nvm for this to work | |
# source ~/.nvm/nvm.sh | |
# # load RVM into a shell session *as a function* | |
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" | |
# general shell aliases for frequently used commands | |
echo "=> adding general shell aliases: .., h, j, ls, ll, la, rm, cp, mv, psef, mkdir" | |
alias ..='cd ..' | |
alias h='history' | |
alias j='jobs -l' | |
alias ls='ls -GFh' | |
alias ll="ls -ll" | |
alias la="ll -a" | |
alias rm='rm -i' | |
alias cp='cp -i' | |
alias mv='mv -i' | |
alias psef='ps -ef | grep --color=auto' | |
alias mkdir='mkdir -p' | |
alias which='type -a' | |
# # apache helpers | |
# echo "=> adding apache aliases: rsapache, ezapache, stapache, stpapache" | |
# alias rsapache='sudo apachectl restart' | |
# alias ezapache='sudo apachectl graceful' | |
# alias stapache='sudo apachectl start' | |
# alias stpapache='sudo apachectl stop' | |
# # to enable apache web server on Mavericks and later | |
# sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist | |
# some helper aliases | |
echo "=> adding helper aliases: path, du, df, reloadrc, openrc, openhosts, flushcache" | |
alias path='echo -e ${PATH//:/\\n}' | |
alias du='du -kh' | |
alias df='df -kTh' | |
alias openrc='subl ~/.bashrc' | |
alias reloadrc='. ~/.bashrc' | |
alias openhosts='sudo subl /etc/hosts' | |
alias flushcache='dscacheutil -flushcache' | |
# some aliases to streamline git commands | |
echo "=> adding git aliases: gst, gad, gch, gcb, gcm, gcam, gl, gf, gp, gph, gpom, gphom, gphsm, gphhm, gphpm, gpre" | |
alias gst='git status' | |
alias gad='git add -A' | |
alias gch='git checkout' | |
alias gcb='git checkout -b' | |
alias gcm='git commit -m' | |
alias gcam='git commit -am' | |
alias gf='git fetch' | |
alias gp='git pull' | |
alias gph='git push' | |
alias gpom='git pull origin master' | |
alias gphom='git push origin master' | |
alias gphsm='git push staging master' | |
alias gphpm='git push prod master' | |
alias gphhm='git push heroku master' | |
alias gpre='git pull --rebase' | |
# a really sweet git log prettifier - thx to JMarsh | |
alias gl='git log --graph --abbrev-commit --pretty=format:"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"' | |
# open with IA Writer | |
echo "=> open docs with iA Writer with 'iamd'" | |
alias iamd='open -a "iA\ Writer"' | |
# dig down to the Packages folder for Sublime Text since the beta version doesn't manage its own packages yet | |
echo "=> jump to the Sublime Text packages folder with 'sublpkg'" | |
alias sublpkg='cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages' | |
# # launch an app's development environment in one command with a bash function, e.g., | |
# function project_name { | |
# cd ~/path/to/project | |
# mongod --rest --dbpath ~/path/to/db& | |
# sass -w src/css:dest/css& | |
# DEBUG=express:* node app.js | |
# } | |
# function opache { | |
# take the PWD and grab the youngest directory | |
# pwd=$PWD | |
# this_dir=${pwd##*/} | |
# open http://ksnyder-mac/~ksnyder/$this_dir | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment