Last active
December 31, 2015 12:18
-
-
Save kasperlewau/7984875 to your computer and use it in GitHub Desktop.
dotfiles
This file contains hidden or 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
# [[ -r ~/.bash_prompt ]] && source ~/.bash_prompt | |
# [[ -s ~/.bashrc ]] && source ~/.bashrc | |
# [[ -s ~/.exports ]] && source ~/.exports | |
for file in ~/.{bash_prompt,bashrc,exports}; do | |
[ -r "$file" ] && source "$file" | |
done | |
alias rdbm="be rake db:migrate" | |
alias rdbt="be rake db:test:prepare" | |
alias seed="be rake db:seed" | |
alias dropdb="~/pg_kill.sh && be rake db:drop" | |
alias createdb="be rake db:create" | |
alias initdb="createdb && rdbm && rdbt && seed" | |
alias fuckdb="dropdb && createdb && rdbm && rdbt && seed" | |
alias pubkey="cat ~/.ssh/id_rsa.pub | pbcopy && echo 'Yay! Key copied to clipboard.'" | |
alias pgdir="cd /usr/local/var/postgres" | |
alias rmpg="rm postmaster.pid" | |
alias startpg="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start" | |
alias restartpg="pgdir && rmpg && startpg" | |
This file contains hidden or 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
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt” | |
# Shamelessly copied from https://github.com/gf3/dotfiles | |
default_username='paulirish' | |
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then | |
export TERM=gnome-256color | |
elif infocmp xterm-256color >/dev/null 2>&1; then | |
export TERM=xterm-256color | |
fi | |
if tput setaf 1 &> /dev/null; then | |
tput sgr0 | |
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then | |
MAGENTA=$(tput setaf 9) | |
ORANGE=$(tput setaf 172) | |
GREEN=$(tput setaf 190) | |
PURPLE=$(tput setaf 141) | |
WHITE=$(tput setaf 256) | |
else | |
MAGENTA=$(tput setaf 5) | |
ORANGE=$(tput setaf 4) | |
GREEN=$(tput setaf 2) | |
PURPLE=$(tput setaf 1) | |
WHITE=$(tput setaf 7) | |
fi | |
BOLD=$(tput bold) | |
RESET=$(tput sgr0) | |
else | |
MAGENTA="\033[1;31m" | |
ORANGE="\033[1;33m" | |
GREEN="\033[1;32m" | |
PURPLE="\033[1;35m" | |
WHITE="\033[1;37m" | |
BOLD="" | |
RESET="\033[m" | |
fi | |
# Fastest possible way to check if repo is dirty. a savior for the WebKit repo. | |
function parse_git_dirty() { | |
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo '*' | |
} | |
function parse_git_branch() { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" | |
} | |
# Only show username/host if not default | |
function usernamehost() { | |
if [ $USER != $default_username ]; then echo "${MAGENTA}$USER ${WHITE}at ${ORANGE}$HOSTNAME $WHITEin "; fi | |
} | |
# iTerm Tab and Title Customization and prompt customization | |
# http://sage.ucsc.edu/xtal/iterm_tab_customization.html | |
# Put the string " [bash] hostname::/full/directory/path" | |
# in the title bar using the command sequence | |
# \[\e]2;[bash] \h::\]$PWD\[\a\] | |
# Put the penultimate and current directory | |
# in the iterm tab | |
# \[\e]1;\]$(basename $(dirname $PWD))/\W\[\a\] | |
PS1="\[\e]2;$PWD\[\a\]\[\e]1;\]$(basename "$(dirname "$PWD")")/\W\[\a\]${BOLD}\$(usernamehost)\[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" |
This file contains hidden or 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
#!/usr/bin/env bash | |
# kill all connections to the postgres server | |
if [ -n "$1" ] ; then | |
where="where pg_stat_activity.datname = '$1'" | |
echo "killing all connections to database '$1'" | |
else | |
where="where pg_stat_activity.datname in (select datname from pg_database where datname != 'postgres')" | |
echo "killing all connections to database" | |
fi | |
cat <<-EOF | psql -U kasper -d postgres | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
${where} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment