1 (( $+commands[apt] )) && APT=apt || APT=apt-get
3 alias acs='apt-cache search'
5 alias afs='apt-file search --regexp'
7 # These are apt/apt-get only
8 alias ags="$APT source"
10 alias acp='apt-cache policy'
12 #List all installed packages
13 alias agli='apt list --installed'
15 # List available updates only
16 alias aglu='apt list --upgradable'
18 alias acsp='apt-cache showpkg'
19 compdef _acsp acsp='apt-cache showpkg'
21 # superuser operations ######################################################
23 alias afu='sudo apt-file update'
25 alias ppap='sudo ppa-purge'
28 alias aga="sudo $APT autoclean"
29 alias agb="sudo $APT build-dep"
30 alias agc="sudo $APT clean"
31 alias agd="sudo $APT dselect-upgrade"
32 alias agi="sudo $APT install"
33 alias agp="sudo $APT purge"
34 alias agr="sudo $APT remove"
35 alias agu="sudo $APT update"
36 alias agud="sudo $APT update && sudo $APT dist-upgrade"
37 alias agug="sudo $APT upgrade"
38 alias aguu="sudo $APT update && sudo $APT upgrade"
39 alias agar="sudo $APT autoremove"
42 # Remove ALL kernel images and headers EXCEPT the one in use
43 alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'
45 # Misc. #####################################################################
46 # print all installed packages
47 alias allpkgs='dpkg --get-selections | grep -v deinstall'
49 # Create a basic .deb package
50 alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
52 # apt-add-repository with automatic install/upgrade of the desired package
53 # Usage: aar ppa:xxxxxx/xxxxxx [packagename]
54 # If packagename is not given as 2nd argument the function will ask for it and guess the default by taking
55 # the part after the / from the ppa name which is sometimes the right name for the package you want to install
60 read "PACKAGE?Type in the package name to install/upgrade with this ppa [${1##*/}]: "
63 if [ -z "$PACKAGE" ]; then
67 sudo apt-add-repository $1 && sudo $APT update
68 sudo $APT install $PACKAGE
76 # apt-history rollback
78 # Based On: https://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
79 function apt-history() {
82 zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
85 zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
88 zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
89 grep "$2" -A10000000 | \
90 grep "$3" -B10000000 | \
94 zgrep --no-filename '' $(ls -rt /var/log/dpkg*)
98 echo " install - Lists all packages that have been installed."
99 echo " upgrade - Lists all packages that have been upgraded."
100 echo " remove - Lists all packages that have been removed."
101 echo " rollback - Lists rollback information."
102 echo " list - Lists all contains of dpkg logs."
107 # Kernel-package building shortcut
109 # temporarily unset MAKEFLAGS ( '-j3' will fail )
110 MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
111 print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
112 appendage='-custom' # this shows up in $(uname -r)
113 revision=$(date +"%Y%m%d") # this shows up in the .deb file name
117 time fakeroot make-kpkg --append-to-version "$appendage" --revision \
118 "$revision" kernel_image kernel_headers
121 # List packages by size
122 function apt-list-packages {
123 dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | \
124 grep -v deinstall | \
126 awk '{print $1" "$2}'