debian.plugin.zsh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Authors:
  2. # https://github.com/AlexBio
  3. # https://github.com/dbb
  4. #
  5. # Debian-related zsh aliases and functions for zsh
  6. # Use aptitude if installed, or apt-get if not.
  7. # You can just set apt_pref='apt-get' to override it.
  8. if [[ -e $( which aptitude ) ]]; then
  9. apt_pref='aptitude'
  10. else
  11. apt_pref='apt-get'
  12. fi
  13. # Use sudo by default if it's installed
  14. if [[ -e $( which sudo ) ]]; then
  15. use_sudo=1
  16. fi
  17. # Aliases ###################################################################
  18. # These are for more obscure uses of apt-get and aptitude that aren't covered
  19. # below.
  20. alias ag='apt-get'
  21. alias at='aptitude'
  22. # Some self-explanatory aliases
  23. alias acs="apt-cache search"
  24. alias aps='aptitude search'
  25. alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
  26. --no-gui --disable-columns search" # search package
  27. # apt-file
  28. alias afs='apt-file search --regexp'
  29. # These are apt-get only
  30. alias asrc='apt-get source'
  31. alias ap='apt-cache policy'
  32. # superuser operations ######################################################
  33. if [[ $use_sudo -eq 1 ]]; then
  34. # commands using sudo #######
  35. alias aac='sudo $apt_pref autoclean'
  36. alias abd='sudo $apt_pref build-dep'
  37. alias ac='sudo $apt_pref clean'
  38. alias ad='sudo $apt_pref update'
  39. alias adg='sudo $apt_pref update && sudo $apt_pref upgrade'
  40. alias adu='sudo $apt_pref update && sudo $apt_pref dist-upgrade'
  41. alias afu='sudo apt-file update'
  42. alias ag='sudo $apt_pref upgrade'
  43. alias ai='sudo $apt_pref install'
  44. alias ap='sudo $apt_pref purge'
  45. alias ar='sudo $apt_pref remove'
  46. # apt-get only
  47. alias ads='sudo $apt_pref dselect-upgrade'
  48. # Install all .deb files in the current directory.
  49. # Warning: you will need to put the glob in single quotes if you use:
  50. # glob_subst
  51. alias di='sudo dpkg -i ./*.deb'
  52. # Remove ALL kernel images and headers EXCEPT the one in use
  53. alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
  54. ?not(~n`uname -r`))'
  55. # commands using su #########
  56. else
  57. alias aac='su -ls \'$apt_pref autoclean\' root'
  58. abd() {
  59. cmd="su -lc '$apt_pref build-dep $@' root"
  60. print "$cmd"
  61. eval "$cmd"
  62. }
  63. alias ac='su -ls \'$apt_pref clean\' root'
  64. alias ad='su -lc \'$apt_pref update\' root'
  65. alias adg='su -lc \'$apt_pref update && aptitude safe-upgrade\' root'
  66. alias adu='su -lc \'$apt_pref update && aptitude dist-upgrade\' root'
  67. alias afu='su -lc "apt-file update"'
  68. alias ag='su -lc \'$apt_pref safe-upgrade\' root'
  69. ai() {
  70. cmd="su -lc 'aptitude -P install $@' root"
  71. print "$cmd"
  72. eval "$cmd"
  73. }
  74. ap() {
  75. cmd="su -lc '$apt_pref -P purge $@' root"
  76. print "$cmd"
  77. eval "$cmd"
  78. }
  79. ar() {
  80. cmd="su -lc '$apt_pref -P remove $@' root"
  81. print "$cmd"
  82. eval "$cmd"
  83. }
  84. # Install all .deb files in the current directory
  85. # Assumes glob_subst is off
  86. alias di='su -lc "dpkg -i ./*.deb" root'
  87. # Remove ALL kernel images and headers EXCEPT the one in use
  88. alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \
  89. ?not(~n`uname -r`))'\'' root'
  90. fi
  91. # Misc. #####################################################################
  92. # print all installed packages
  93. alias allpkgs='aptitude search -F "%p" --disable-columns ~i'
  94. # Create a basic .deb package
  95. alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
  96. # Functions #################################################################
  97. # create a simple script that can be used to 'duplicate' a system
  98. apt-copy() {
  99. print '#!/bin/sh'"\n" > apt-copy.sh
  100. cmd='$apt_pref install'
  101. for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {
  102. cmd="${cmd} ${p}"
  103. }
  104. print $cmd "\n" >> apt-copy.sh
  105. chmod +x apt-copy.sh
  106. }
  107. # Prints apt history
  108. # Usage:
  109. # apt-history install
  110. # apt-history upgrade
  111. # apt-history remove
  112. # apt-history rollback
  113. # apt-history list
  114. # Based On: http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
  115. apt-history () {
  116. case "$1" in
  117. install)
  118. zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
  119. ;;
  120. upgrade|remove)
  121. zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
  122. ;;
  123. rollback)
  124. zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
  125. grep "$2" -A10000000 | \
  126. grep "$3" -B10000000 | \
  127. awk '{print $4"="$5}'
  128. ;;
  129. list)
  130. zcat $(ls -rt /var/log/dpkg*)
  131. ;;
  132. *)
  133. echo "Parameters:"
  134. echo " install - Lists all packages that have been installed."
  135. echo " upgrade - Lists all packages that have been upgraded."
  136. echo " remove - Lists all packages that have been removed."
  137. echo " rollback - Lists rollback information."
  138. echo " list - Lists all contains of dpkg logs."
  139. ;;
  140. esac
  141. }
  142. # Kernel-package building shortcut
  143. kerndeb () {
  144. # temporarily unset MAKEFLAGS ( '-j3' will fail )
  145. MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
  146. print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
  147. appendage='-custom' # this shows up in $ (uname -r )
  148. revision=$(date +"%Y%m%d") # this shows up in the .deb file name
  149. make-kpkg clean
  150. time fakeroot make-kpkg --append-to-version "$appendage" --revision \
  151. "$revision" kernel_image kernel_headers
  152. }