Prechádzať zdrojové kódy

Cleaning and rewrite most of zsh config.

Emmanuel Bouthenot 17 rokov pred
rodič
commit
326cdb96ff

+ 35 - 14
.zsh.d/config.d/alias.zsh

@@ -1,31 +1,52 @@
 
+# 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 lm="tail -n 60 -f /var/log/syslog"
 alias df="df -h"
-alias emacs="emacs -nw"
-alias e="emacs -nw"
 alias rsu="sudo zsh"
-alias zconf="source ~/.zshrc"
+alias reload="exec zsh"
 alias grep="grep --color=tty"
 
-[ "$SUDO_USER" -a $UID = 0 ] && alias emacs="emacs -u $SUDO_USER -nw"
-[ "$SUDO_USER" -a $UID = 0 ] && alias e="emacs -u $SUDO_USER -nw"
+alias slog="tail -n 60 -f /var/log/syslog"
+alias mlog="tail -n 60 -f /var/log/maik.log"
+
+# using colortail if available (freebsd)
+-exe colortail \
+    && alias lm="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog"
+
+[ -n "$EDITOR" -a -n "$SUDO_USER" -a $UID = 0 -a $EDITOR[1,5] = "emacs" ] \
+    && alias e="$EDITOR -u $SUDO_USER"
+
+-exe ccze \
+    && alias slog="tail -n 60 -f /var/log/syslog | ccze" \
+    && alias mlog="tail -n 60 -f /var/log/mail.log | ccze"
 
-[ -x "$(whence ccze)" ] && alias lm="tail -n 60 -f /var/log/syslog | ccze"
-[ -x "$(whence pydf)" ] && alias df="pydf -h"
-[ -x "$(whence colormake)" ] && alias make="colormake"
+-exe pydf \
+    && alias df="pydf -h"
+-exe colormake \
+    && alias make="colormake"
 
 # 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
+[ -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 git="PAGER=$GIT_PAGER git"
 unset GIT_PAGER
 
-#pager stuff
-[ -x "$(whence most)" ] && export PAGER=most && alias more='most' && alias less='most'
+# Pager stuff
+-exe most \
+    && export PAGER=most && alias more='most' && alias less='most'
+
+
+

+ 2 - 0
.zsh.d/config.d/history.zsh

@@ -7,9 +7,11 @@ setopt histignorealldups	# ignores duplications
 
 HISTDIR=$DOTZSHDIR/history
 [ ! -d $HISTDIR ] && mkdir -p $HISTDIR
+
 HISTFILE=$HISTDIR/history
 
 HISTSIZE=1000000
 SAVEHIST=1000000
 
 export HISTFILE HISTSIZE SAVEHIST
+unset HISTDIR

+ 21 - 0
.zsh.d/config.d/personal.zsh

@@ -0,0 +1,21 @@
+
+# zsh personal settings
+
+# full name
+NAME="Emmanuel Bouthenot"
+DEBFULLNAME=$NAME
+
+# email address
+export EMAIL="kolter@openics.org"
+export DEBEMAIL=$EMAIL
+
+# email address for anonymous ftp
+export EMAIL_ADDR=plop@dev.null
+
+# checking events on system (users login/logout, etc...)
+watch=(notme)
+LOGCHECK=5
+WATCHFMT="[%T] %n has %a %l from %M"
+
+# override default umask
+umask 0022

+ 4 - 15
.zsh.d/config.d/prompt.zsh

@@ -5,22 +5,11 @@ export PR_OS_NAME=$(uname -s)
 export PR_OS_ARCH=$(uname -m)
 
 if [ -f /etc/debian_version ]; then
-    echo $PR_OS_NAME | grep -i linux >/dev/null 2>&1
-    if [ $? = 0 ]; then
-	PR_OS_NAME="Debian GNU/${PR_OS_NAME}"
-    else
-	PR_OS_NAME="Debian ${PR_OS_NAME}"
-    fi
-    debian_version=$(</etc/debian_version)
-    [ $debian_version = 'testing/unstable' ] && PR_OS_NAME="${PR_OS_NAME} sid" || PR_OS_NAME="${PR_OS_NAME} ${debian_version}"
-    
+    PR_OS_NAME="Debian GNU/${PR_OS_NAME} $(</etc/debian_version)"
+
+    [ -f /etc/debian_chroot ]\
+	&& PR_OS_NAME="$PR_OS_NAME [chroot: $(</etc/debian_version)]"
     
-    if [ -f /etc/debian_chroot ]; then
-	chroot_name=(${(s:-:)$(</etc/debian_chroot)})
-	chroot_name=$chroot_name[0]
-	PR_OS_NAME="${PR_OS_NAME} [chroot: ${chroot_name}]"
-    fi
-	
 fi
 
 [ "$TERM" = "screen" -a -n "$WINDOW" ] && PR_OS_PTY="screen/$WINDOW" || PR_OS_PTY=$(print -P %l)

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

@@ -3,8 +3,7 @@
 
 if [ -n "$LS_COLORS" ]; then
     zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
-
-    zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
-    zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)[ 0-9:]#([^ ]#)*=01;30=01;31=01;38'
+    
+    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
-

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

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

