ubuntu.plugin.zsh 4.9 KB

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