debian.plugin.zsh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 2>&1 ) ]]; 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 2>&1 ) ]]; 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 ap='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 app='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. # Install all packages given on the command line while using only the first word of each line:
  45. # acs ... | ail
  46. alias ail="sed -e 's/ */ /g' -e 's/ *//' | cut -s -d ' ' -f 1 | "' xargs sudo $apt_pref install'
  47. alias ap='sudo $apt_pref purge'
  48. alias ar='sudo $apt_pref remove'
  49. # apt-get only
  50. alias ads='sudo $apt_pref dselect-upgrade'
  51. # Install all .deb files in the current directory.
  52. # Warning: you will need to put the glob in single quotes if you use:
  53. # glob_subst
  54. alias dia='sudo dpkg -i ./*.deb'
  55. alias di='sudo dpkg -i'
  56. # Remove ALL kernel images and headers EXCEPT the one in use
  57. alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
  58. ?not(~n`uname -r`))'
  59. # commands using su #########
  60. else
  61. alias aac='su -ls \'$apt_pref autoclean\' root'
  62. abd() {
  63. cmd="su -lc '$apt_pref build-dep $@' root"
  64. print "$cmd"
  65. eval "$cmd"
  66. }
  67. alias ac='su -ls \'$apt_pref clean\' root'
  68. alias ad='su -lc \'$apt_pref update\' root'
  69. alias adg='su -lc \'$apt_pref update && aptitude safe-upgrade\' root'
  70. alias adu='su -lc \'$apt_pref update && aptitude dist-upgrade\' root'
  71. alias afu='su -lc "apt-file update"'
  72. alias ag='su -lc \'$apt_pref safe-upgrade\' root'
  73. ai() {
  74. cmd="su -lc 'aptitude -P install $@' root"
  75. print "$cmd"
  76. eval "$cmd"
  77. }
  78. ap() {
  79. cmd="su -lc '$apt_pref -P purge $@' root"
  80. print "$cmd"
  81. eval "$cmd"
  82. }
  83. ar() {
  84. cmd="su -lc '$apt_pref -P remove $@' root"
  85. print "$cmd"
  86. eval "$cmd"
  87. }
  88. # Install all .deb files in the current directory
  89. # Assumes glob_subst is off
  90. alias dia='su -lc "dpkg -i ./*.deb" root'
  91. alias di='su -lc "dpkg -i" root'
  92. # Remove ALL kernel images and headers EXCEPT the one in use
  93. alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \
  94. ?not(~n`uname -r`))'\'' root'
  95. fi
  96. # Misc. #####################################################################
  97. # print all installed packages
  98. alias allpkgs='aptitude search -F "%p" --disable-columns ~i'
  99. # Create a basic .deb package
  100. alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
  101. # Functions #################################################################
  102. # create a simple script that can be used to 'duplicate' a system
  103. apt-copy() {
  104. print '#!/bin/sh'"\n" > apt-copy.sh
  105. cmd='$apt_pref install'
  106. for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {
  107. cmd="${cmd} ${p}"
  108. }
  109. print $cmd "\n" >> apt-copy.sh
  110. chmod +x apt-copy.sh
  111. }
  112. # Prints apt history
  113. # Usage:
  114. # apt-history install
  115. # apt-history upgrade
  116. # apt-history remove
  117. # apt-history rollback
  118. # apt-history list
  119. # Based On: http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
  120. apt-history () {
  121. case "$1" in
  122. install)
  123. zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
  124. ;;
  125. upgrade|remove)
  126. zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
  127. ;;
  128. rollback)
  129. zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
  130. grep "$2" -A10000000 | \
  131. grep "$3" -B10000000 | \
  132. awk '{print $4"="$5}'
  133. ;;
  134. list)
  135. zcat $(ls -rt /var/log/dpkg*)
  136. ;;
  137. *)
  138. echo "Parameters:"
  139. echo " install - Lists all packages that have been installed."
  140. echo " upgrade - Lists all packages that have been upgraded."
  141. echo " remove - Lists all packages that have been removed."
  142. echo " rollback - Lists rollback information."
  143. echo " list - Lists all contains of dpkg logs."
  144. ;;
  145. esac
  146. }
  147. # Kernel-package building shortcut
  148. kerndeb () {
  149. # temporarily unset MAKEFLAGS ( '-j3' will fail )
  150. MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
  151. print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
  152. appendage='-custom' # this shows up in $ (uname -r )
  153. revision=$(date +"%Y%m%d") # this shows up in the .deb file name
  154. make-kpkg clean
  155. time fakeroot make-kpkg --append-to-version "$appendage" --revision \
  156. "$revision" kernel_image kernel_headers
  157. }