a66d09403f70cf820155f2b263967b9f8e8b4496
[zsh.git] / .zsh / 35_Aliases.zsh
1 # -*- mode: sh;-*-
2
3 # default switches
4 if ls --help 2>/dev/null | grep -q GNU; then
5 alias ls='command ls -AF --color=auto'
6 elif isdarwin || isfreebsd; then
7 alias ls='command ls -AF -G'
8 fi
9
10 alias lsbig='command ls -flh *(.OL[1,10])' # display the biggest files
11 alias lssmall='command ls -Srl *(.oL[1,10])' # display the smallest files
12 alias lsnew='command ls -rl *(D.om[1,10])' # display the newest files
13 alias lsold='command ls -rtlh *(D.om[-11,-1])' # display the oldest files
14
15 alias mv='command mv -i'
16 alias mmv='noglob mmv'
17 alias cp='command cp -i'
18 alias wget='noglob wget'
19 alias cgrep='grep --color'
20 alias git='git'
21 alias rot13='tr a-zA-Z n-za-mN-ZA-M'
22 alias scp='noglob scp'
23
24 is-callable psql && alias psql='LD_PRELOAD=/lib/libreadline.so.5 psql'
25
26 alias logout='noglob logout'
27
28 # want to trace a shell function? ztrace $FUNCTIONNAME and there it goes.
29 alias ztrace='typeset -f -t'
30 alias zuntrace='typeset -f +t'
31
32 # overwrite cal
33 alias cal='cal -3'
34
35 # convenient abbreviations
36 alias c=clear
37
38 alias d='dirs -v'
39
40 alias cd/='cd /'
41 alias ..='cd ..'
42 alias ...='cd ../..'
43 alias cd..='cd ..'
44 alias cd...='cd ../..'
45 alias cd....='cd ../../..'
46 alias cd.....='cd ../../../..'
47 alias -- -='cd -'
48 for index ({1..9}) alias "$index"="cd -${index}"; unset index
49
50 alias mc='mc -d -U'
51 alias cpan='perl -MCPAN -e shell'
52 alias rh='run-help'
53
54 # No spellchecks here
55 alias man='nocorrect noglob man'
56 alias mysql='nocorrect mysql'
57 alias mkdir='nocorrect mkdir'
58 alias mv='nocorrect mv'
59
60 if [ -x /usr/bin/recode ]; then
61 alias unix2dos='recode lat1..ibmpc'
62 alias dos2unix='recode ibmpc..lat1'
63 fi
64
65 # used when you press M-? on a command line
66 alias which-command='whence -a'
67
68 # zsh function tracing
69 alias ztrace='typeset -f -t'
70 alias zuntrace='typeset -f +t'
71
72 # Make popd changes permanent without having to wait for logout
73 if zstyle -T ':ganneff:config' dirstackhandling dirpersist dirstack; then
74 alias popd="popd;dirpersiststore"
75 fi
76
77 # git related
78 # Aliases
79 alias g='git'
80
81 # branch related
82 #a# git branch base
83 alias gb='git branch'
84 #a# create a branch and switch to it
85 alias gbc='git checkout -b'
86 #a# show details for git branches
87 alias gbl='git branch -v'
88 #a# show details for git branches incl. remotes
89 alias gbL='git branch -av'
90 alias gba='git branch -av'
91 #a# delete git branch
92 alias gbx='git branch -d'
93 #a# Move/rename a branch
94 alias gbm='git branch -m'
95
96 # commit
97 #a# commit changes in git
98 alias gc='git commit -v'
99 #a# commit anything changed
100 alias gca='git commit -v -a'
101 #a# amend last git commit
102 alias gca='git commit -v --amend'
103 #a# revert a commit
104 alias gcr='git revert'
105
106 #a# cherry-pick
107 alias gcp='git cherry-pick'
108
109 alias ga='git add'
110 alias gap='git add --patch'
111 alias gau='git add --update'
112
113 alias grh='git reset HEAD'
114 alias grhh='git reset HEAD --hard'
115
116 # clone/pull/fetch/push
117 #a# fetch and merge from another repository (pull)
118 alias gl='git pull'
119 #a# fetch and rebase from another repository
120 alias gup='git pull --rebase'
121 #a# fetch another repository
122 alias gf='git fetch'
123 #a# clone another repository
124 alias gcl='git clone'
125 #a# push changes
126 alias gp='git push'
127 #a# push everything to origin
128 alias gpoat='git push origin --all && git push origin --tags'
129
130 # remotes
131 alias gr='git remote'
132 alias grv='git remote -v'
133 alias grmv='git remote rename'
134 alias grrm='git remote remove'
135 alias grset='git remote set-url'
136 alias grup='git remote update'
137
138 alias gcs='git show'
139 alias gcR='git reset "HEAD^"'
140 alias gco='git checkout'
141 alias gcO='git checkout --patch'
142 alias gm='git merge'
143
144 alias gst='git status'
145 alias gss='git status -s'
146
147 alias gd='git diff'
148 alias gdc='git diff --cached'
149
150 alias gco='git checkout'
151 alias gcm='git checkout master'
152 alias gcount='git shortlog -sn'
153 alias glg='git log --stat --max-count=5'
154 alias glgg='git log --graph --max-count=5'
155 alias glgga='git log --graph --decorate --all'
156 alias gcfl='git config --list'
157 alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
158 alias gf='git ls-files | grep'
159 alias gg='git grep'
160
161 # Will cd into the top of the current repository
162 # or submodule.
163 alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
164
165 alias gsr='git svn rebase'
166 alias gsd='git svn dcommit'
167
168 # Will return the current branch name
169 # Usage example: git pull origin $(current_branch)
170 #
171 current_branch() {
172 ref=$(git symbolic-ref HEAD 2> /dev/null) || \
173 ref=$(git rev-parse --short HEAD 2> /dev/null) || return
174 echo ${ref#refs/heads/}
175 }
176
177 current_repository() {
178 ref=$(git symbolic-ref HEAD 2> /dev/null) || \
179 ref=$(git rev-parse --short HEAD 2> /dev/null) || return
180 echo $(git remote -v | cut -d':' -f 2)
181 }
182
183 # these aliases take advantage of the previous function
184 alias ggpull='git pull origin $(current_branch)'
185 alias ggpush='git push origin $(current_branch)'
186 alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
187
188
189 ## global aliases. Handle with care!
190 alias -g LS='| less'
191 alias -g LL="|& less"
192 alias -g WC='| wc -l'
193 alias -g SO='| sort'
194 alias -g CD='| colordiff | less -R'
195 alias -g NE="2> /dev/null"