From 9a671cf2922a1dd49cb18cb077c45ab29da44565 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Fri, 27 Jan 2012 15:19:03 -0500 Subject: [PATCH] Generalize commands across OSes - support Arch, Debian and Mac OS (with homebrew) with package shortcuts - generalize sudo commands for root --- dot-files/zshrc | 65 +++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/dot-files/zshrc b/dot-files/zshrc index f5e0496..df9a5e5 100644 --- a/dot-files/zshrc +++ b/dot-files/zshrc @@ -79,39 +79,60 @@ alias ls="ls $LS_OPTS" export TREE_OPTS="-I '*.pyc' -Ch --filelimit 20" alias tree="tree $TREE_OPTS" -# installation and compilation -alias cmi="sudo date && ./configure $CONF && make && make test && sudo make install && make clean && date" +#### OS- or distribution-dependent... +ARCH=[ -e /etc/arch-release ] +DEBIAN=[ -e /etc/debian_version ] +MAC=[ "$(uname)" -eq "Darwin" ] + +#### User-dependent +if [ "$USER" -eq "root" ]; then + SUDO='' +else + SUDO='sudo' +fi + + +alias cmi="$SUDO date && ./configure $CONF && make && make test && $SUDO make install && make clean && date" +alias apres="$SUDO apache2ctl restart" + +if $ARCH; then + alias get="$SUDO pacman -S" + alias agu="$SUDO pacman -Syu" + alias acs="$SUDO pacman -Ss" +fi +if $DEBIAN; then + alias get="$SUDO apt-get install" + alias agu="$SUDO apt-get update; $SUDO apt-get upgrade; $SUDO apt-get dist-upgrade" + alias acs="apt-cache search" +fi +if $MAC; then + alias get="brew install" + alias agu="brew update && brew upgrade" + alias acs="brew search" +fi -# screen-related -alias svim='screen vim' - -# frequent sudo tasks -alias get='sudo apt-get install' -alias apres='sudo apache2ctl restart' -alias agu='sudo apt-get update; sudo apt-get upgrade; sudo apt-get dist-upgrade' -alias acs='apt-cache search' ns () { - sudo vim /etc/apache2/sites-available/$1.terst.org +":0r /etc/apache2/sites-available/template" +":%s/DEFAULT/$1/g" + $SUDO vim /etc/apache2/sites-available/$1.terst.org +":0r /etc/apache2/sites-available/template" +":%s/DEFAULT/$1/g" if [ $? -eq 0 ]; then - sudo mkdir -p /workspace/sites/$1.terst.org/docroot - sudo ln -s /workspace/sites/$1.terst.org /var/www/htdocs/$1.terst.org - sudo a2ensite $1.terst.org - sudo apache2ctl restart + $SUDO mkdir -p /workspace/sites/$1.terst.org/docroot + $SUDO ln -s /workspace/sites/$1.terst.org /var/www/htdocs/$1.terst.org + $SUDO a2ensite $1.terst.org + $SUDO apache2ctl restart echo "http://$1.terst.org/ is active." else echo "cancelled...." fi } es () { - sudo vim /etc/apache2/sites-available/$1.terst.org && sudo apache2ctl restart + $SUDO vim /etc/apache2/sites-available/$1.terst.org && $SUDO apache2ctl restart } # xkcd.com/149 mmas () { echo "What? Make it yourself." - echo "-> sudo $(history|tail -1|sed "s/ [0-9][0-9][0-9][0-9][ *] //")" + echo "-> $SUDO $(history|tail -1|sed "s/ [0-9][0-9][0-9][0-9][ *] //")" echo "Ok." - sudo $(history|tail -1|sed "s/ [0-9][0-9][0-9][0-9][ *] //") + $SUDO $(history|tail -1|sed "s/ [0-9][0-9][0-9][0-9][ *] //") } # update this config and reload @@ -132,14 +153,6 @@ tlog () tail -fn0 /var/log/apache2/{$1.access,error,rewrite}.log fi } - - -sd () -{ - svn diff --diff-cmd=colordiff $@ | more -} -alias zf=/workspace/runtimes/ZendFramework-1.11.10/bin/zf.sh -alias sc="sudo -u www-data /workspace/sites/s.terst.org/app/console" cdls () { \cd $1 ls -t --color=always | head -3 | sed 's/^/\t/'