+ 0 - 0
.zsh.d/extra.zsh


+ 0 - 22
.zsh.d/functions.d/_a2utils

@@ -1,22 +0,0 @@
-#compdef a2ensite a2dissite a2enmod a2dismod
-
-case "$service" in
-    a2ensite)
-	sites=( /etc/apache2/sites-available/*(:t) )
-	_wanted sites expl sites compadd $sites
-	;;
-    a2dissite)
-	sites=( /etc/apache2/sites-enabled/*(:t) )
-	_wanted sites expl sites compadd $sites
-	;;
-    a2enmod)
-	mods=( /etc/apache2/mods-available/*.load(:r:t) )
-	_wanted mods expl mods compadd $mods
-	;;
-    a2dismod)
-	mods=( /etc/apache2/mods-enabled/*.load(:r:t) )
-	_wanted mods expl mods compadd $mods
-	;;
-esac
-
-return 0

+ 0 - 54
.zsh.d/functions.d/_aptitude

@@ -1,54 +0,0 @@
-#compdef aptitude
-
-local curcontext="$curcontext" state line cmds ret=1
-
-_arguments -C \
-  '(- 1 *)'{-h,--help}'[display help information]' \
-  '(- 1 *)--version[display version information]' \
-  '(-s --simulate)'{-s,--simulate}'[print actions without performing them]' \
-  '(-d --download-only)'{-d,--download-only}"[just download packages - don't install]" \
-  '(-P --prompt)'{-P,--prompt}'[always display a prompt]' \
-  '(-y --assume-yes)'{-y,--assume-yes}'[assume yes answer to questions]' \
-  '(-F --display-format)'{-F,--display-format}'[specify output format for search command]:format' \
-  '(-O --sort)'{-O,--sort}'[specify sort order]:sort order:()' \
-  '(-w --width)'{-w,--width}'[specify output width]:width' \
-  '-f[aggressivley try to fix dependencies of broken packages]' \
-  '(-V --show-versions)'{-V,--show-versions}'[show which versions of packages will be installed]' \
-  '(-D --show-deps)'{-D,--show-deps}'[show brief explanations of automatic installations and removals]' \
-  '-Z[show disk space changes for each package]' \
-  '(-v --verbose)'{-v,--verbose}'[causes some commands to display extra information]' \
-  '(--without-recommends)--with-recommends[install recommended packages when installing new packages]' \
-  '(--without-suggests)--with-suggests[install suggested packages when installing new packages]' \
-  '(--with-recommends)--without-recommends[ignore recommended packages when installing new packages]' \
-  '(--with-suggests)--without-suggests[ignore suggested packages when installing new packages]' \
-  '1: :->cmds' \
-  '*: :->args' && ret=0
-
-case $state in
-  cmds)
-    cmds=( ${${(M)${(f)"$(LC_ALL=C _call_program commands aptitude -h 2>/dev/null)"}:#* - *}/(#b) (*[^ ]) #- (*)/$match[1]:$match[2]:l})
-
-    _describe -t commands 'aptitude command' cmds && ret=0
-  ;;
-  args)
-    case $line[1] in
-      search)
-        _message -e patterns pattern
-      ;;
-      download|show)
-        _deb_packages avail && ret=0
-      ;;
-      remove|purge|hold)
-        _deb_packages installed && ret=0
-      ;;
-      install|markauto|unmarkauto)
-        _deb_packages uninstalled && ret=0
-      ;;
-      *)
-        (( ret )) && _message 'no more arguments'
-      ;;
-    esac
-  ;;
-esac
-
-return ret

+ 0 - 31
.zsh.d/functions.d/_invoke-rc.d

@@ -1,31 +0,0 @@
-#compdef invoke-rc.d
-
-local state ret=-1
-
-_arguments -C \
-    '(- 1 *)--help[display usage help]' \
-    '--quiet[quiet mode, no error messages displayed]' \
-    '--try-anyway[try to run script while non-fatal error is detected]' \
-    '--disclose-deny[return status code 101 instead of 0 if the script action is denied]' \
-    '--query[returns one of the status codes 100-106. Does not run the init script]' \
-    '--no-fallback[ignore any fallback action requests by the policy]' \
-    '--force[try to run the init script regardless of policy and errors]' \
-    '1:service:_services' \
-    '2:service action:->saction' \
-    '*::arguments _normal' \
-    && ret=0
-
-case $state in
-    saction)
-	case $words[CURRENT-1] in
-	    --*)
-		;;
-	    *)
-		actions=($(sed -ne "y/|/ /; s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" /etc/init.d/$words[CURRENT-1]))
-		 _wanted actions expl actions compadd $actions
-		;;
-	esac
-	;;
-esac
-
-return ret

+ 0 - 67
.zsh.d/functions.d/_weechat

@@ -1,67 +0,0 @@
-#compdef weechat-curses
-
-local state ret=-1
-
-_arguments -s -C \
-    '(-a --no-connect)'{-a,--no-connect}'[disable auto-connect to servers at startup]' \
-    '(-c --config)'{-c,--config}'[display config file options]' \
-    '(-d --dir)'{-d,--dir}'[set WeeChat home directory (default: ~/.weechat)]:dir:_dir_list' \
-    '(-f --key-functions)'{-f,--key-functions}'[display WeeChat internal functions for keys]' \
-    '(-h --help)'{-h,--help}'[display help and usage]' \
-    '(-i --irc-commands)'{-i,--irc-commands}'[display IRC commands]' \
-    '(-k --keys)'{-k,--keys}'[display WeeChat default keys]' \
-    '(-l --license)'{-l,--license}'[display WeeChat license]' \
-    '(-p --no-plugin)'{-p,--no-plugin}"[don't load any plugin at startup]" \
-    '(-v --version)'{-v,--version}'[display WeeChat version]' \
-    '(-w --weechat-commands)'{-w,--weechat-commands}'[display WeeChat commands]' \
-    '1:url:->weeurl' \
-    '*::arguments _normal' \
-    && ret=0
-
-
-if [ "$state" = 'weeurl' ]; then
-
-    urls=( irc:// ircs:// irc6:// irc6s:// )
-
-    nicks=( $(grep server_nick ~/.weechat/weechat.rc | tr -d '"' | cut -d ' ' -f3 | tr '\n' ' ') )
-    nicks+=('undef')
-    
-    pass=( $(grep server_password ~/.weechat/weechat.rc | tr -d '"' | cut -d ' ' -f3 | tr '\n' ' ') )
-    pass+=('undef')
-    
-    servers=( $(grep server_address ~/.weechat/weechat.rc | tr -d '"' | cut -d ' ' -f3 | tr '\n' ' ') )
-    servers+=('undef')
-    
-    set -a weeconf
-    
-    weeconf=()
-    for u in $urls ; do
-	for n in $nicks ; do
-	    for p in $pass; do
-		for s in $servers; do
-		    value=$u
-		    if [ "$n" != 'undef' ]; then
-			if [ "$p" != 'undef' ]; then
-			    value="${value}${n}:${p}"
-			else
-			    value="${value}${n}"
-			fi
-			if [ "$s" != 'undef' ]; then
-			    value="${value}@${s}"
-			fi
-		    else
-			if [ "$s" != 'undef' ]; then
-			    value="${value}${s}"
-			fi
-		    fi
-		    weeconf+=( $value )
-		done
-	    done
-	done
-    done
-    
-    _wanted weeconf expl weeconf compadd $weeconf
-    
-fi
-
-return ret

+ 7 - 0
.zsh.d/lib.d/common.zsh

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

+ 5 - 7
.zsh.d/os.d/FreeBSD.zsh

@@ -1,14 +1,10 @@
 
 # FreeBSD stuff
 
-# using colortail if available
-[ -x "$(whence colortail)" ] && alias lm="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog"
-
 # GNU ls(1) from FreeBSD ports is called gnuls(1).
-if [ -x "$(whence gnuls)" ]; then
+if -exe gnuls ; then
     if [ "$TERM" != "dumb" ]; then
 	eval $(gdircolors -b)
-	
 	alias ls="gnuls -h --color=auto"
 	alias l="gnuls -lh --color=auto"
     else
@@ -27,7 +23,9 @@ else
 fi
 
 # GNU tar is called gtar 
-[ -x "$(whence gtar)" ] && alias tar="gtar"
+-exe gtar \
+    && alias tar="gtar"
 
 # GNU find is called gfind
-[ -x "$(whence gfind)" ] && alias find="gfind"
+-exe gfind \
+    && alias find="gfind"

+ 2 - 1
.zsh.d/os.d/Linux.zsh

@@ -4,7 +4,8 @@
 [ -r /etc/debian_version ] && source $DOTZSHDIR/os.d/Debian.zsh
 
 if [ "$TERM" != "dumb" ]; then
-    [ -x =dircolors ] && eval $(dircolors -b)
+    -exe dircolors \
+	&& eval $(dircolors -b)
     
     alias ls="ls -h --color=auto"
     alias l="ls -lh --color=auto"

+ 7 - 8
.zsh.d/os.d/OpenBSD.zsh

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

+ 6 - 6
.zsh.d/os.d/SunOS.zsh

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

+ 7 - 25
.zsh.d/zshrc

@@ -6,29 +6,11 @@
 #  but WITHOUT ANY WARRANTY
 #
 
-# editor
-export EDITOR="emacs"
-
-# email address
-export EMAIL="kolter@openics.org"
-
-# email address for anonymous ftp
-export EMAIL_ADDR=pwet@dev.null
-
 # redefine PATH
 export PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/games
 
 # define personal zsh config directory
-if [ -n "$APPSHOME" ] ; then
-    export DOTZSHDIR="$APPSHOME/.zsh.d"
-else
-    export DOTZSHDIR="$HOME/.zsh.d"
-fi
-
-# checking events on system (users login/logout, etc...)
-watch=(notme)
-LOGCHECK=5
-WATCHFMT="[%T] %n has %a %l from %M"
+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 !!)
@@ -39,14 +21,16 @@ autoload -U compinit
 autoload -U complist
 compinit
 
-# override default umask
-umask 0022
+# include custom functions
+for f in $DOTZSHDIR/lib.d/*.zsh; do
+    [ -r "$f" ] && source $f
+done
 
 # per OS resource file
 local os=$(uname)
 [ -r "$DOTZSHDIR/os.d/${os}.zsh" ] && source "$DOTZSHDIR/os.d/${os}.zsh"
 
-# sourcing resource files
+# sourcing config files
 for f in $DOTZSHDIR/config.d/*.zsh; do
     [ -r "$f" ] && source $f
 done
@@ -59,9 +43,7 @@ if [ "$SUDO_USER" -a $UID = 0 ]; then
     # ugly hack : reset some file perms to normal to avoid warnings
     chmod 0644 ~/.zcompdump
     chown $SUDO_USER:$SUDO_USER ~/.zcompdump
-
-    # unsetting TMPDIR when logged as root
-    [ -z "$TMPDIR" ] && unset TMPDIR
+    
 fi
 
 # sourcing extra file