2 # https://github.com/AlexBio
3 # https://github.com/dbb
5 # Debian-related zsh aliases and functions for zsh
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
15 # Use sudo by default if it's installed
16 if [[ -e $( which sudo 2>&1 ) ]]; then
20 # Aliases ###################################################################
21 # These are for more obscure uses of apt-get and aptitude that aren't covered
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
33 alias afs
='apt-file search --regexp'
36 # These are apt-get only
37 alias asrc
='apt-get source'
38 alias app
='apt-cache policy'
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:
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'
59 alias ads
='sudo $apt_pref dselect-upgrade'
61 # Install all .deb files in the current directory.
62 # Warning: you will need to put the glob in single quotes if you use:
64 alias dia
='sudo dpkg -i ./*.deb'
65 alias di
='sudo dpkg -i'
67 # Remove ALL kernel images and headers EXCEPT the one in use
68 alias kclean
='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
72 # commands using su #########
74 alias aac
='su -ls \'$apt_pref autoclean\' root'
76 cmd
="su -lc '$apt_pref build-dep $@' root"
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'
87 cmd
="su -lc 'aptitude -P install $@' root"
92 cmd
="su -lc '$apt_pref -P purge $@' root"
97 cmd
="su -lc '$apt_pref -P remove $@' root"
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'
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'
113 # Misc. #####################################################################
114 # print all installed packages
115 alias allpkgs
='aptitude search -F "%p" --disable-columns ~i'
117 # Create a basic .deb package
118 alias mydeb
='time dpkg-buildpackage -rfakeroot -us -uc'
121 # Functions #################################################################
122 # create a simple script that can be used to 'duplicate' a system
124 print
'#!/bin/sh'"\n" > apt
-copy.sh
126 cmd
='$apt_pref install'
128 for p
in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {
132 print
$cmd "\n" >> apt
-copy.sh
139 # apt-history install
140 # apt-history upgrade
142 # apt-history rollback
144 # Based On: http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
148 zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
151 zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
154 zgrep --no-filename upgrade
$(ls -rt /var/log/dpkg*) | \
155 grep "$2" -A10000000 | \
156 grep "$3" -B10000000 | \
157 awk '{print $4"="$5}'
160 zcat
$(ls -rt /var/log/dpkg*)
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."
173 # Kernel-package building shortcut
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
183 time fakeroot
make-kpkg --append-to-version "$appendage" --revision \
184 "$revision" kernel_image kernel_headers