ubuntu.plugin.zsh 4.6 KB

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