Browse Source

Huge update in zsh config (improve code quality, add/remove aliases)

Emmanuel Bouthenot 14 years ago
parent
commit
ac25f5a486

+ 79 - 40
.zsh.d/config.d/alias.zsh

@@ -1,52 +1,91 @@
-
+#
 # Editor
--exe emacs \
-    && export EDITOR="emacs -nw"
-alias e=$EDITOR
-
-# common aliases
-alias rm="rm -i"
-alias mv="mv -i"
-alias cp="cp -i"
-alias vlock="clear; vlock"
-alias df="df -h"
-alias rsu="sudo zsh"
-alias reload="exec zsh"
-alias grep="grep --color=tty"
+#
+if -exe emacs; then
+    export EDITOR='emacs -nw'
+fi
 
-alias slog="tail -n 60 -f /var/log/syslog"
-alias mlog="tail -n 60 -f /var/log/mail.log"
+if [ -n "$EDITOR" -a -n "$SUDO_USER" -a "$UID" = 0 -a "$EDITOR[1,5]" = 'emacs' ]; then
+    e="$EDITOR -u $SUDO_USER"
+else
+    alias e=$EDITOR
+fi
 
-# using colortail if available (freebsd)
--exe colortail \
-    && alias slog="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog"
+#
+# Pager
+#
+if -exe most; then
+    export PAGER=most
+    alias less='most'
+    alias more='most'
+elif -exe less; then
+    export PAGER=less
+elif -exe more; then
+    export PAGER=more
+fi
 
-[ -n "$EDITOR" -a -n "$SUDO_USER" -a $UID = 0 -a $EDITOR[1,5] = "emacs" ] \
-    && alias e="$EDITOR -u $SUDO_USER"
+#
+# Common aliases
+#
+alias rm='rm -i'
+alias mv='mv -i'
+alias cp='cp -i'
 
--exe ccze \
-    && alias slog="tail -n 60 -f /var/log/syslog | ccze" \
-    && alias mlog="tail -n 60 -f /var/log/mail.log | ccze"
+alias vlock='clear;vlock'
+alias q='clear;exit'
 
--exe pydf \
-    && alias df="pydf -h"
--exe colormake \
-    && alias make="colormake"
+alias grep="grep --color=tty"
+alias mgrep="grep --color=tty -rnisH"
 
-# git stuff
-[ -z "$GIT_PAGER" ] \
-    && [ -x =less ] && export GIT_PAGER=less
-[ -z "$GIT_PAGER" ] \
-    && [ -x =more ] && export GIT_PAGER=more
-[ -z "$GIT_PAGER" ] \
-    && export GIT_PAGER=cat
+alias rsu="sudo zsh"
+alias reload="exec zsh"
+
+#
+# Log viewers aliases
+#
+if -exe ccze; then
+    alias slog="tail -n 300 -f /var/log/syslog | ccze"
+    alias mlog="tail -n 300 -f /var/log/mail.log | ccze"
+else
+    alias slog="tail -n 60 -f /var/log/syslog"
+    alias mlog="tail -n 60 -f /var/log/mail.log"
+fi
+# using colortail if available (freebsd)
+if -exe colortail; then
+    alias slog="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog"
+fi
 
-alias git="PAGER=$GIT_PAGER git"
-unset GIT_PAGER
+#
+# System tools aliases
+#
+alias df='df -h'
+if -exe pydf; then
+    alias df="pydf -h"
+fi
 
-# Pager stuff
--exe most \
-    && export PAGER=most && alias more='most' && alias less='most'
+#
+# Devel tools aliases
+#
+if -exe colordiff; then
+    diff='colordiff'
+    if -exe tput; then
+        alias cdiff='colordiff -yW$(tput cols)'
+    fi
+fi
 
+if -exe colormake; then
+    alias make="colormake"
+fi
 
+#
+# Git stuff
+#
+if [ -z "$GIT_PAGER" ]; then
+    for p in less more cat; do
+        if -exe "$p"; then
+            alias git="PAGER=$p git"
+            break
+        fi
+    done
+fi
 

+ 4 - 10
.zsh.d/config.d/devel.zsh

@@ -1,13 +1,7 @@
-
-# devel stuff
-
-# WeeChat Stuff
-alias weecvs="cvs -z3 -d:ext:kolter@cvs.sv.gnu.org:/sources/weechat"
-compdef _cvs weecvs
-
-# kpkgmanager / kio-apt stuff
-alias kpmcvs="cvs -z3 -d:ext:kolterox@kpkgmanager.cvs.sourceforge.net:/cvsroot/kpkgmanager"
-compdef _cvs kpmcvs
+#
+# Devel stuff
+#
 
 # Python completion
 export PYTHONSTARTUP=~/.pythonrc
+

+ 12 - 8
.zsh.d/config.d/history.zsh

@@ -1,17 +1,21 @@
+#
+# History options
+#
 
-# history options
+setopt extendedhistory      # add a timestamp and the duration of each command
+setopt sharehistory         # _all_ zsh sessions share the same history files
+setopt histignorealldups    # ignores duplications
 
-setopt extendedhistory		# add a timestamp and the duration of each command
-setopt sharehistory	 	# _all_ zsh sessions share the same history files
-setopt histignorealldups	# ignores duplications
+HISTDIR="$DOTZSHDIR/history"
+if [ ! -d "$HISTDIR" ]; then
+    mkdir -p "$HISTDIR"
+fi
 
-HISTDIR=$DOTZSHDIR/history
-[ ! -d $HISTDIR ] && mkdir -p $HISTDIR
-
-HISTFILE=$HISTDIR/history
+HISTFILE="$HISTDIR/history"
 
 HISTSIZE=1000000
 SAVEHIST=1000000
 
 export HISTFILE HISTSIZE SAVEHIST
 unset HISTDIR
+

+ 10 - 10
.zsh.d/config.d/options.zsh

@@ -1,21 +1,21 @@
+#
+# Zsh options
+#
 
-# zsh options
+export LISTPROMPT           # in order to scroll if completion list is too big
 
-export LISTPROMPT	    # in order to scroll if completion list is too big
-
-setopt auto_cd		    # a command like % /usr/local is equivalent to cd /usr/local
+setopt auto_cd              # a command like % /usr/local is equivalent to cd /usr/local
 setopt nohup                # don't send HUP signal when closing term session
-setopt extended_glob	    # in order to use #, ~ and ^ for filename generation
-setopt always_to_end	    # move to cursor to the end after completion
-setopt notify		    # report the status of backgrounds jobs immediately
-setopt correct		    # try to correct the spelling if possible
-setopt rmstarwait	    # wait 10 seconds before querying for a rm which contains a *
+setopt extended_glob        # in order to use #, ~ and ^ for filename generation
+setopt always_to_end        # move to cursor to the end after completion
+setopt notify               # report the status of backgrounds jobs immediately
+setopt correct              # try to correct the spelling if possible
+setopt rmstarwait           # wait 10 seconds before querying for a rm which contains a *
 setopt noflowcontrol        # disable xon/xoff
 setopt histnostore          # don't store history command in history
 setopt nobanghist           # don't care of '!' in commands
 setopt emacs                # zle in emacs mode
 setopt pushdignoredups      # ignore dups in pushd stack
-#setopt printexitvalue       # show the exit-value if > 0
 setopt auto_continue        # send SIGCONT to jobs disowned
 setopt auto_list            # list choice on ambiguous command
 setopt auto_pushd           # cd = pushd

+ 5 - 3
.zsh.d/config.d/personal.zsh

@@ -1,5 +1,6 @@
-
-# zsh personal settings
+#
+# Personal settings
+#
 
 # full name
 NAME="Emmanuel Bouthenot"
@@ -7,7 +8,7 @@ DEBFULLNAME=$NAME
 
 # email address
 export EMAIL="kolter@openics.org"
-export DEBEMAIL=$EMAIL
+export DEBEMAIL="kolter@debian.org"
 
 # email address for anonymous ftp
 export EMAIL_ADDR=plop@dev.null
@@ -19,3 +20,4 @@ WATCHFMT="[%T] %n has %a %l from %M"
 
 # override default umask
 umask 0022
+

+ 11 - 11
.zsh.d/config.d/prompt.zsh

@@ -1,5 +1,6 @@
-
-# prompt config
+#
+# Prompt config
+#
 
 setopt prompt_subst
 
@@ -19,12 +20,12 @@ export PR_OS_ARCH=$(uname -m)
 
 if [ -f /etc/debian_version ]; then
     if [ "$PR_OS_NAME" = "Linux" ]; then
-	PR_OS_NAME="debian $(</etc/debian_version)"
+        PR_OS_NAME="debian $(</etc/debian_version)"
     else
-	PR_OS_NAME="debian/${PR_OS_NAME} $(</etc/debian_version)"
+        PR_OS_NAME="debian/${PR_OS_NAME} $(</etc/debian_version)"
     fi
     if [ -f /etc/debian_chroot ]; then
-	PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}$(</etc/debian_version)"
+        PR_OS_NAME="${PR_OS_NAME} ${PR_LIGHT_RED}chroot:${PR_WHITE}$(</etc/debian_version)"
     fi
 fi
 PR_OS_NAME="${PR_OS_NAME} ${PR_OS_ARCH}"
@@ -41,15 +42,13 @@ else
     export PR_OS_SSH=
 fi
 
-if [ $UID = 0 ]; then
+if [ "$UID" = 0 ]; then
     export PR_ROOT_PREFIX='*'
 else
     export PR_ROOT_PREFIX=
 fi
 
 function mytitle {
-    # if running konsole, setting current directory name in tab
-    [ "$KONSOLE_DCOP_SESSION" ] && dcop $KONSOLE_DCOP_SESSION renameSession "${PR_ROOT_PREFIX}${1}"
     # if running screen, setting current directory name in caption/statusbar
     [ "$TERM" = "screen" ] && echo -ne "\033k${PR_ROOT_PREFIX}${1}\033\\"
     # if running 'xterm like' terminal setting directory name in title bar
@@ -68,9 +67,9 @@ function precmd {
 
 myprompt() {    
     if [ "$TERM" = "dumb" ]; then
-	PROMPT="-(%n@%m)-(%(!.%d.%~))->"
+    PROMPT="-(%n@%m)-(%(!.%d.%~))->"
     else
-	PROMPT='\
+    PROMPT='\
 ${PR_BLUE}\
 %1(j.-(${PR_YELLOW}jobs:${PR_WHITE}%j${PR_BLUE}).)\
 ${PR_BLUE}-(\
@@ -81,4 +80,5 @@ ${PR_WHITE}${PR_OS_NAME}${PR_BLUE})-(${PR_WHITE}%(!.%d.%~)${PR_BLUE})
     fi
 }
 
-myprompt
+myprompt
+

+ 4 - 3
.zsh.d/config.d/shell.zsh

@@ -1,9 +1,10 @@
-
-# shell tweaking
+#
+# Shell tweaking
+#
 
 if [ -n "$LS_COLORS" ]; then
     zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
-    
     zstyle ':completion:*:processes' command 'ps -aU$USER -o pid,user,time,cmd --sort user|grep -v "ps -aU$USER -o pid,user,time,cmd --sort user"'
     zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([^ ]#) ([^ ]#)[ 0-9:]#([^ :]#)*=01;30=01;31=01;38=01;38'    
 fi
+

+ 4 - 2
.zsh.d/config.d/ulimit.zsh

@@ -1,4 +1,6 @@
+#
+# Ulimit options
+#
 
-# ulimit options
+ulimit -c 8192  # max coredump size
 
-ulimit -c 8192        # max coredump size

+ 3 - 2
.zsh.d/config.d/zle.zsh

@@ -1,3 +1,4 @@
-
-# zle config
+#
+# Zle config
+#
 

+ 5 - 3
.zsh.d/lib.d/common.zsh

@@ -1,7 +1,9 @@
+#
+# Zsh custom functions
+#
 
-# zsh custom functions
-
-function -exe () {    
+function -exe () {
     whence -p $1 >/dev/null 2>&1
     return $?
 }
+

+ 21 - 20
.zsh.d/os.d/Debian.zsh

@@ -1,29 +1,30 @@
-
+#
 # Debian stuff
+#
 
 # specific aliases
 alias lintian="lintian --color=auto -IEm --pedantic"
 
 # building environements
 cow-dist () {
-	if [ $# -lt 2 ]; then
-		echo "Error args."
-		return
-	fi
-	DIST=$1
-	shift
-	OPTS=
-	if [ "$1" = "--update" ]; then
-		OPTS="--no-cowdancer-update"
-	elif [ "$1" = "--build" -a -z "$2" ]; then
-		if [ -f debian/changelog ]; then
-			dsc=$(egrep -v "^([[:space:]]+|$)" debian/changelog| \
-				sed 's/\([^ ]*\) (\([^)]*\)).*/..\/\1_\2.dsc/'|head -1)
-			if [ -f "$dsc" ]; then
-				OPTS="$dsc"
-			fi
-		fi
-	fi
+    if [ $# -lt 2 ]; then
+        echo "Error args."
+        return
+    fi
+    DIST=$1
+    shift
+    OPTS=
+    if [ "$1" = "--update" ]; then
+        OPTS="--no-cowdancer-update"
+    elif [ "$1" = "--build" -a -z "$2" ]; then
+        if [ -f debian/changelog ]; then
+            dsc=$(egrep -v "^([[:space:]]+|$)" debian/changelog| \
+                sed 's/\([^ ]*\) (\([^)]*\)).*/..\/\1_\2.dsc/'|head -1)
+            if [ -f "$dsc" ]; then
+                OPTS="$dsc"
+            fi
+        fi
+    fi
     sudo DIST=$DIST cowbuilder $@ $OPTS
     return $?
 }
@@ -70,7 +71,7 @@ pdebdiff() {
                 echo "*** DIFF ${pkg}_${v2} -> ${pkg}_${v1} ***"
                 echo
                 debdiff ../${pkg}_${v2}_${arch}.deb ../${pkg}_${v1}_${arch}.deb
-                )|$PAGER
+            )|$PAGER
     done
 }
 

+ 25 - 19
.zsh.d/os.d/FreeBSD.zsh

@@ -1,31 +1,37 @@
-
+#
 # FreeBSD stuff
+#
 
 # GNU ls(1) from FreeBSD ports is called gnuls(1).
-if -exe gnuls ; then
-    if [ "$TERM" != "dumb" ]; then
-	eval $(gdircolors -b)
-	alias ls="gnuls -h --color=auto"
-	alias l="gnuls -lh --color=auto"
+if -exe gnuls; then
+    if [ "$TERM" != 'dumb' ]; then
+        if -exe gdircolors; then
+            eval $(gdircolors -b)
+        fi
+        alias ls='gnuls -h --color=auto'
+        alias l='gnuls -lh --color=auto'
     else
-	alias ls="gnuls -h"
-	alias l="gnuls -lh"
+        alias ls='gnuls -h'
+        alias l='gnuls -lh'
     fi
 else
-    if [ "$TERM" != "dumb" ]; then
-	export LSCOLORS="exfxbxdxcxegedabagacad"
-	alias ls="ls -GFh"
-	alias l="ls -lGFh"
+    if [ "$TERM" != 'dumb' ]; then
+        export LSCOLORS='exfxbxdxcxegedabagacad'
+        alias ls='ls -GFh'
+    alias l='ls -lGFh'
     else
-	alias ls="ls -Fh"
-	alias l="ls -lFh"
+        alias ls='ls -Fh'
+        alias l='ls -lFh'
     fi
 fi
 
-# GNU tar is called gtar 
--exe gtar \
-    && alias tar="gtar"
+# GNU tar is called gtar
+if -exe gtar; then
+    alias tar='gtar'
+fi
 
 # GNU find is called gfind
--exe gfind \
-    && alias find="gfind"
+if -exe gfind; then
+    alias find='gfind'
+fi
+

+ 13 - 10
.zsh.d/os.d/Linux.zsh

@@ -1,16 +1,19 @@
-
+#
 # Linux Stuff
+#
 
-[ -r /etc/debian_version ] && source $DOTZSHDIR/os.d/Debian.zsh
+if [ -r /etc/debian_version ]; then
+    source "$DOTZSHDIR/os.d/Debian.zsh"
+fi
 
-if [ "$TERM" != "dumb" ]; then
-    -exe dircolors \
-	&& eval $(dircolors -b)
-    
-    alias ls="ls -h --color=auto"
-    alias l="ls -lh --color=auto"
+if [ "$TERM" != 'dumb' ]; then
+    if -exe dircolors; then
+        eval $(dircolors -b)
+    fi
+    alias ls='ls -h --color=auto'
+    alias l='ls -lh --color=auto'
 else
-    alias ls="ls -h"
-    alias l="ls -lh"
+    alias ls='ls -h'
+    alias l='ls -lh'
 fi
 

+ 28 - 21
.zsh.d/os.d/OpenBSD.zsh

@@ -1,34 +1,41 @@
-
+#
 # OpenBSD stuff
+#
 
 # GNU ls(1) from OpenBSD ports is named gls(1)/gdircolors(1).
-if -exe gdircolors ; then
-    if [ "$TERM" != "dumb" ]; then
-	eval $(gdircolors -b)	
-	alias ls="gls -h --color=auto"
-	alias l="gls -lh --color=auto"
+if -exe gls; then
+    if [ "$TERM" != 'dumb' ]; then
+        if -exe gdircolors; then
+            eval $(gdircolors -b)
+        fi
+        alias ls='gls -h --color=auto'
+        alias l='gls -lh --color=auto'
     else
-	alias ls="gls -h"
-	alias l="gls -lh"
+        alias ls='gls -h'
+        alias l='gls -lh'
     fi
+
 # colorls(1) is {Open,Net}BSD port name for FreeBSD ls(1)
-elif -exe colorls ; then
-    if [ "$TERM" != "dumb" ]; then
-	export LSCOLORS="exfxbxdxcxegedabagacad"
-	alias ls="colorls -GFh"
-	alias l="colorls -lGFh"
+elif -exe colorls; then
+    if [ "$TERM" != 'dumb' ]; then
+        export LSCOLORS='exfxbxdxcxegedabagacad'
+        alias ls='colorls -GFh'
+        alias l='colorls -lGFh'
     else
-	alias ls="colorls -Fh"
-	alias l="colorls -lFh"
+        alias ls='colorls -Fh'
+        alias l='colorls -lFh'
     fi
 else
-    alias ls="ls -Fh"
+    alias ls='ls -Fh'
 fi
 
-# GNU tar is called gtar 
--exe gtar \
-    && alias tar="gtar"
+# GNU tar is called gtar
+if -exe gtar; then
+    alias tar='gtar'
+fi
 
 # GNU find is called gfind
--exe gfind \
-    && alias find="gfind"
+if -exe gfind; then
+    alias find='gfind'
+fi
+

+ 19 - 13
.zsh.d/os.d/SunOS.zsh

@@ -1,5 +1,6 @@
-
+#
 # SunOS, Solaris Stuff
+#
 
 PATH=$PATH:/usr/ccs/bin:/usr/sfw/bin:/usr/openwin/bin
 MANPATH=/usr/man
@@ -19,21 +20,26 @@ fi
 export PATH MANPATH
 
 # GNU ls(1) from SunOS ports is called gls(1)/gdircolors(1).
-if -exe gdircolors ; then
-    if [ "$TERM" != "dumb" ]; then
-	eval $(gdircolors -b)
-	alias ls="gls -h --color=auto"
-	alias l="gls -lh --color=auto"
+if -exe gls; then
+    if [ "$TERM" != 'dumb' ]; then
+        if -exe gdircolors; then
+            eval $(gdircolors -b)
+        fi
+        alias ls='gls -h --color=auto'
+        alias l='gls -lh --color=auto'
     else
-	alias ls="gls -h"
-	alias l="gls -lh"
+        alias ls='gls -h'
+        alias l='gls -lh'
     fi
 fi
 
-# GNU tar is called gtar 
--exe gtar \
-    && alias tar="gtar"
+# GNU tar is called gtar
+if -exe gtar; then
+    alias tar='gtar'
+fi
 
 # GNU find is called gfind
--exe gfind \
-    && alias find="gfind"
+if -exe gfind; then
+    alias find='gfind'
+fi
+

+ 20 - 10
.zsh.d/zshrc

@@ -14,7 +14,9 @@ export DOTZSHDIR="$HOME/.zsh.d"
 
 # overide insecure stuff with compinit while using 'sudo zsh'
 # my functions (don't forget to modify fpath before call compinit !!)
-[ -z "$SUDO_USER" -a $UID != 0 ] && fpath=($DOTZSHDIR/functions.d $fpath)
+if [ -z "$SUDO_USER" -a "$UID" != 0 ]; then
+    fpath=($DOTZSHDIR/functions.d $fpath)
+fi
 
 autoload -U zutil
 autoload -U compinit
@@ -27,26 +29,34 @@ for f in $DOTZSHDIR/lib.d/*.zsh; do
 done
 
 # per OS resource file
-local os=$(uname)
+os=$(uname)
 # special case
-[ "$os" = "GNU/kFreeBSD" ] && os="Linux"
-[ -r "$DOTZSHDIR/os.d/${os}.zsh" ] && source "$DOTZSHDIR/os.d/${os}.zsh"
+if [ "$os" = "GNU/kFreeBSD" ]; then
+    os="Linux"
+fi
+if [ -r "$DOTZSHDIR/os.d/${os}.zsh" ]; then
+    source "$DOTZSHDIR/os.d/${os}.zsh"
+fi
+unset os
 
 # sourcing config files
 for f in $DOTZSHDIR/config.d/*.zsh; do
-    [ -r "$f" ] && source $f
+    if [ -r "$f" ]; then
+        source $f
+    fi
 done
 
 # using 'sudo zsh'
-if [ "$SUDO_USER" -a $UID = 0 ]; then
+if [ "$SUDO_USER" -a "$UID" = 0 ]; then
     # define root history path
     export HISTFILE="$DOTZSHDIR/history/history_root"
-    
     # ugly hack : reset some file perms to normal to avoid warnings
     chmod 0644 ~/.zcompdump
-    chown $SUDO_USER:$SUDO_USER ~/.zcompdump
-    
+    chown "$SUDO_USER:$SUDO_USER" ~/.zcompdump
 fi
 
 # sourcing extra file
-[ -r "$DOTZSHDIR/extra.zsh" ] && source "$DOTZSHDIR/extra.zsh"
+if [ -r "$DOTZSHDIR/extra.zsh" ]; then
+    source "$DOTZSHDIR/extra.zsh"
+fi
+