summary refs log tree commit diff
path: root/.zshrc
blob: e30f41eeeeabde262ff7ecd79712eab7a8bd6729 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Save 5000 lines of history, writing after each command, ignoring duplicates.
HISTFILE=~/.history
HISTSIZE=SAVEHIST=5000
setopt inc_append_history hist_ignore_dups

# Error if glob does not match.
setopt nomatch

# Allow comments in interactive shell.
setopt interactive_comments

# No.
unsetopt beep

# Vim line editing, eliminate escape key delay.
bindkey -v
KEYTIMEOUT=1

# Initialize completion and colors.
autoload -Uz compinit && compinit
autoload colors && colors

# Color prompt magenta over SSH.
[[ -n "$SSH_CLIENT" ]] && _prompt_ssh_color="$fg[magenta]"

# Color prompt yellow in vi normal mode.
function zle-line-init zle-keymap-select {
  _prompt_vi_color=
  [[ "$KEYMAP" == "vicmd" ]] && _prompt_vi_color="$fg[yellow]"
  zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select

# Show git branch or commit in right prompt.
_prompt_git_branch() {
  [[ -f .git/HEAD ]] || return 0
  local head
  read head < .git/HEAD
  case "$head" in
    ref:*)
      echo ":${head#*/*/}"
      ;;
    *)
      echo ":${head:0:7}"
      ;;
  esac
}

# Single colored character prompt, directory and git branch in right prompt.
setopt prompt_subst
PROMPT='%{%(?.$fg[green]$_prompt_ssh_color.$fg[red])$_prompt_vi_color%}»%{$reset_color%} '
RPROMPT='%{$fg[blue]%}%-50<…<%~%{$fg[yellow]%}$(_prompt_git_branch)%{$reset_color%}'

# Print a newline before every prompt after the first one.
_newline_precmd() { _newline_precmd() { echo } }

# Set title to directory name at prompt, prefixed with hostname over SSH. Add
# current command to title while running.
_title() {
  [[ "$TERM" =~ 'xterm' ]] && print -Pn "\e]0;$@\a"
}
[[ -n "$SSH_CLIENT" ]] && _title_host='%m:'
_title_preexec() { _title "$_title_host%1~: $1" }
_title_precmd() { _title "$_title_host%1~" }

typeset -ga preexec_functions
typeset -ga precmd_functions
preexec_functions+=(_title_preexec)
precmd_functions+=(_newline_precmd _title_precmd)

# General environment setup.
PATH=$PATH:~/.bin
export EDITOR=vim
export CLICOLOR=1 # color ls output on OS X

# Detect OS X for conditional aliases.
[[ "$OSTYPE" =~ 'darwin' ]] && alias osx=true || alias osx=false

# Color output on Linux.
osx || alias ls='ls --color'
osx || alias grep='grep --color'

# Verbose output from rm with confirmation on Linux.
osx || alias rm='rm -vI'
osx && alias rm='rm -v'

# Suppress output from Linux gvim, alias gvim to MacVim.
osx || alias gvim='gvim 2> /dev/null'
osx && alias gvim=mvim

tn() { [ -n "$1" ] && tmux new -s "$1" || tmux new }
ta() { [ -n "$1" ] && tmux attach -t "$1" || tmux attach }

alias g=git
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gca='git commit --amend'
alias gcl='git clone'
alias gco='git checkout'
alias gd='git diff'
alias gl='git log --graph --pretty=log'
alias gm='git merge'
alias gmv='git mv'
alias gp='git push'
alias gr='git rebase'
alias grc='git rebase --continue'
alias grs='git rebase --skip'
alias gra='git rebase --abort'
alias grm='git rm'
alias gs='git status -sb'
alias gsh='git show'
alias gst='git stash'
alias gt='git tag'
alias gu='git pull'
alias gf='git fetch'

alias hu=heroku

[[ -f ~/.nvm/nvm.sh ]] && source ~/.nvm/nvm.sh

if [[ -d /usr/local/share/chruby ]]; then
  source /usr/local/share/chruby/chruby.sh
  chruby ruby
fi

# Prevent red first prompt.
true