Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
179 lines (154 sloc) 5.26 KB
#include this file in .bashrc like this:
#if [ -f ~/.bashrc_portable ]; then
# . ~/.bashrc_portable
#else
# echo -e "\t (no .bashrc_portable file found)"
#fi
if [ -f .bash_aliases ]; then
. .config/aliases
fi
alias vlf="vi $(\ls -t | head -n1)" #open the file with the newest timestamp in the directory
#system specific aliases
uname=$(uname -a)
if [[ $uname =~ ^Linux ]]; then
echo "detected linux"
alias ls="\ls -la --color=auto"
alias ll="\ls -l --color=auto"
elif [[ $uname =~ ^Darwin ]]; then
echo "detected darwin"
alias ls="\ls -la -G"
alias ll="\ls -l -G"
else
echo "could not detect operating system"
fi
function c {
#color table swiped from http://tammersaleh.com/posts/a-better-rvm-bash-prompt/
# regular colors
case $1 in
# colors
K) echo "\[\033[0;30m\]" ;;
R) echo "\[\033[0;31m\]" ;;
G) echo "\[\033[0;32m\]" ;;
Y) echo "\[\033[0;33m\]" ;;
B) echo "\[\033[0;34m\]" ;;
M) echo "\[\033[0;35m\]" ;;
C) echo "\[\033[0;36m\]" ;;
W) echo "\[\033[0;37m\]" ;;
# emphasized (bolded) colors
EMK) echo "\[\033[1;30m\]" ;;
EMR) echo "\[\033[1;31m\]" ;;
EMG) echo "\[\033[1;32m\]" ;;
EMY) echo "\[\033[1;33m\]" ;;
EMB) echo "\[\033[1;34m\]" ;;
EMM) echo "\[\033[1;35m\]" ;;
EMC) echo "\[\033[1;36m\]" ;;
EMW) echo "\[\033[1;37m\]" ;;
# background colors
BGK) echo "\[\033[40m\]" ;;
BGR) echo "\[\033[41m\]" ;;
BGG) echo "\[\033[42m\]" ;;
BGY) echo "\[\033[43m\]" ;;
BGB) echo "\[\033[44m\]" ;;
BGM) echo "\[\033[45m\]" ;;
BGC) echo "\[\033[46m\]" ;;
BGW) echo "\[\033[47m\]" ;;
# not-colors
*) echo "\[\033[0m\]" ;;
esac
}
function _git_bang_if_dirty { # http://tammersaleh.com/posts/a-better-rvm-bash-prompt/
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo "!"
}
function _git_dash_unless_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] || echo "-"
}
function _git_current_branch { # adapted from http://amix.dk/blog/post/19571
git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function _git_hash { # thank you mr. seguin
sha=($(git log -1 2>/dev/null)) # parens make it an array, space seperated
sha=${sha[1]} # pull out the full hash
echo ${sha:0:7} # first few characters of the hash
}
cs () { cd "$1" && ls; } #cd then ls
#PS1='\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1=""
#PS1="$PS1\n" # newline
PS1="$PS1$(c EMR)\$(_git_bang_if_dirty)$(c)" # exclamation point if branch is dirty
PS1="$PS1$(c C)\$(_git_current_branch)$(c)" # current branch name
PS1="$PS1$(c K)@\$(_git_hash)$(c)" # current sha hash
PS1="$PS1$(c K) \D{%b-%d %H:%m:%S}$(c)" # time, so we can see when the last command finished, black, so its there when we need it but not in the way.
PS1="$PS1\n" # newline
PS1="$PS1$(c G)\u@\h$(c):$(c B)\w$(c)\$ " # the real prompt
screen -x
##################################################################################
#
# Open a file in a vim session, use sudo if needed.
#
vib() {
if test -w $1; then
vim $1
else
sudo vim $1
fi
}
#
# For use when resuming remote screen session to re-sync
# ssh agent, and thus keys push through the new ssh session
# and make them available to shells running inside of screen
#
# Run before connecting to screen to dump env vars to a file,
# then resume or extend screen session and run again to
# import those env vars to the current environment.
#
keyme() {
if [[ $TERM =~ "screen" ]]; then
echo -n "Importing ssh agent - "
if [ -s $HOME/.ssh/envs ]; then
. $HOME/.ssh/envs
echo "Success!"
else
echo "No envs file found."
fi
else
echo -n "Exporting ssh agent - "
# Courtesy of http://www.deadman.org/sshscreen.php
SSHVARS="SSH_CLIENT SSH_TTY SSH_AUTH_SOCK SSH_CONNECTION DISPLAY"
for x in ${SSHVARS} ; do
(eval echo $x=\$$x) | sed 's/=/="/
s/$/"/
s/^/export /'
done 1>$HOME/.ssh/envs
echo "Success!"
fi
}
# OSX: Run a command in a new terminal tab -- probably will blow up or something on nix's
# shamelessly nabbed from http://tomafro.net/2009/08/tip-open-new-tab-in-osx-terminal
tab () {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
activate
do script with command "cd $PWD; $*" in window 1
end tell
EOF
}
#
# Start up the rails dev environment in the current directory, again probably blows up on nix's
#
# Might be worth it to write some logic that encapsulates screen/osx commands into generics...
#
workflow () {
tab rc # start rails console in a new tab
[[ -f Guardfile ]] && tab guard # start guard in a new tab
tab # blank tab for rake tasks and such
mvim . &>/dev/null # open up macvim in this directory -- auto-opens tabs for relevant rails folders
rs # start the rails server in this tab
}
notes () {
[[ -f ~/notes.md ]] && less ~/notes.md
}