ubuntu.plugin.zsh 4.5 KB

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