]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/aliases
setup.sh: Fix GNU screen Git check.
[config/dotfiles.git] / shell / aliases
1 # Aliases and similar functions which can be used by all shells (supporting
2 # them).
3
4 # Copyright (C) 2011-2012  Simon Ruderich
5 #
6 # This file is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This file is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this file.  If not, see <http://www.gnu.org/licenses/>.
18
19
20 # Shortcuts for often used programs.
21 alias c=clear
22 alias d=cd
23 alias e=elinks
24 alias g=git
25 alias l=ls
26 alias m=mutt
27 alias p=less # p for pager
28 alias s=mpc  # s for sound, m is already used
29 alias v=vim
30
31
32 # Improved ls which displays the files in columns (-C), visualizes
33 # directories, links and other special files (-F) and pages everything through
34 # less.
35 #
36 # If available use GNU ls with colorized output. If it isn't available try
37 # normal ls which needs CLICOLOR_FORCE so it displays colors when used with a
38 # pager. If none work no colors are used.
39
40 # Check if colors are available.
41 ls --color > /dev/null 2>&1
42 if [ $? -eq 0 ]; then
43     ls_color=gnu
44 else
45     ls -G > /dev/null 2>&1
46     if [ $? -eq 0 ]; then
47         ls_color=cli
48     else
49         ls_color=
50     fi
51 fi
52
53 # Main ls function, separated to prevent code duplication.
54 ls_path=`which ls`
55 my_ls() {
56     "$ls_path" -C -F "$@" 2>&1 | less
57 }
58 # Make sure there is no alias named ls as it causes problems with the
59 # following ls function on (at least) bash 4.0.35.
60 unalias ls 2> /dev/null
61 # GNU ls with colors.
62 if [ x$ls_color = xgnu ]; then
63     ls() {
64         my_ls --color "$@"
65     }
66 # Normal ls with colors.
67 elif [ x$ls_color = xcli ]; then
68     ls() {
69         CLICOLOR_FORCE=1 my_ls -G "$@"
70     }
71 # Simple ls with no colors.
72 else
73     ls() {
74         my_ls "$@"
75     }
76 fi
77 unset ls_color
78 # Helper function to list all files.
79 la() {
80     ls -a "$@"
81 }
82 # Helper function to list the files in list format with access rights, etc.
83 ll() {
84     ls -l "$@"
85 }
86 # Helper function to list all files in list format with access rights, etc.
87 lal() {
88     la -l "$@"
89 }
90
91
92 # Make going up directories simple.
93 alias ..='cd ..'
94 alias ...='cd ../..'
95 alias ....='cd ../../..'
96 alias .....='cd ../../../..'
97
98 # I sometimes confuse editor and shell, print a warning to prevent I exit the
99 # shell.
100 alias :q='echo "This is not Vim!" >&2'
101
102 # Automatically use unified diffs.
103 alias diff='diff -u'
104
105 # Display all files and use human readable sizes.
106 alias du='du -sh'
107 # Use human readable sizes.
108 alias df='df -h'
109
110 # Edit the mercurial patch queue series file for the current mercurial
111 # repository in Vim. Also change Vim's pwd to the patches directory so other
112 # patches can easily be opened.
113 alias vqs='vim -c "cd `hg root`/.hg/patches/" "`hg root`/.hg/patches/series"'
114
115 # vim: ft=sh