ubuntu.plugin.zsh 4.9 KB

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