Skip to content

Instantly share code, notes, and snippets.

@collegeimprovements
Forked from chrisbloom7/.bash_aliases
Created December 24, 2015 08:46
Show Gist options
  • Save collegeimprovements/4251fdee9850e6b6f7fd to your computer and use it in GitHub Desktop.
Save collegeimprovements/4251fdee9850e6b6f7fd to your computer and use it in GitHub Desktop.
A portion of my alias entries and some other useful snippets for Bash
#!/bin/sh
# GENERAL COMMANDS
alias l='ls -AHhlp'
alias c='clear'
alias cx='chmod +x'
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias reload='source ~/.bash_profile'
alias release='xattr -d com.apple.quarantine'
alias flushdns='sudo discoveryutil udnsflushcaches'
alias mail_log="tail -f /private/var/log/mail.log"
alias hist="history | grep -i"
alias me="git pretty | grep \"Chris Bloom\" | more"
alias beep="say -v Zarvox \"My liege, the task is complete\""
# alias reclaim="sudo chflags -R nouchg * && sudo chown -R chrisbloom7:staff *"
function reclaim {
echo changing flags on "$@"
sudo chflags -Rvv nouchg "$@"
echo changing ownership on "$@"
sudo chown -Rv chrisbloom7:staff "$@"
}
# RUBY / RUBY ON RAILS COMMANDS
alias rails_mv="rails -v | sed 's/Rails \([0-9]\).*/\1/g'"
alias bexec='bundle exec'
# Alias the rake command to Spring binstubs or fallback to "bundle exec"
# http://goo.gl/HkhHAf, http://goo.gl/STtIvF
function brake {
if [ -f bin/rake ]
then
bin/rake "$@"
else
if [ `rails_mv` -lt 3 ]; then
rake "$@"
else
bexec rake "$@"
fi
fi
}
function brails {
if [ -f bin/rake ]
then
bin/rails "$@"
else
bexec rails "$@"
fi
}
function cons {
if [ `rails_mv` -lt 3 ]; then
./script/console "$@"
else
brails c "$@"
fi
}
function dbcons {
if [ `rails_mv` -lt 3 ]; then
echo "Not supported in this version of Rails (`rails -v`)"
else
brails db "$@"
fi
}
function gen {
if [ `rails_mv` -lt 3 ]; then
./script/generate "$@"
else
brails g "$@"
fi
}
function srv {
if [ `rails_mv` -lt 3 ]; then
./script/server "$@"
else
brails s "$@"
fi
}
function run {
if [ `rails_mv` -lt 3 ]; then
./script/runner "$@"
else
brails r "$@"
fi
}
alias sandbox='cons --sandbox'
alias epoch="ruby -e 'puts Time.now.to_i'"
alias timestamp='epoch'
# RVM COMMANDS
# alias rvmrc='rvm rvmrc create `rvm current` --ruby-version'
function rvmrc {
read -r -p "Create ruby-version files for `rvm current`? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
rvm rvmrc create `rvm current` --ruby-version
echo "Created .ruby-version:"
echo "-----"
cat .ruby-version
echo ""
echo "Created .ruby-gemset:"
echo "-----"
cat .ruby-gemset
;;
*)
echo "Canceled"
;;
esac
}
# TEXTMATE SHORTUTS
# alias mate_apache_conf='mate /etc/apache2'
# alias mate_vhosts='mate /etc/apache2/extra/httpd-vhosts.conf'
# alias mate_passenger_vhosts='mate /etc/apache2/passenger_pane_vhosts'
alias mate_bash_profile='mate ~/.bash_profile'
alias mate_bash_login='mate ~/.bash_login'
alias mate_bashrc='mate ~/.bashrc'
alias mate_hosts='mate /etc/hosts'
alias mate_aliases='mate ~/.bash_aliases'
# HOMEBREW POSTGRES COMMANDS
# # We're using the postgresql-common package from
# # https://github.com/petere/homebrew-postgresql
# # See config data for all clusters with `pg_lsclusters`
# alias pg84_start='pg_ctlcluster 8.4 development start'
# alias pg84_stop='pg_ctlcluster 8.4 development stop'
alias pg92_start='/usr/local/opt/postgresql92/bin/pg_ctl start -w -t 10 -D /usr/local/var/postgres-9.2 -l ~/Library/Logs/postgres.log'
alias pg92_stop='/usr/local/opt/postgresql92/bin/pg_ctl -D /usr/local/var/postgres-9.2 stop -s -m fast'
alias pg_start='pg_ctl start -w -t 10 -D /usr/local/var/postgres -l ~/Library/Logs/postgres.log'
alias pg_stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
# HOMEBREW MYSQL COMMANDS
# alias 'mysql51.server'='/usr/local/Cellar/mysql51/5.1.73/bin/mysql.server'
# alias mysql51='/usr/local/Cellar/mysql51/5.1.73/bin/mysql'
# alias mysqladmin51='/usr/local/Cellar/mysql51/5.1.73/bin/mysqladmin'
# alias mysqldump51='/usr/local/Cellar/mysql51/5.1.73/bin/mysqldump'
# NATIVE APACHE COMMANDS
alias apache_start='sudo /usr/sbin/apachectl start'
alias apache_stop='sudo /usr/sbin/apachectl stop'
alias apache_restart='sudo /usr/sbin/apachectl restart'
alias tail_apache_error_log='tail /var/log/apache2/error_log'
alias tail_apache_access_log='tail /var/log/apache2/access_log'
# REDIRECT PORT 25 TO 1025 FOR MOCKSMTP
alias forward_port_25='sudo ipfw add 1025 forward 127.0.0.1,1025 ip from any to any 25 in'
alias reset_port_25='sudo ipfw delete 1025'
# SUBVERSION COMMANDS
alias svn_list_unversioned="svn status --no-ignore | grep '^\?' | sed 's/^\? //'"
alias svn_delete_unversioned="svn status --no-ignore | grep '^\?' | sed 's/^\? //' | xargs rm -rf"
# GIT COMMANDS
function git-make-branch {
echo "\$@ = '$@'"
typeset branch
if [[ "$@" != "" ]]; then
branch=$(ruby -e 'puts ARGV.join(" ").strip.gsub(/[\W\s_]+/, " ").downcase.split(" ").join("-")' "$@")
# echo "branch = '$branch'"
if [[ "$branch" = "" ]]; then
echo "-- Could not create branch from supplied arguments"
else
git co -b "$branch"
echo "-- Created branch $branch"
fi
else
echo "-- Could not create branch from supplied arguments"
fi
}
alias git-mb='git-make-branch'
# From http://stackoverflow.com/a/2831173/83743
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function git-branch-incoming {
echo branch \($1\) has these commits and \($(parse_git_branch)\) does not
git log ..$1 --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local
}
alias git-bin='git-branch-incoming'
function git-branch-outgoing {
echo branch \($(parse_git_branch)\) has these commits and \($1\) does not
git log $1.. --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local
}
alias git-bout='git-branch-outgoing'
# PROJECT COMMANDS
function proj {
cd "$HOME/Projects/$@"
}
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
if [ -f ~/bin/svn-color/svn-color.sh ]; then
. ~/bin/svn-color/svn-color.sh
fi
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
source $HOME/.bash_login
source $HOME/.bashrc
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
export PS1="\[$(tput bold)\]\[$(tput setaf 6)\]\n\u@\h \w\[$(tput setaf 4)\] \$(parse_git_branch)\n\[$(tput setaf 7)\]$ \[$(tput sgr0)\]"
umask 0002 # grant write permission to group
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=/usr/local/sbin:/usr/local/bin:/Users/chrisbloom7/bin:$PATH
export ARCHFLAGS="-arch x86_64"
export EDITOR='mate -w'
export GIT_EDITOR='mate -wl1'
export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
export ANDROID_HOME=/usr/local/opt/android-sdk
# virtualenv should use Distribute instead of legacy setuptools
export VIRTUALENV_DISTRIBUTE=true
# Centralized location for new virtual environments
export PIP_VIRTUALENV_BASE=$HOME/.virtualenvs
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# disable this requirement manually so we can update packages, etc.
syspip(){
PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
complete -C "$HOME/Scripts/rake_autocomplete_for_bash.rb" -o default rake
PROMPT_COMMAND='echo -ne "\033]0; ${PWD##*/}\007"'
alias diff=colordiff
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
#!/bin/bash
function svn
{
# rebuild args to get quotes right
CMD=
for i in "$@"
do
if [[ "$i" =~ \ ]]
then
CMD="$CMD \"$i\""
else
CMD="$CMD $i"
fi
done
# pad with spaces to strip --nocol
CMD=" $CMD "
CMDLEN=${#CMD}
# parse disabling arg
CMD="${CMD/ --nocol / }"
# check if disabled
test "$CMDLEN" = "${#CMD}"
if [ $? = 1 ] || [ ! -t 1 ]
then
eval $(which svn) $CMD
return
fi
# supported svn actions for "status-like" output
ACTIONS="add|checkout|co|cp|del|export|remove|rm|st"
ACTIONS="$ACTIONS|merge|mkdir|move|mv|ren|sw|up"
# actions that outputs "status-like" data
if [[ "$1" =~ ^($ACTIONS) ]]
then
eval $(which svn) $CMD | while IFS= read -r RL
do
if [[ $RL =~ ^\ ?M ]]; then C="\033[34m";
elif [[ $RL =~ ^\ ?C ]]; then C="\033[41m\033[37m\033[1m";
elif [[ $RL =~ ^A ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^D ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^X ]]; then C="\033[37m";
elif [[ $RL =~ ^! ]]; then C="\033[43m\033[37m\033[1m";
elif [[ $RL =~ ^I ]]; then C="\033[33m";
elif [[ $RL =~ ^R ]]; then C="\033[35m";
else C=
fi
echo -e "$C${RL/\\/\\\\}\033[0m\033[0;0m"
done
# actions that outputs "diff-like" data
elif [[ "$1" =~ ^diff ]]
then
eval $(which svn) $CMD | while IFS= read -r RL
do
if [[ $RL =~ ^Index:\ ]]; then C="\033[34m\033[1m";
elif [[ $RL =~ ^@@ ]]; then C="\033[37m";
# removed
elif [[ $RL =~ ^-\<\<\< ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^-\>\>\> ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^-=== ]]; then C="\033[31m\033[1m";
elif [[ $RL =~ ^- ]]; then C="\033[31m";
# added
elif [[ $RL =~ ^\+\<\<\< ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^\+\>\>\> ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^\+=== ]]; then C="\033[32m\033[1m";
elif [[ $RL =~ ^\+ ]]; then C="\033[32m";
else C=
fi
echo -e "$C${RL/\\/\\\\}\033[0m\033[0;0m"
done
else
eval $(which svn) $CMD
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment