ubuntu.plugin.zsh 4.6 KB

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