]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/debian/debian.plugin.zsh
add xbindkeysrc
[dotfiles.git] / zsh / plugins / debian / debian.plugin.zsh
1 # Authors:
2 # https://github.com/AlexBio
3 # https://github.com/dbb
4 #
5 # Debian-related zsh aliases and functions for zsh
6
7 # Use aptitude if installed, or apt-get if not.
8 # You can just set apt_pref='apt-get' to override it.
9 if [[ -e $( which aptitude 2>&1 ) ]]; then
10 apt_pref='aptitude'
11 else
12 apt_pref='apt-get'
13 fi
14
15 # Use sudo by default if it's installed
16 if [[ -e $( which sudo 2>&1 ) ]]; then
17 use_sudo=1
18 fi
19
20 # Aliases ###################################################################
21 # These are for more obscure uses of apt-get and aptitude that aren't covered
22 # below.
23 alias ag='apt-get'
24 alias ap='aptitude'
25
26 # Some self-explanatory aliases
27 alias acs="apt-cache search"
28 alias aps='aptitude search'
29 alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
30 --no-gui --disable-columns search" # search package
31
32 # apt-file
33 alias afs='apt-file search --regexp'
34
35
36 # These are apt-get only
37 alias asrc='apt-get source'
38 alias app='apt-cache policy'
39
40 # superuser operations ######################################################
41 if [[ $use_sudo -eq 1 ]]; then
42 # commands using sudo #######
43 alias aac='sudo $apt_pref autoclean'
44 alias abd='sudo $apt_pref build-dep'
45 alias ac='sudo $apt_pref clean'
46 alias ad='sudo $apt_pref update'
47 alias adg='sudo $apt_pref update && sudo $apt_pref upgrade'
48 alias adu='sudo $apt_pref update && sudo $apt_pref dist-upgrade'
49 alias afu='sudo apt-file update'
50 alias ag='sudo $apt_pref upgrade'
51 alias ai='sudo $apt_pref install'
52 # Install all packages given on the command line while using only the first word of each line:
53 # acs ... | ail
54 alias ail="sed -e 's/ */ /g' -e 's/ *//' | cut -s -d ' ' -f 1 | "' xargs sudo $apt_pref install'
55 alias ap='sudo $apt_pref purge'
56 alias ar='sudo $apt_pref remove'
57
58 # apt-get only
59 alias ads='sudo $apt_pref dselect-upgrade'
60
61 # Install all .deb files in the current directory.
62 # Warning: you will need to put the glob in single quotes if you use:
63 # glob_subst
64 alias dia='sudo dpkg -i ./*.deb'
65 alias di='sudo dpkg -i'
66
67 # Remove ALL kernel images and headers EXCEPT the one in use
68 alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
69 ?not(~n`uname -r`))'
70
71
72 # commands using su #########
73 else
74 alias aac='su -ls \'$apt_pref autoclean\' root'
75 abd() {
76 cmd="su -lc '$apt_pref build-dep $@' root"
77 print "$cmd"
78 eval "$cmd"
79 }
80 alias ac='su -ls \'$apt_pref clean\' root'
81 alias ad='su -lc \'$apt_pref update\' root'
82 alias adg='su -lc \'$apt_pref update && aptitude safe-upgrade\' root'
83 alias adu='su -lc \'$apt_pref update && aptitude dist-upgrade\' root'
84 alias afu='su -lc "apt-file update"'
85 alias ag='su -lc \'$apt_pref safe-upgrade\' root'
86 ai() {
87 cmd="su -lc 'aptitude -P install $@' root"
88 print "$cmd"
89 eval "$cmd"
90 }
91 ap() {
92 cmd="su -lc '$apt_pref -P purge $@' root"
93 print "$cmd"
94 eval "$cmd"
95 }
96 ar() {
97 cmd="su -lc '$apt_pref -P remove $@' root"
98 print "$cmd"
99 eval "$cmd"
100 }
101
102 # Install all .deb files in the current directory
103 # Assumes glob_subst is off
104 alias dia='su -lc "dpkg -i ./*.deb" root'
105 alias di='su -lc "dpkg -i" root'
106
107 # Remove ALL kernel images and headers EXCEPT the one in use
108 alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \
109 ?not(~n`uname -r`))'\'' root'
110 fi
111
112
113 # Misc. #####################################################################
114 # print all installed packages
115 alias allpkgs='aptitude search -F "%p" --disable-columns ~i'
116
117 # Create a basic .deb package
118 alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
119
120
121 # Functions #################################################################
122 # create a simple script that can be used to 'duplicate' a system
123 apt-copy() {
124 print '#!/bin/sh'"\n" > apt-copy.sh
125
126 cmd='$apt_pref install'
127
128 for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {
129 cmd="${cmd} ${p}"
130 }
131
132 print $cmd "\n" >> apt-copy.sh
133
134 chmod +x apt-copy.sh
135 }
136
137 # Prints apt history
138 # Usage:
139 # apt-history install
140 # apt-history upgrade
141 # apt-history remove
142 # apt-history rollback
143 # apt-history list
144 # Based On: http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
145 apt-history () {
146 case "$1" in
147 install)
148 zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
149 ;;
150 upgrade|remove)
151 zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
152 ;;
153 rollback)
154 zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
155 grep "$2" -A10000000 | \
156 grep "$3" -B10000000 | \
157 awk '{print $4"="$5}'
158 ;;
159 list)
160 zcat $(ls -rt /var/log/dpkg*)
161 ;;
162 *)
163 echo "Parameters:"
164 echo " install - Lists all packages that have been installed."
165 echo " upgrade - Lists all packages that have been upgraded."
166 echo " remove - Lists all packages that have been removed."
167 echo " rollback - Lists rollback information."
168 echo " list - Lists all contains of dpkg logs."
169 ;;
170 esac
171 }
172
173 # Kernel-package building shortcut
174 kerndeb () {
175 # temporarily unset MAKEFLAGS ( '-j3' will fail )
176 MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
177 print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
178 appendage='-custom' # this shows up in $ (uname -r )
179 revision=$(date +"%Y%m%d") # this shows up in the .deb file name
180
181 make-kpkg clean
182
183 time fakeroot make-kpkg --append-to-version "$appendage" --revision \
184 "$revision" kernel_image kernel_headers
185 }
186