debian.plugin.zsh 5.4 KB

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