diff options
Diffstat (limited to 'plugins/debian')
| -rw-r--r-- | plugins/debian/debian.plugin.zsh | 86 | 
1 files changed, 62 insertions, 24 deletions
diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index 16a5d54ca..1e15487ba 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -1,19 +1,20 @@  # Authors:  # https://github.com/AlexBio  # https://github.com/dbb +# https://github.com/Mappleconfusers  #  # Debian-related zsh aliases and functions for zsh  # Use aptitude if installed, or apt-get if not.  # You can just set apt_pref='apt-get' to override it. -if [[ -e $( which aptitude ) ]]; then +if [[ -e $( which -p aptitude 2>&1 ) ]]; then      apt_pref='aptitude'  else      apt_pref='apt-get'  fi  # Use sudo by default if it's installed -if [[ -e $( which sudo ) ]]; then +if [[ -e $( which -p sudo 2>&1 ) ]]; then      use_sudo=1  fi @@ -21,7 +22,7 @@ fi  # These are for more obscure uses of apt-get and aptitude that aren't covered  # below.  alias ag='apt-get' -alias at='aptitude' +alias ap='aptitude'  # Some self-explanatory aliases  alias acs="apt-cache search" @@ -35,30 +36,34 @@ alias afs='apt-file search --regexp'  # These are apt-get only  alias asrc='apt-get source' -alias ap='apt-cache policy' +alias app='apt-cache policy'  # superuser operations ######################################################  if [[ $use_sudo -eq 1 ]]; then  # commands using sudo ####### -    alias aac="sudo $apt_pref autoclean" -    alias abd="sudo $apt_pref build-dep" -    alias ac="sudo $apt_pref clean" -    alias ad="sudo $apt_pref update" -    alias adg="sudo $apt_pref update && sudo $apt_pref upgrade" -    alias adu="sudo $apt_pref update && sudo $apt_pref dist-upgrade" +    alias aac='sudo $apt_pref autoclean' +    alias abd='sudo $apt_pref build-dep' +    alias ac='sudo $apt_pref clean' +    alias ad='sudo $apt_pref update' +    alias adg='sudo $apt_pref update && sudo $apt_pref upgrade' +    alias adu='sudo $apt_pref update && sudo $apt_pref dist-upgrade'      alias afu='sudo apt-file update' -    alias ag="sudo $apt_pref upgrade" -    alias ai="sudo $apt_pref install" -    alias ap="sudo $apt_pref purge" -    alias ar="sudo $apt_pref remove" +    alias ag='sudo $apt_pref upgrade' +    alias ai='sudo $apt_pref install' +    # Install all packages given on the command line while using only the first word of each line: +    # acs ... | ail +    alias ail="sed -e 's/  */ /g' -e 's/ *//' | cut -s -d ' ' -f 1 | "' xargs sudo $apt_pref install' +    alias ap='sudo $apt_pref purge' +    alias ar='sudo $apt_pref remove'      # apt-get only -    alias ads="sudo $apt_pref dselect-upgrade" +    alias ads='sudo apt-get dselect-upgrade'      # Install all .deb files in the current directory.      # Warning: you will need to put the glob in single quotes if you use:      # glob_subst -    alias di='sudo dpkg -i ./*.deb' +    alias dia='sudo dpkg -i ./*.deb' +    alias di='sudo dpkg -i'      # Remove ALL kernel images and headers EXCEPT the one in use      alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \ @@ -67,18 +72,18 @@ if [[ $use_sudo -eq 1 ]]; then  # commands using su #########  else -    alias aac='su -ls "'"$apt_pref"' autoclean" root' +    alias aac='su -ls \'$apt_pref autoclean\' root'      abd() {          cmd="su -lc '$apt_pref build-dep $@' root"          print "$cmd"          eval "$cmd"      } -    alias ac='su -ls "'"$apt_pref"' clean" root' -    alias ad='su -lc "'"$apt_pref"' update" root' -    alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root' -    alias adu='su -lc "'"$apt_pref"' update && aptitude dist-upgrade" root' +    alias ac='su -ls \'$apt_pref clean\' root' +    alias ad='su -lc \'$apt_pref update\' root' +    alias adg='su -lc \'$apt_pref update && aptitude safe-upgrade\' root' +    alias adu='su -lc \'$apt_pref update && aptitude dist-upgrade\' root'      alias afu='su -lc "apt-file update"' -    alias ag='su -lc "'"$apt_pref"' safe-upgrade" root' +    alias ag='su -lc \'$apt_pref safe-upgrade\' root'      ai() {          cmd="su -lc 'aptitude -P install $@' root"          print "$cmd" @@ -97,13 +102,46 @@ else      # Install all .deb files in the current directory      # Assumes glob_subst is off -    alias di='su -lc "dpkg -i ./*.deb" root' +    alias dia='su -lc "dpkg -i ./*.deb" root' +    alias di='su -lc "dpkg -i" root'      # Remove ALL kernel images and headers EXCEPT the one in use      alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \          ?not(~n`uname -r`))'\'' root'  fi +# Completion ################################################################ + +# +# Registers a compdef for $1 that calls $apt_pref with the commands $2 +# To do that it creates a new completion function called _apt_pref_$2 +# +apt_pref_compdef() { +    local f fb +    f="_apt_pref_${2}" + +    eval "function ${f}() { +        shift words;  +	service=\"\$apt_pref\";  +	words=(\"\$apt_pref\" '$2' \$words);  +	((CURRENT++)) +	test \"\${apt_pref}\" = 'aptitude' && _aptitude || _apt +    }" + +    compdef "$f" "$1" +} + +apt_pref_compdef aac "autoclean" +apt_pref_compdef abd "build-dep" +apt_pref_compdef ac  "clean" +apt_pref_compdef ad  "update" +apt_pref_compdef afu "update" +apt_pref_compdef ag  "upgrade" +apt_pref_compdef ai  "install" +apt_pref_compdef ail "install" +apt_pref_compdef ap  "purge" +apt_pref_compdef ar  "remove" +apt_pref_compdef ads "dselect-upgrade"  # Misc. #####################################################################  # print all installed packages @@ -118,7 +156,7 @@ alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'  apt-copy() {      print '#!/bin/sh'"\n" > apt-copy.sh -    cmd="$apt_pref install " +    cmd='$apt_pref install'      for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {          cmd="${cmd} ${p}"  | 
