Parent directory

ubuntu.plugin.zsh

3951 bytes
  1# Detect available package manager (prefer apt-fast > apt > apt-get)
  2if (( $+commands[apt-fast] )); then
  3    APT=apt-fast
  4elif (( $+commands[apt] )); then
  5    APT=apt
  6else
  7    APT=apt-get
  8fi
  9
 10alias acs='apt-cache search'
 11
 12alias afs='apt-file search --regexp'
 13
 14# These are apt/apt-get only
 15if (( $+commands[apt] )); then
 16    alias ags="apt source"
 17else
 18    alias ags="apt-get source"
 19fi
 20
 21alias acp='apt-cache policy'
 22
 23#List all installed packages
 24alias agli='apt list --installed'
 25
 26# List available updates only
 27alias aglu='apt list --upgradable'
 28
 29alias acsp='apt-cache showpkg'
 30compdef _acsp acsp='apt-cache showpkg'
 31
 32# superuser operations ######################################################
 33
 34alias afu='sudo apt-file update'
 35
 36alias ppap='sudo ppa-purge'
 37
 38alias age="sudo $APT"
 39alias aga="sudo $APT autoclean"
 40alias agb="sudo $APT build-dep"
 41alias agc="sudo $APT clean"
 42alias agd="sudo $APT dselect-upgrade"
 43alias agi="sudo $APT install"
 44alias agp="sudo $APT purge"
 45alias agr="sudo $APT remove"
 46alias agu="sudo $APT update"
 47alias agud="sudo $APT update && sudo $APT dist-upgrade"
 48alias agug="sudo $APT upgrade"
 49alias aguu="sudo $APT update && sudo $APT upgrade"
 50alias agar="sudo $APT autoremove"
 51
 52
 53# Remove ALL kernel images and headers EXCEPT the one in use
 54alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'
 55
 56# Misc. #####################################################################
 57# print all installed packages
 58alias allpkgs='dpkg --get-selections | grep -v deinstall'
 59
 60# Create a basic .deb package
 61alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
 62
 63# apt-add-repository with automatic install/upgrade of the desired package
 64# Usage: aar ppa:xxxxxx/xxxxxx [packagename]
 65# If packagename is not given as 2nd argument the function will ask for it and guess the default by taking
 66# the part after the / from the ppa name which is sometimes the right name for the package you want to install
 67function aar() {
 68	if [ -n "$2" ]; then
 69		PACKAGE=$2
 70	else
 71		read "PACKAGE?Type in the package name to install/upgrade with this ppa [${1##*/}]: "
 72	fi
 73
 74	if [ -z "$PACKAGE" ]; then
 75		PACKAGE=${1##*/}
 76	fi
 77
 78	sudo apt-add-repository $1 && sudo $APT update
 79	sudo $APT install $PACKAGE
 80}
 81
 82# Prints apt history
 83# Usage:
 84#   apt-history install
 85#   apt-history upgrade
 86#   apt-history remove
 87#   apt-history rollback
 88#   apt-history list
 89# Based On: https://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
 90function apt-history() {
 91  case "$1" in
 92    install)
 93      zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
 94      ;;
 95    upgrade|remove)
 96      zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
 97      ;;
 98    rollback)
 99      zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
100        grep "$2" -A10000000 | \
101        grep "$3" -B10000000 | \
102        awk '{print $4"="$5}'
103      ;;
104    list)
105      zgrep --no-filename '' $(ls -rt /var/log/dpkg*)
106      ;;
107    *)
108      echo "Parameters:"
109      echo " install - Lists all packages that have been installed."
110      echo " upgrade - Lists all packages that have been upgraded."
111      echo " remove - Lists all packages that have been removed."
112      echo " rollback - Lists rollback information."
113      echo " list - Lists all contains of dpkg logs."
114      ;;
115  esac
116}
117
118# Kernel-package building shortcut
119function kerndeb() {
120  # temporarily unset MAKEFLAGS ( '-j3' will fail )
121  MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
122  print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
123  appendage='-custom' # this shows up in $(uname -r)
124  revision=$(date +"%Y%m%d") # this shows up in the .deb file name
125
126  make-kpkg clean
127
128  time fakeroot make-kpkg --append-to-version "$appendage" --revision \
129      "$revision" kernel_image kernel_headers
130}
131
132# List packages by size
133function apt-list-packages {
134  dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | \
135  grep -v deinstall | \
136  sort -n | \
137  awk '{print $1" "$2}'
138}