ubuntu.plugin.zsh 3.6 KB

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