-
-
Save davidgoldcode/fe76d6a441e5e86b9bc03f968725a75b to your computer and use it in GitHub Desktop.
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
# ------------------------------------------------------------------- | |
# use nocorrect alias to prevent auto correct from "fixing" these | |
# ------------------------------------------------------------------- | |
alias foobar='nocorrect foobar' | |
alias g8='nocorrect g8' | |
# ------------------------------------------------------------------- | |
# Ruby stuff | |
# ------------------------------------------------------------------- | |
alias ri='ri -Tf ansi' # Search Ruby documentation | |
alias rake="noglob rake" # necessary to make rake work inside of zsh | |
alias be='bundle exec' | |
alias bx='bundle exec' | |
alias gentags='ctags .' | |
# ------------------------------------------------------------------- | |
# directory movement | |
# ------------------------------------------------------------------- | |
alias cd~='cd ~' | |
alias cd..='cd ..' | |
alias ..='cd ..' | |
alias ...='cd ../..' | |
alias ....='cd ../../..' | |
alias bk='cd $OLDPWD' | |
# ------------------------------------------------------------------- | |
# directory information | |
# ------------------------------------------------------------------- | |
alias lh='ls -d .*' # show hidden files/directories only | |
alias lsd='ls -aFhlG' | |
alias l='ls -al' | |
alias ls='ls -GFh' # Colorize output, add file type indicator, and put sizes in human readable format | |
alias ll='ls -GFhl' # Same as above, but in long listing format | |
alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'" | |
alias dus='du -sckx * | sort -nr' #directories sorted by size | |
alias wordy='wc -w * | sort | tail -n10' # sort files in current directory by the number of words they contain | |
alias filecount='find . -type f | wc -l' # number of files (not directories) | |
# ------------------------------------------------------------------- | |
# Mac only | |
# ------------------------------------------------------------------- | |
if [[ $IS_MAC -eq 1 ]]; then | |
alias ql='qlmanage -p 2>/dev/null' # OS X Quick Look | |
alias oo='open .' # open current directory in OS X Finder | |
alias today='calendar -A 0 -f /usr/share/calendar/calendar.mark | sort' | |
alias mailsize='du -hs ~/Library/mail' | |
alias smart='diskutil info disk0 | grep SMART' # display SMART status of hard drive | |
# Hall of the Mountain King | |
alias cello='say -v cellos "di di di di di di di di di di di di di di di di di di di di di di di di di di"' | |
# alias to show all Mac App store apps | |
alias apps='mdfind "kMDItemAppStoreHasReceipt=1"' | |
# reset Address Book permissions in Mountain Lion (and later presumably) | |
alias resetaddressbook='tccutil reset AddressBook' | |
# refresh brew by upgrading all outdated casks | |
alias freshbrew='brew outdated | while read cask; do brew upgrade $cask; done' | |
alias newbrew='brew install' | |
# rebuild Launch Services to remove duplicate entries on Open With menu | |
alias rebuildopenwith='/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.fram ework/Support/lsregister -kill -r -domain local -domain system -domain user' | |
fi | |
# ------------------------------------------------------------------- | |
# remote machines | |
# ------------------------------------------------------------------- | |
alias rb='ssh butlerx@pyg.redbrick.dcu.ie' | |
#alias rbvm ='ssh -L 5900:136.206.16.1:5913 butlerx@login.redbrick.dcu.ie' | |
alias home='ssh 109.255.32.18 -p 1337' | |
alias dcu='ssh -X butlec25@student.computing.dcu.ie' | |
alias oracle='ssh butlerx@45.55.6.41' | |
# ------------------------------------------------------------------- | |
# database | |
# ------------------------------------------------------------------- | |
alias psqlstart='/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start' | |
alias psqlstop='/usr/local/pgsql/bin/pg_ctl stop' | |
alias mysql='mysql -u butlerx' | |
alias mysqladmin='mysqladmin -u root' | |
# ------------------------------------------------------------------- | |
# Mercurial (hg) | |
# ------------------------------------------------------------------- | |
alias h='hg status' | |
alias hc='hg commit' | |
alias push='hg push' | |
alias pull='hg pull' | |
alias clone='hg clone' | |
# ------------------------------------------------------------------- | |
# Git | |
# ------------------------------------------------------------------- | |
alias ga='git add' | |
alias gp='git push' | |
alias gl='git log' | |
alias gpl="git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" | |
alias gs='git status' | |
alias gd='git diff' | |
alias gm='git commit -m' | |
alias gma='git commit -am' | |
alias gb='git branch' | |
alias gc='git checkout' | |
alias gcb='git checkout -b' | |
alias gra='git remote add' | |
alias grr='git remote rm' | |
alias gpu='git pull' | |
alias gcl='git clone' | |
alias gta='git tag -a -m' | |
alias gf='git reflog' | |
alias gv='git log --pretty=format:'%s' | cut -d " " -f 1 | sort | uniq -c | sort -nr' | |
# leverage aliases from ~/.gitconfig | |
alias gh='git hist' | |
alias gt='git today' | |
# curiosities | |
# gsh shows the number of commits for the current repos for all developers | |
alias gsh="git shortlog | grep -E '^[ ]+\w+' | wc -l" | |
# gu shows a list of all developers and the number of commits they've made | |
alias gu="git shortlog | grep -E '^[^ ]'" | |
# ------------------------------------------------------------------- | |
# Python virtualenv | |
# ------------------------------------------------------------------- | |
alias mkenv='mkvirtualenv' | |
alias pyon="workon" | |
alias pyoff="deactivate" | |
# ------------------------------------------------------------------- | |
# Oddball stuff | |
# ------------------------------------------------------------------- | |
alias sloc='/usr/local/sloccount/bin/sloccount' | |
alias adventure='emacs -batch -l dunnet' # play adventure in the console | |
alias ttop='top -ocpu -R -F -s 2 -n30' # fancy top | |
alias rm='rm -i' # make rm command (potentially) less destructive | |
# Force tmux to use 256 colors | |
alias tmux='TERM=screen-256color-bce tmux' | |
# alias to cat this file to display | |
alias acat='< ~/.zsh/aliases.zsh' | |
alias fcat='< ~/.zsh/functions.zsh' | |
alias sz='source ~/.zshrc' | |
# ------------------------------------------------------------------- | |
# some Octopress helpers | |
# ------------------------------------------------------------------- | |
alias generate='date ; rake generate ; date ;' | |
alias gen='date ; rake generate ; date ;' | |
alias ingen='date ; rake integrate ; generate ; date ;' | |
alias deploy='rm deploy.log ; rake deploy > deploy.log ; tail -n 3 deploy.log ;' | |
alias np='newpost.rb' | |
# copy .htaccess files for zanshin.net and its image sub-directory | |
alias htaccess='scp /Users/mark/Projects/octopress/zanshin/source/htaccess/.htaccess markn@markn.webfactional.com:~/webapps/zanshin ; scp /Users/mark/Projects/octopress/zanshin/source/images/.htaccess markn@markn.webfactional.com:~/webapps/zanshin/images ;' | |
# deploy zanshin.net and move its .htaccess files | |
alias dz='deploy ; htaccess ;' | |
# ------------------------------------------------------------------- | |
# Source: http://aur.archlinux.org/packages/lolbash/lolbash/lolbash.sh | |
# ------------------------------------------------------------------- | |
alias wtf='dmesg' | |
alias onoz='cat /var/log/errors.log' | |
alias rtfm='man' | |
alias visible='echo' | |
alias invisible='cat' | |
alias moar='more' | |
alias icanhas='mkdir' | |
alias donotwant='rm' | |
alias dowant='cp' | |
alias gtfo='mv' | |
alias hai='cd' | |
alias plz='pwd' | |
alias inur='locate' | |
alias nomz='ps aux | less' | |
alias nomnom='killall' | |
alias cya='reboot' | |
alias kthxbai='halt' | |
# ------------------------------------------------------------------- | |
# Linux only | |
# ------------------------------------------------------------------- | |
if [[ $IS_LINUX -eq 1 ]]; then | |
alias brew='sudo apt-get' | |
alias freshbrew='sudo apt-get update' | |
alias newbrew='sudo apt-get install' | |
fi | |
alias cl='clear' | |
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
# To see the key combo you want to use just do: | |
# cat > /dev/null | |
# And press it | |
bindkey "^K" kill-whole-line # ctrl-k | |
bindkey "^R" history-incremental-search-backward # ctrl-r | |
bindkey "^A" beginning-of-line # ctrl-a | |
bindkey "^E" end-of-line # ctrl-e | |
bindkey "[B" history-search-forward # down arrow | |
bindkey "[A" history-search-backward # up arrow | |
bindkey "^D" delete-char # ctrl-d | |
bindkey "^F" forward-char # ctrl-f | |
bindkey "^B" backward-char # ctrl-b | |
bindkey -v # Default to standard vi bindings, regardless of editor string |
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
# checks (stolen from zshuery) | |
if [[ $(uname) = 'Linux' ]]; then | |
IS_LINUX=1 | |
fi | |
if [[ $(uname) = 'Darwin' ]]; then | |
IS_MAC=1 | |
fi | |
if [[ -x `which brew` ]]; then | |
HAS_BREW=1 | |
fi | |
if [[ -x `which apt-get` ]]; then | |
HAS_APT=1 | |
fi | |
if [[ -x `which yum` ]]; then | |
HAS_YUM=1 | |
fi |
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
autoload colors; colors | |
# The variables are wrapped in \%\{\%\}. This should be the case for every | |
# variable that does not contain space. | |
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do | |
eval PR_$COLOR='%{$fg_no_bold[${(L)COLOR}]%}' | |
eval PR_BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}' | |
done | |
eval RESET='$reset_color' | |
export PR_RED PR_GREEN PR_YELLOW PR_BLUE PR_WHITE PR_BLACK | |
export PR_BOLD_RED PR_BOLD_GREEN PR_BOLD_YELLOW PR_BOLD_BLUE | |
export PR_BOLD_WHITE PR_BOLD_BLACK | |
# Clear LSCOLORS | |
unset LSCOLORS | |
# Main change, you can see directories on a dark background | |
#expor tLSCOLORS=gxfxcxdxbxegedabagacad | |
export CLICOLOR=1 | |
export LS_COLORS=exfxcxdxbxegedabagacad |
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
autoload -U compinit && compinit | |
zmodload -i zsh/complist | |
# man zshcontrib | |
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' | |
zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f ' | |
zstyle ':vcs_info:*' enable git #svn cvs | |
# Enable completion caching, use rehash to clear | |
zstyle ':completion::complete:*' use-cache on | |
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST | |
# Fallback to built in ls colors | |
zstyle ':completion:*' list-colors '' | |
# Make the list prompt friendly | |
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s' | |
# Make the selection prompt friendly when there are a lot of choices | |
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' | |
# Add simple colors to kill | |
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' | |
# list of completers to use | |
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate | |
zstyle ':completion:*' menu select=1 _complete _ignored _approximate | |
# insert all expansions for expand completer | |
# zstyle ':completion:*:expand:*' tag-order all-expansions | |
# match uppercase from lowercase | |
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' | |
# offer indexes before parameters in subscripts | |
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters | |
# formatting and messages | |
zstyle ':completion:*' verbose yes | |
zstyle ':completion:*:descriptions' format '%B%d%b' | |
zstyle ':completion:*:messages' format '%d' | |
zstyle ':completion:*:warnings' format 'No matches for: %d' | |
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b' | |
zstyle ':completion:*' group-name '' | |
# ignore completion functions (until the _ignored completer) | |
zstyle ':completion:*:functions' ignored-patterns '_*' | |
zstyle ':completion:*:scp:*' tag-order files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *' | |
zstyle ':completion:*:scp:*' group-order files all-files users hosts-domain hosts-host hosts-ipaddr | |
zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *' | |
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr | |
zstyle '*' single-ignored show |
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
# Currently this path is appended to dynamically when picking a ruby version | |
# zshenv has already started PATH with rbenv so append only here | |
export PATH=$PATH~/bin:/usr/local/bin:/usr/local/sbin:~/bin | |
# Set default console Java to 1.6 | |
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home | |
# Setup terminal, and turn on colors | |
export TERM=xterm-256color | |
export CLICOLOR=1 | |
export LSCOLORS=Gxfxcxdxbxegedabagacad | |
# Enable color in grep | |
export GREP_OPTIONS='--color=auto' | |
export GREP_COLOR='3;33' | |
# This resolves issues install the mysql, postgres, and other gems with native non universal binary extensions | |
export ARCHFLAGS='-arch x86_64' | |
export LESS='--ignore-case --raw-control-chars' | |
export PAGER='less' | |
export EDITOR='vim' | |
#export NODE_PATH=/opt/github/homebrew/lib/node_modules | |
#export PYTHONPATH=/usr/local/lib/python2.6/site-packages | |
# CTAGS Sorting in VIM/Emacs is better behaved with this in place | |
export LC_COLLATE=C | |
#export GH_ISSUE_CREATE_TOKEN=083f60c674d8eb41f98258df9fc8d94cb733218a | |
# Virtual Environment Stuff | |
export WORKON_HOME=$HOME/.virtualenvs | |
export PROJECT_HOME=$HOME/Projects/django | |
#source /usr/local/bin/virtualenvwrapper.sh |
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
# ------------------------------------------------------------------- | |
# compressed file expander | |
# (from https://github.com/myfreeweb/zshuery/blob/master/zshuery.sh) | |
# ------------------------------------------------------------------- | |
ex() { | |
if [[ -f $1 ]]; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1;; | |
*.tar.gz) tar xvzf $1;; | |
*.tar.xz) tar xvJf $1;; | |
*.tar.lzma) tar --lzma xvf $1;; | |
*.bz2) bunzip $1;; | |
*.rar) unrar $1;; | |
*.gz) gunzip $1;; | |
*.tar) tar xvf $1;; | |
*.tbz2) tar xvjf $1;; | |
*.tgz) tar xvzf $1;; | |
*.zip) unzip $1;; | |
*.Z) uncompress $1;; | |
*.7z) 7z x $1;; | |
*.dmg) hdiutul mount $1;; # mount OS X disk images | |
*) echo "'$1' cannot be extracted via >ex<";; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# ------------------------------------------------------------------- | |
# any function from http://onethingwell.org/post/14669173541/any | |
# search for running processes | |
# ------------------------------------------------------------------- | |
any() { | |
emulate -L zsh | |
unsetopt KSH_ARRAYS | |
if [[ -z "$1" ]] ; then | |
echo "any - grep for process(es) by keyword" >&2 | |
echo "Usage: any " >&2 ; return 1 | |
else | |
ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}" | |
fi | |
} | |
# ------------------------------------------------------------------- | |
# display a neatly formatted path | |
# ------------------------------------------------------------------- | |
path() { | |
echo $PATH | tr ":" "\n" | \ | |
awk "{ sub(\"/usr\", \"$fg_no_bold[green]/usr$reset_color\"); \ | |
sub(\"/bin\", \"$fg_no_bold[blue]/bin$reset_color\"); \ | |
sub(\"/opt\", \"$fg_no_bold[cyan]/opt$reset_color\"); \ | |
sub(\"/sbin\", \"$fg_no_bold[magenta]/sbin$reset_color\"); \ | |
sub(\"/local\", \"$fg_no_bold[yellow]/local$reset_color\"); \ | |
print }" | |
} | |
# ------------------------------------------------------------------- | |
# Mac specific functions | |
# ------------------------------------------------------------------- | |
if [[ $IS_MAC -eq 1 ]]; then | |
# view man pages in Preview | |
pman() { ps=`mktemp -t manpageXXXX`.ps ; man -t $@ > "$ps" ; open "$ps" ; } | |
# function to show interface IP assignments | |
ips() { foo=`/Users/mark/bin/getip.py; /Users/mark/bin/getip.py en0; /Users/mark/bin/getip.py en1`; echo $foo; } | |
# notify function - http://hints.macworld.com/article.php?story=20120831112030251 | |
notify() { automator -D title=$1 -D subtitle=$2 -D message=$3 ~/Library/Workflows/DisplayNotification.wflow } | |
fi | |
# ------------------------------------------------------------------- | |
# nice mount (http://catonmat.net/blog/another-ten-one-liners-from-commandlingfu-explained) | |
# displays mounted drive information in a nicely formatted manner | |
# ------------------------------------------------------------------- | |
function nicemount() { (echo "DEVICE PATH TYPE FLAGS" && mount | awk '$2="";1') | column -t ; } | |
# ------------------------------------------------------------------- | |
# myIP address | |
# ------------------------------------------------------------------- | |
function myip() { | |
ifconfig lo0 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "lo0 : " $2}' | |
ifconfig en0 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "en0 (IPv4): " $2 " " $3 " " $4 " " $5 " " $6}' | |
ifconfig en0 | grep 'inet6 ' | sed -e 's/ / /' | awk '{print "en0 (IPv6): " $2 " " $3 " " $4 " " $5 " " $6}' | |
ifconfig en1 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "en1 (IPv4): " $2 " " $3 " " $4 " " $5 " " $6}' | |
ifconfig en1 | grep 'inet6 ' | sed -e 's/ / /' | awk '{print "en1 (IPv6): " $2 " " $3 " " $4 " " $5 " " $6}' | |
} | |
# ------------------------------------------------------------------- | |
# (s)ave or (i)nsert a directory. | |
# ------------------------------------------------------------------- | |
s() { pwd > ~/.save_dir ; } | |
i() { cd "$(cat ~/.save_dir)" ; } | |
# ------------------------------------------------------------------- | |
# console function | |
# ------------------------------------------------------------------- | |
function console () { | |
if [[ $# > 0 ]]; then | |
query=$(echo "$*"|tr -s ' ' '|') | |
tail -f /var/log/system.log|grep -i --color=auto -E "$query" | |
else | |
tail -f /var/log/system.log | |
fi | |
} | |
# ------------------------------------------------------------------- | |
# shell function to define words | |
# http://vikros.tumblr.com/post/23750050330/cute-little-function-time | |
# ------------------------------------------------------------------- | |
givedef() { | |
if [[ $# -ge 2 ]] then | |
echo "givedef: too many arguments" >&2 | |
return 1 | |
else | |
curl "dict://dict.org/d:$1" | |
fi | |
} |
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
# HISTORY | |
HISTSIZE=10000 | |
SAVEHIST=9000 | |
HISTFILE=~/.zsh_history |
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
function virtualenv_info { | |
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' | |
} | |
function prompt_char { | |
git branch >/dev/null 2>/dev/null && echo '>' && return | |
hg root >/dev/null 2>/dev/null && echo '~>'&& return | |
echo '>' | |
} | |
function box_name { | |
[ -f ~/.box-name ] && cat ~/.box-name || hostname -s | |
} | |
# http://blog.joshdick.net/2012/12/30/my_git_prompt_for_zsh.html | |
# copied from https://gist.github.com/4415470 | |
# Adapted from code found at <https://gist.github.com/1712320>. | |
#setopt promptsubst | |
autoload -U colors && colors # Enable colors in prompt | |
# Modify the colors and symbols in these variables as desired. | |
GIT_PROMPT_SYMBOL="%{$fg[blue]%}±" | |
GIT_PROMPT_PREFIX="%{$fg[green]%} [%{$reset_color%}" | |
GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}" | |
GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}" | |
GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}" | |
GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}" | |
GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}u%{$reset_color%}" | |
GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}d%{$reset_color%}" | |
GIT_PROMPT_STAGED="%{$fg_bold[green]%}s%{$reset_color%}" | |
# Show Git branch/tag, or name-rev if on detached head | |
function parse_git_branch() { | |
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null | |
} | |
# Show different symbols as appropriate for various Git repository states | |
function parse_git_state() { | |
# Compose this value via multiple conditional appends. | |
local GIT_STATE="" | |
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')" | |
if [ "$NUM_AHEAD" -gt 0 ]; then | |
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD} | |
fi | |
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')" | |
if [ "$NUM_BEHIND" -gt 0 ]; then | |
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND} | |
fi | |
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)" | |
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING | |
fi | |
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED | |
fi | |
if ! git diff --quiet 2> /dev/null; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED | |
fi | |
if ! git diff --cached --quiet 2> /dev/null; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED | |
fi | |
if [[ -n $GIT_STATE ]]; then | |
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" | |
fi | |
} | |
# If inside a Git repository, print its branch and state | |
function git_prompt_string() { | |
local git_where="$(parse_git_branch)" | |
[ -n "$git_where" ] && echo "on %{$fg[blue]%}${git_where#(refs/heads/|tags/)}$(parse_git_state)" | |
} | |
# determine Ruby version whether using RVM or rbenv | |
# the chpwd_functions line cause this to update only when the directory changes | |
function _update_ruby_version() { | |
typeset -g ruby_version='' | |
if which rvm-prompt &> /dev/null; then | |
ruby_version="$(rvm-prompt i v g)" | |
else | |
if which rbenv &> /dev/null; then | |
ruby_version="$(rbenv version | sed -e "s/ (set.*$//")" | |
fi | |
fi | |
} | |
chpwd_functions+=(_update_ruby_version) | |
function current_pwd { | |
echo $(pwd | sed -e "s,^$HOME,~,") | |
} | |
PROMPT=' | |
${PR_GREEN}%n%{$reset_color%}%{$FG[239]%}@%{$reset_color%}${PR_BOLD_BLUE}$(box_name)%{$reset_color%}%{$FG[239]%}: %{$reset_color%} ${PR_BOLD_YELLOW}$(current_pwd)%{$reset_color%} $(git_prompt_string)$(prompt_char) ' | |
export SPROMPT="Correct $fg[red]%R$reset_color to $fg[green]%r$reset_color [(y)es (n)o (a)bort (e)dit]? " | |
RPROMPT='${PR_GREEN}$(virtualenv_info)%{$reset_color%} ${PR_RED}${ruby_version}%{$reset_color%}' |
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
function virtualenv_info { | |
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' | |
} | |
function prompt_char { | |
git branch >/dev/null 2>/dev/null && echo ' && return | |
hg root >/dev/null 2>/dev/null && echo '☿' && return | |
echo '○' | |
} | |
function box_name { | |
[ -f ~/.box-name ] && cat ~/.box-name || hostname -s | |
} | |
# http://blog.joshdick.net/2012/12/30/my_git_prompt_for_zsh.html | |
# copied from https://gist.github.com/4415470 | |
# Adapted from code found at <https://gist.github.com/1712320>. | |
#setopt promptsubst | |
autoload -U colors && colors # Enable colors in prompt | |
# Modify the colors and symbols in these variables as desired. | |
GIT_PROMPT_SYMBOL="%{$fg[blue]%}±" | |
GIT_PROMPT_PREFIX="%{$fg[green]%} [%{$reset_color%}" | |
GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}" | |
GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}" | |
GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}" | |
GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}" | |
GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}u%{$reset_color%}" | |
GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}d%{$reset_color%}" | |
GIT_PROMPT_STAGED="%{$fg_bold[green]%}s%{$reset_color%}" | |
# Show Git branch/tag, or name-rev if on detached head | |
function parse_git_branch() { | |
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null | |
} | |
# Show different symbols as appropriate for various Git repository states | |
function parse_git_state() { | |
# Compose this value via multiple conditional appends. | |
local GIT_STATE="" | |
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')" | |
if [ "$NUM_AHEAD" -gt 0 ]; then | |
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD} | |
fi | |
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')" | |
if [ "$NUM_BEHIND" -gt 0 ]; then | |
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND} | |
fi | |
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)" | |
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING | |
fi | |
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED | |
fi | |
if ! git diff --quiet 2> /dev/null; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED | |
fi | |
if ! git diff --cached --quiet 2> /dev/null; then | |
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED | |
fi | |
if [[ -n $GIT_STATE ]]; then | |
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" | |
fi | |
} | |
# If inside a Git repository, print its branch and state | |
function git_prompt_string() { | |
local git_where="$(parse_git_branch)" | |
[ -n "$git_where" ] && echo "on %{$fg[blue]%}${git_where#(refs/heads/|tags/)}$(parse_git_state)" | |
} | |
# determine Ruby version whether using RVM or rbenv | |
# the chpwd_functions line cause this to update only when the directory changes | |
function _update_ruby_version() { | |
typeset -g ruby_version='' | |
if which rvm-prompt &> /dev/null; then | |
ruby_version="$(rvm-prompt i v g)" | |
else | |
if which rbenv &> /dev/null; then | |
ruby_version="$(rbenv version | sed -e "s/ (set.*$//")" | |
fi | |
fi | |
} | |
chpwd_functions+=(_update_ruby_version) | |
function current_pwd { | |
echo $(pwd | sed -e "s,^$HOME,~,") | |
} | |
PROMPT=' | |
${PR_GREEN}%n%{$reset_color%}%{$FG[239]%}@%{$reset_color%}${PR_BOLD_BLUE}$(box_name)%{$reset_color%}%{$FG[239]%}: %{$reset_color%} ${PR_BOLD_YELLOW}$(current_pwd)%{$reset_color%} $(git_prompt_string)$(prompt_char) ' | |
export SPROMPT="Correct $fg[red]%R$reset_color to $fg[green]%r$reset_color [(y)es (n)o (a)bort (e)dit]? " | |
RPROMPT='${PR_GREEN}$(virtualenv_info)%{$reset_color%} ${PR_RED}${ruby_version}%{$reset_color%}' |
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
# ===== Basics | |
setopt no_beep # don't beep on error | |
setopt interactive_comments # Allow comments even in interactive shells (especially for Muness) | |
# ===== Changing Directories | |
setopt auto_cd # If you type foo, and it isn't a command, and it is a directory in your cdpath, go there | |
setopt cdablevarS # if argument to cd is the name of a parameter whose value is a valid directory, it will become the current directory | |
setopt pushd_ignore_dups # don't push multiple copies of the same directory onto the directory stack | |
# ===== Expansion and Globbing | |
setopt extended_glob # treat #, ~, and ^ as part of patterns for filename generation | |
# ===== History | |
setopt append_history # Allow multiple terminal sessions to all append to one zsh command history | |
setopt extended_history # save timestamp of command and duration | |
setopt inc_append_history # Add comamnds as they are typed, don't wait until shell exit | |
setopt hist_expire_dups_first # when trimming history, lose oldest duplicates first | |
setopt hist_ignore_dups # Do not write events to history that are duplicates of previous events | |
setopt hist_ignore_space # remove command line from history list when first character on the line is a space | |
setopt hist_find_no_dups # When searching history don't display results already cycled through twice | |
setopt hist_reduce_blanks # Remove extra blanks from each command line being added to history | |
setopt hist_verify # don't execute, just expand history | |
setopt share_history # imports new commands and appends typed commands to history | |
# ===== Completion | |
setopt always_to_end # When completing from the middle of a word, move the cursor to the end of the word | |
setopt auto_menu # show completion menu on successive tab press. needs unsetop menu_complete to work | |
setopt auto_name_dirs # any parameter that is set to the absolute name of a directory immediately becomes a name for that directory | |
setopt complete_in_word # Allow completion from within a word/phrase | |
unsetopt menu_complete # do not autoselect the first completion entry | |
# ===== Correction | |
setopt correct # spelling correction for commands | |
setopt correctall # spelling correction for arguments | |
# ===== Prompt | |
setopt prompt_subst # Enable parameter expansion, command substitution, and arithmetic expansion in the prompt | |
setopt transient_rprompt # only show the rprompt on the current prompt | |
# ===== Scripts and Functions | |
setopt multios # perform implicit tees or cats when multiple redirections are attempted |
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
function precmd { | |
# vcs_info | |
# Put the string "hostname::/full/directory/path" in the title bar: | |
echo -ne "\e]2;$PWD\a" | |
# Put the parentdir/currentdir in the tab | |
echo -ne "\e]1;$PWD:h:t/$PWD:t\a" | |
} | |
function set_running_app { | |
printf "\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a" | |
} | |
function preexec { | |
set_running_app | |
} | |
function postexec { | |
set_running_app | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment