Created
September 30, 2011 18:21
-
-
Save torifat/1254570 to your computer and use it in GitHub Desktop.
My Bashrc
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
## If not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
export EDITOR='mate' | |
export GIT_EDITOR='mate -wl1' | |
## History control | |
# Control how bash stores command history | |
# flags: ignorespace, ignoredups, ignoreboth | |
# ignorespace flag tells bash to ignore commands that start with spaces and ignoredups tells bash to ignore duplicates | |
# ignoreboth = ignorespace:ignoredups | |
export HISTCONTROL=ignoreboth | |
# export HISTSIZE=500 | |
# Enable multiple session history | |
shopt -s histappend | |
## PATH | |
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH | |
# No ._ files in archives please | |
export COPYFILE_DISABLE=true | |
# Use AirDrop over every interface. srsly this should be a default. | |
defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1 | |
## Aliases | |
# ls aliases | |
alias l='ls -G' | |
alias ll='ls -l -h' | |
alias la='ls -a' | |
alias lla='ls -a -l' | |
alias lm='ls -la | less' | |
alias ..='cd ..' | |
alias ...='cd .. ; cd ..' | |
alias cls='clear' | |
alias pg='ping google.com' | |
alias cleanDS='cd / && sudo find . -type f -name "*.DS_Store" -exec rm {} \;' | |
# Clean DNS Cache | |
alias flushdns='dscacheutil -flushcache' | |
# Clear Cache | |
alias clearcache='sudo atsutil databases -remove' | |
alias pigs='du | sort -nr | cut -f2- | xargs du -hs' | |
alias pigs1='du -d1 | sort -nr | cut -f2- | xargs du -hs' | |
alias here='open -a Finder .' | |
alias server='open http://localhost:8000 && python -m SimpleHTTPServer' | |
# Portable ls with colors | |
if ls --color -d . >/dev/null 2>&1; then | |
alias ls='ls --color=auto' # Linux | |
elif ls -G -d . >/dev/null 2>&1; then | |
alias ls='ls -G' # BSD/OS X | |
fi | |
function show-empty-folders { | |
find . -depth -type d -empty | |
} | |
function kill-empty-folders { | |
find . -depth -type d -empty -exec rmdir "{}" \; | |
} | |
alias godmode='mate -w ~/.bashrc; . ~/.bashrc' | |
alias brewit='brew update; brew upgrade' | |
alias reload='. ~/.bashrc' | |
## Tab Completions | |
set completion-ignore-case On | |
set show-all-if-ambiguous On # this allows you to automatically show completion without double tab-ing | |
# Turn on advanced bash completion | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi | |
## Custom prompt | |
# Colors | |
RED="\[\033[0;31m\]" | |
PINK="\[\033[1;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[0;32m\]" | |
LT_GREEN="\[\033[1;32m\]" | |
BLUE="\[\033[0;34m\]" | |
WHITE="\[\033[1;37m\]" | |
PURPLE="\[\033[1;35m\]" | |
CYAN="\[\033[1;36m\]" | |
BROWN="\[\033[0;33m\]" | |
LIGHT="\[\033[0;37m\]" | |
DARK="\[\033[0;90m\]" | |
COLOR_NONE="\[\033[0m\]" | |
LIGHTNING_BOLT="⚡" | |
UP_ARROW="↑" | |
DOWN_ARROW="↓" | |
UD_ARROW="↕" | |
FF_ARROW="→" | |
RECYCLE="♺" | |
MIDDOT="•" | |
PLUSMINUS="±" | |
function parse_git_branch { | |
branch_pattern="^# On branch ([^${IFS}]*)" | |
remote_pattern_ahead="# Your branch is ahead of" | |
remote_pattern_behind="# Your branch is behind" | |
remote_pattern_ff="# Your branch (.*) can be fast-forwarded." | |
diverge_pattern="# Your branch and (.*) have diverged" | |
git_status="$(git status 2> /dev/null)" | |
if [[ ! ${git_status} =~ ${branch_pattern} ]]; then | |
# Rebasing? | |
toplevel=$(git rev-parse --show-toplevel 2> /dev/null) | |
[[ -z "$toplevel" ]] && return | |
[[ -d "$toplevel/.git/rebase-merge" || -d "$toplevel/.git/rebase-apply" ]] && { | |
sha_file="$toplevel/.git/rebase-merge/stopped-sha" | |
[[ -e "$sha_file" ]] && { | |
sha=`cat "${sha_file}"` | |
} | |
echo "${PINK}(rebase in progress)${COLOR_NONE} ${sha}" | |
} | |
return | |
fi | |
branch=${BASH_REMATCH[1]} | |
# Dirty? | |
if [[ ! ${git_status} =~ "working directory clean" ]]; then | |
[[ ${git_status} =~ "modified:" ]] && { | |
git_is_dirty="${RED}${LIGHTNINlG_BOLT}" | |
} | |
[[ ${git_status} =~ "Untracked files" ]] && { | |
git_is_dirty="${git_is_dirty}${WHITE}${MIDDOT}" | |
} | |
[[ ${git_status} =~ "new file:" ]] && { | |
git_is_dirty="${git_is_dirty}${LT_GREEN}+" | |
} | |
[[ ${git_status} =~ "deleted:" ]] && { | |
git_is_dirty="${git_is_dirty}${RED}-" | |
} | |
[[ ${git_status} =~ "renamed:" ]] && { | |
git_is_dirty="${git_is_dirty}${YELLOW}→" | |
} | |
fi | |
# Are we ahead of, beind, or diverged from the remote? | |
if [[ ${git_status} =~ ${remote_pattern_ahead} ]]; then | |
remote="${YELLOW}${UP_ARROW}" | |
elif [[ ${git_status} =~ ${remote_pattern_ff} ]]; then | |
remote_ff="${WHITE}${FF_ARROW}" | |
elif [[ ${git_status} =~ ${remote_pattern_behind} ]]; then | |
remote="${YELLOW}${DOWN_ARROW}" | |
elif [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="${YELLOW}${UD_ARROW}" | |
fi | |
echo "${remote}${remote_ff}${GREEN}(${branch})${COLOR_NONE}${git_is_dirty}${COLOR_NONE}" | |
} | |
function setWindowTitle { | |
case $TERM in | |
*xterm*|ansi) | |
echo -n -e "\033]0;$*\007" | |
;; | |
esac | |
} | |
function set_prompt { | |
[[ -n $HOMEBREW_DEBUG_INSTALL ]] && \ | |
homebrew_prompt="${BROWN}Homebrew:${COLOR_NONE} debugging ${HOMEBREW_DEBUG_INSTALL}\n" | |
git_prompt="$(parse_git_branch)" | |
# create a $fill of all screen width minus the time string and a space: | |
let fillsize=${COLUMNS}-9 | |
fill="" | |
while [ "$fillsize" -gt "0" ] | |
do | |
fill="-${fill}" # fill with underscores to work on | |
let fillsize=${fillsize}-1 | |
done | |
# Prompt variable: | |
export PS1="${DARK}"'$fill \t\n'"[\w] ${git_prompt}${COLOR_NONE}\n${homebrew_prompt}\$ " | |
# Domain is stripped from hostname | |
case $HOSTNAME in | |
Rifats-MacBook-Pro.local) | |
this_host= | |
;; | |
*) | |
this_host="${HOSTNAME%%.*}:" | |
;; | |
esac | |
setWindowTitle "${this_host}${PWD/$HOME/~}" | |
} | |
export PROMPT_COMMAND=set_prompt | |
function git-root { | |
root=$(git rev-parse --git-dir 2> /dev/null) | |
[[ -z "$root" ]] && root="." | |
dirname $root | |
} | |
# Reveal current or provided folder in Path Finder | |
function pf { | |
target_path="$(cd ${1:-"$PWD"} && PWD)" | |
osascript<<END | |
tell app "Path Finder" | |
reveal POSIX file("$target_path") | |
activate | |
end tell | |
END | |
} | |
# Open a manpage in Preview, which can be saved to PDF | |
function pman { | |
man -t "${1}" | open -f -a /Applications/Preview.app | |
} | |
# Open a manpage in the browser | |
function bman { | |
man "${1}" | man2html | browser | |
} | |
function pgrep { | |
local exclude="\.svn|\.git|\.swp|\.coverage|\.pyc|_build" | |
find . -maxdepth 1 -mindepth 1 | egrep -v "$exclude" | xargs egrep -lir "$1" | egrep -v "$exclude" | xargs egrep -Hin --color "$1" | |
} | |
# Create directory and cd to it. | |
function mkcd { | |
mkdir -p "$1" && cd "$1" | |
} | |
function google { | |
open "http://www.google.com/search?q=$1" | |
} | |
. `brew --prefix`/etc/profile.d/z.sh | |
# Fun | |
alias moo="fortune | cowsay -n | lolcat"; | |
function profileme { | |
history | awk '{print $2}' | awk 'BEGIN{FS="|"}{print $1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr; | |
} | |
# Ruby Love | |
export PATH="$HOME/.rbenv/bin:/usr/local/bin:/usr/local/sbin:$PATH" | |
eval "$(rbenv init -)" |
masnun
commented
Apr 23, 2012
via email
Yes :D
…Sent from my Windows Phone
From: Rifat Nabi
Sent: 4/24/2012 12:47 AM
To: Abu Ashraf Masnun
Subject: Re: gist gist: 1254570
Did you mean 👍
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1254570
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment