From 749feb2720948a4ac9a981286654962e699d8d94 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sat, 6 Aug 2011 15:22:55 -0400 Subject: [PATCH 1/7] Merge "deb" and "debian" plugins. --- plugins/deb/deb.plugin.zsh | 13 ------------- plugins/debian/debian.plugin.zsh | 30 +++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 16 deletions(-) delete mode 100644 plugins/deb/deb.plugin.zsh diff --git a/plugins/deb/deb.plugin.zsh b/plugins/deb/deb.plugin.zsh deleted file mode 100644 index 1b35a064..00000000 --- a/plugins/deb/deb.plugin.zsh +++ /dev/null @@ -1,13 +0,0 @@ -# Aliases -alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \ - --no-gui --disable-columns search" # search package -alias ad="sudo apt-get update" # update packages lists -alias au="sudo apt-get update && \ - sudo apt-get dselect-upgrade" # upgrade packages -alias ai="sudo apt-get install" # install package -alias ar="sudo apt-get remove --purge && \ - sudo apt-get autoremove --purge" # remove package -alias ap="apt-cache policy" # apt policy -alias av="apt-cache show" # show package info -alias acs="apt-cache search" # search package -alias ac="sudo apt-get clean && sudo apt-get autoclean" # clean apt cache diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index f8865a41..6feb6973 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -1,4 +1,4 @@ -# https://github.com/dbbolton/ +# https://github.com/dbb/ # # Debian-related zsh aliases and functions for zsh @@ -6,14 +6,29 @@ # Aliases ################################################################### # Some self-explanatory aliases +alias acs="apt-cache search" alias afs='apt-file search --regexp' alias aps='aptitude search' +alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \ + --no-gui --disable-columns search" # search package alias apsrc='apt-get source' alias apv='apt-cache policy' +# aliases that use su -c ############## alias apdg='su -c "aptitude update && aptitude safe-upgrade"' alias apud='su -c "aptitude update"' alias apug='su -c "aptitude safe-upgrade"' +# end aliases that use su -c ########## + +# aliases that use sudo ############### +alias ad="sudo apt-get update" # update packages lists +alias au="sudo apt-get update && \ + sudo apt-get dselect-upgrade" # upgrade packages +alias ai="sudo apt-get install" # install package +alias ar="sudo apt-get remove --purge && \ + sudo apt-get autoremove --purge" # remove package +alias ac="sudo apt-get clean && sudo apt-get autoclean" # clean apt cache +# end aliases that use sudo ########### # print all installed packages alias allpkgs='aptitude search -F "%p" --disable-columns ~i' @@ -33,6 +48,13 @@ alias kclean='su -c '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`unam # Functions ################################################################# +# install packages without sudo +apin() { + cmd="su -lc 'aptitude -P install $@' root" + print "$cmd" + eval "$cmd" +} + # create a simple script that can be used to 'duplicate' a system apt-copy() { print '#!/bin/sh'"\n" > apt-copy.sh @@ -46,8 +68,10 @@ apt-copy() { # Kernel-package building shortcut -dbb-build () { - MAKEFLAGS='' # temporarily unset MAKEFLAGS ( '-j3' will fail ) +kerndeb () { + # temporarily unset MAKEFLAGS ( '-j3' will fail ) + MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' ) + print '$MAKEFLAGS set to '"'$MAKEFLAGS'" appendage='-custom' # this shows up in $ (uname -r ) revision=$(date +"%Y%m%d") # this shows up in the .deb file name From fd55d53eb22856883953bb6efc89bb2d643ef296 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sat, 6 Aug 2011 15:41:52 -0400 Subject: [PATCH 2/7] Fix su commands --- plugins/debian/debian.plugin.zsh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index 6feb6973..0c487cf7 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -15,9 +15,9 @@ alias apsrc='apt-get source' alias apv='apt-cache policy' # aliases that use su -c ############## -alias apdg='su -c "aptitude update && aptitude safe-upgrade"' -alias apud='su -c "aptitude update"' -alias apug='su -c "aptitude safe-upgrade"' +alias apdg='su -lc "aptitude update && aptitude safe-upgrade" root' +alias apud='su -lc "aptitude update" root' +alias apug='su -lc "aptitude safe-upgrade" root' # end aliases that use su -c ########## # aliases that use sudo ############### @@ -36,13 +36,13 @@ alias allpkgs='aptitude search -F "%p" --disable-columns ~i' # 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='su -c "dpkg -i ./*.deb"' +alias di='su -lc "dpkg -i ./*.deb" root' # Create a basic .deb package alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' # Remove ALL kernel images and headers EXCEPT the one in use -alias kclean='su -c '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'\'' root' +alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'\'' root' @@ -81,4 +81,3 @@ kerndeb () { "$revision" kernel_image kernel_headers } - From 8ed6dd5fc4c5e9b28d0f8a87f72c0bbe5f628580 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sat, 6 Aug 2011 15:58:40 -0400 Subject: [PATCH 3/7] Add functions for new GH repos. --- plugins/github/github.plugin.zsh | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugins/github/github.plugin.zsh b/plugins/github/github.plugin.zsh index 1eb33811..e5f59097 100644 --- a/plugins/github/github.plugin.zsh +++ b/plugins/github/github.plugin.zsh @@ -4,3 +4,44 @@ if [ "$commands[(I)hub]" ]; then # eval `hub alias -s zsh` function git(){hub "$@"} fi + +# Functions ################################################################# + +# https://github.com/dbb + +# These are taken directly from the instructions you see after you create a new +# repo. As the names imply, new_gh() assumes you're starting from scratch in a +# directory named after the repo (this name is the only argument it takes), and +# exist_gh() assumes that you've already initialized git in the given directory +# (again, the only argument). +# set up a new repo + +new_gh() { # [NAME_OF_REPO] + repo = $1 + + name=$( igit config user.name ) + email=$( git config user.email ) + user=$( git config github.user ) + + mkdir "$repo" + cd "$repo" + git init + touch README + git add README + git commit -m 'Initial commit.' + git remote add origin git@github.com:${user}/${name}.git + git push -u origin master +} + +exist_gh() { # [DIRECTORY] + cd "$1" + name=$( git config user.name ) + email=$( git config user.email ) + user=$( git config github.user ) + + git remote add origin git@github.com:${user}/${name}.git + git push -u origin master +} + +# End Functions ############################################################# + From 8c48f10a04ce8e6c789cead457e062602cc89931 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sat, 6 Aug 2011 16:15:09 -0400 Subject: [PATCH 4/7] Add functions for new GH repos. --- plugins/github/github.plugin.zsh | 44 +++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/plugins/github/github.plugin.zsh b/plugins/github/github.plugin.zsh index e5f59097..fc51b173 100644 --- a/plugins/github/github.plugin.zsh +++ b/plugins/github/github.plugin.zsh @@ -9,19 +9,13 @@ fi # https://github.com/dbb -# These are taken directly from the instructions you see after you create a new -# repo. As the names imply, new_gh() assumes you're starting from scratch in a -# directory named after the repo (this name is the only argument it takes), and -# exist_gh() assumes that you've already initialized git in the given directory -# (again, the only argument). -# set up a new repo -new_gh() { # [NAME_OF_REPO] +# empty_gh [NAME_OF_REPO] +# +# Use this when creating a new repo from scratch. +empty_gh() { # [NAME_OF_REPO] repo = $1 - - name=$( igit config user.name ) - email=$( git config user.email ) - user=$( git config github.user ) + ghuser=$( git config github.user ) mkdir "$repo" cd "$repo" @@ -29,17 +23,37 @@ new_gh() { # [NAME_OF_REPO] touch README git add README git commit -m 'Initial commit.' - git remote add origin git@github.com:${user}/${name}.git + git remote add origin git@github.com:${ghuser}/${repo}.git git push -u origin master } +# new_gh [DIRECTORY] +# +# Use this when you have a directory that is not yet set up for git. +# This function will add all non-hidden files to git. +new_gh() { # [DIRECTORY] + cd "$1" + ghuser=$( git config github.user ) + + git init + # add all non-dot files + print '.*'"\n"'*~' >> .gitignore + git add ^.* + git commit -m 'Initial commit.' + git remote add origin git@github.com:${ghuser}/${repo}.git + git push -u origin master +} + +# exist_gh [DIRECTORY] +# +# Use this when you have a git repo that's ready to go and you want to add it +# to your GitHub. exist_gh() { # [DIRECTORY] cd "$1" name=$( git config user.name ) - email=$( git config user.email ) - user=$( git config github.user ) + ghuser=$( git config github.user ) - git remote add origin git@github.com:${user}/${name}.git + git remote add origin git@github.com:${ghuser}/${repo}.git git push -u origin master } From fac74012f81fc99eb2ba7a85e94a2cd74c352271 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sun, 7 Aug 2011 15:30:55 -0400 Subject: [PATCH 5/7] Add options for su(do) and apt(itude|-get) --- plugins/debian/debian.plugin.zsh | 76 ++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index 0c487cf7..1df91dc4 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -1,48 +1,76 @@ -# https://github.com/dbb/ +# Authors: +# https://github.com/AlexBio +# https://github.com/dbb # # Debian-related zsh aliases and functions for zsh +# Set to 'apt-get' or 'aptitude' +apt_pref='aptitude' + +# Use sudo by default if it's installed +if [[ -e $( which sudo ) ]]; then + use_sudo=1 +fi # Aliases ################################################################### # Some self-explanatory aliases alias acs="apt-cache search" -alias afs='apt-file search --regexp' alias aps='aptitude search' alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \ --no-gui --disable-columns search" # search package -alias apsrc='apt-get source' -alias apv='apt-cache policy' -# aliases that use su -c ############## -alias apdg='su -lc "aptitude update && aptitude safe-upgrade" root' -alias apud='su -lc "aptitude update" root' -alias apug='su -lc "aptitude safe-upgrade" root' -# end aliases that use su -c ########## +# apt-file +alias afs='apt-file search --regexp' + + +# These are apt-get only +alias asrc='apt-get source' +alias ap='apt-cache policy' + +# superuser operations ################ +if [[ $use_sudo -eq 1 ]]; then + alias ai="sudo $apt_pref install" + alias ad="sudo $apt_pref update" + alias afu='sudo apt-file update' + alias ag="sudo $apt_pref upgrade" + alias adg="sudo $apt_pref update && sudo $apt_pref upgrade" + alias ap="sudo $apt_pref purge" + alias ar="sudo $apt_pref remove" + + if [[ $apt_pref -eq 'apt-get' ]]; then + alias ads="sudo $apt_pref dselect-upgrade" + fi + + # 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' + + # Remove ALL kernel images and headers EXCEPT the one in use + alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))' +else + alias ai='apin' + alias ad='su -lc "'"$apt_pref"' update" root' + alias afu='su -lc "apt-file update"' + alias ag='su -lc "'"$apt_pref"' safe-upgrade" root' + alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root' + alias di='su -lc "dpkg -i ./*.deb" 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 +# end superuser operations ########## -# aliases that use sudo ############### -alias ad="sudo apt-get update" # update packages lists -alias au="sudo apt-get update && \ - sudo apt-get dselect-upgrade" # upgrade packages -alias ai="sudo apt-get install" # install package -alias ar="sudo apt-get remove --purge && \ - sudo apt-get autoremove --purge" # remove package -alias ac="sudo apt-get clean && sudo apt-get autoclean" # clean apt cache -# end aliases that use sudo ########### # print all installed packages alias allpkgs='aptitude search -F "%p" --disable-columns ~i' -# 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='su -lc "dpkg -i ./*.deb" root' + # Create a basic .deb package alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' -# 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' + From 65393b4bb10de841edbe2026dba29b73625b33d7 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sun, 7 Aug 2011 16:51:14 -0400 Subject: [PATCH 6/7] Extend root ops, switch apt-copy to plain zsh --- plugins/debian/debian.plugin.zsh | 92 ++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index 1df91dc4..23cb98f9 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -4,8 +4,13 @@ # # Debian-related zsh aliases and functions for zsh -# Set to 'apt-get' or 'aptitude' -apt_pref='aptitude' +# 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 + apt_pref='aptitude' +else + apt_pref='apt-get' +fi # Use sudo by default if it's installed if [[ -e $( which sudo ) ]]; then @@ -13,6 +18,10 @@ if [[ -e $( which sudo ) ]]; then fi # Aliases ################################################################### +# These are for more obscure uses of apt-get and aptitude that aren't covered +# below. +alias ag='apt-get' +alias at='aptitude' # Some self-explanatory aliases alias acs="apt-cache search" @@ -28,19 +37,23 @@ alias afs='apt-file search --regexp' alias asrc='apt-get source' alias ap='apt-cache policy' -# superuser operations ################ +# superuser operations ###################################################### if [[ $use_sudo -eq 1 ]]; then - alias ai="sudo $apt_pref install" +# 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 afu='sudo apt-file update' alias ag="sudo $apt_pref upgrade" - alias adg="sudo $apt_pref update && sudo $apt_pref upgrade" + alias ai="sudo $apt_pref install" alias ap="sudo $apt_pref purge" alias ar="sudo $apt_pref remove" - if [[ $apt_pref -eq 'apt-get' ]]; then - alias ads="sudo $apt_pref dselect-upgrade" - fi + # apt-get only + alias ads="sudo $apt_pref dselect-upgrade" # Install all .deb files in the current directory. # Warning: you will need to put the glob in single quotes if you use: @@ -48,25 +61,54 @@ if [[ $use_sudo -eq 1 ]]; then alias di='sudo dpkg -i ./*.deb' # Remove ALL kernel images and headers EXCEPT the one in use - alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))' + alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \ + ?not(~n`uname -r`))' + + +# commands using su ######### else - alias ai='apin' + 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 afu='su -lc "apt-file update"' alias ag='su -lc "'"$apt_pref"' safe-upgrade" root' - alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root' + ai() { + cmd="su -lc 'aptitude -P install $@' root" + print "$cmd" + eval "$cmd" + } + ap() { + cmd="su -lc '$apt_pref -P purge $@' root" + print "$cmd" + eval "$cmd" + } + ar() { + cmd="su -lc '$apt_pref -P remove $@' root" + print "$cmd" + eval "$cmd" + } + + # Install all .deb files in the current directory + # Assumes glob_subst is off alias di='su -lc "dpkg -i ./*.deb" 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' + alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \ + ?not(~n`uname -r`))'\'' root' fi -# end superuser operations ########## +# Misc. ##################################################################### # print all installed packages alias allpkgs='aptitude search -F "%p" --disable-columns ~i' - - # Create a basic .deb package alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' @@ -75,23 +117,19 @@ alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' # Functions ################################################################# - -# install packages without sudo -apin() { - cmd="su -lc 'aptitude -P install $@' root" - print "$cmd" - eval "$cmd" -} - # create a simple script that can be used to 'duplicate' a system apt-copy() { - print '#!/bin/sh'"\n" > apt-copy.sh + print '#!/bin/sh'"\n" > apt-copy.sh - list=$(perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;') + cmd="$apt_pref install -s " - print 'aptitude install '"$list\n" >> apt-copy.sh + for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; { + cmd="${cmd} ${p}" + } - chmod +x apt-copy.sh + print $cmd "\n" >> apt-copy.sh + + chmod +x apt-copy.sh } From d3116d4f0b499bb76e371f7d60eed48b81068932 Mon Sep 17 00:00:00 2001 From: Daniel Bolton Date: Sat, 13 Aug 2011 10:53:24 -0400 Subject: [PATCH 7/7] Remove -s switch from apt-copy --- plugins/debian/debian.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index 23cb98f9..09771881 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -121,7 +121,7 @@ alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' apt-copy() { print '#!/bin/sh'"\n" > apt-copy.sh - cmd="$apt_pref install -s " + cmd="$apt_pref install " for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; { cmd="${cmd} ${p}"