ubuntu.plugin.zsh 4.7 KB

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