From 06c5e2becdfd9293aa8d90d3e517ef1f03ac653c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 22 Nov 2009 12:52:49 +0100 Subject: make the zshrc work without packages/zsh/etc --- etc/functions/chpwd | 6 ----- etc/functions/dirinfo | 19 -------------- etc/functions/salias | 37 --------------------------- etc/functions/xhashd | 7 ----- etc/functions/xsource | 22 ---------------- etc/rc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 69 insertions(+), 93 deletions(-) delete mode 100644 etc/functions/chpwd delete mode 100644 etc/functions/dirinfo delete mode 100644 etc/functions/salias delete mode 100644 etc/functions/xhashd delete mode 100644 etc/functions/xsource (limited to 'etc') diff --git a/etc/functions/chpwd b/etc/functions/chpwd deleted file mode 100644 index e950844..0000000 --- a/etc/functions/chpwd +++ /dev/null @@ -1,6 +0,0 @@ -## vim:ft=zsh - -# This all belongs into the prompt, but since it only changes -# when changing directories, it's more efficient to do it here -psvar[1]=$(dirinfo) -psvar[2]=$(rtab) diff --git a/etc/functions/dirinfo b/etc/functions/dirinfo deleted file mode 100644 index 689c20f..0000000 --- a/etc/functions/dirinfo +++ /dev/null @@ -1,19 +0,0 @@ -## vim:ft=zsh -## Collect some directory information for the prompt - -typeset string - -[[ -r .todo ]] && string+='todo ' -[[ -f .fehindex.jpg ]] && string+='feh ' -[[ -d .hg ]] && string+='hg ' -[[ -d .git ]] && string+='git ' -[[ -d .svn ]] && string+='svn ' -[[ -f Makefile || -f makefile ]] && string+='make ' - -# if we're running in screen, we're the only one writing into the prompt -# -> no trailing whitespace -if [[ $TERM == screen ]] { - echo ${string% } -} else { - echo $string -} diff --git a/etc/functions/salias b/etc/functions/salias deleted file mode 100644 index d8a3340..0000000 --- a/etc/functions/salias +++ /dev/null @@ -1,37 +0,0 @@ -## vim:ft=zsh -## creates an alias and precedes the command with sudo if $EUID is not zero. -## Taken from the grml zshrc - http://grml.org -local only=0 -local multi=0 -while [[ ${1} == -* ]] ; do - case ${1} in - (-o) only=1 ;; - (-a) multi=1 ;; - (--) shift ; break ;; - (-h) - printf 'usage: salias [-h|-o|-a] \n' - printf ' -h shows this help text.\n' - printf ' -a replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n' - printf ' be careful using this option.\n' - printf ' -o only sets an alias if a preceding sudo would be needed.\n' - return 0 - ;; - (*) printf "unkown option: '%s'\n" "${1}" ; return 1 ;; - esac - shift -done - -if (( ${#argv} > 1 )) ; then - printf 'Too many arguments %s\n' "${#argv}" - return 1 -fi - -key="${1%%\=*}" ; val="${1#*\=}" -if (( EUID == 0 )) && (( only == 0 )); then - alias -- "${key}=${val}" -elif (( EUID > 0 )) ; then - (( multi > 0 )) && val="${val// ; / ; sudo }" - alias -- "${key}=sudo ${val}" -fi - -return 0 diff --git a/etc/functions/xhashd b/etc/functions/xhashd deleted file mode 100644 index 2909ea7..0000000 --- a/etc/functions/xhashd +++ /dev/null @@ -1,7 +0,0 @@ -## vim:ft=zsh -## hash a directory if it exists -typeset directory=${~1#*\=} name=${1%%\=*} - -if [[ -d $directory ]] { - hash -d $name=$directory -} diff --git a/etc/functions/xsource b/etc/functions/xsource deleted file mode 100644 index 50ad5be..0000000 --- a/etc/functions/xsource +++ /dev/null @@ -1,22 +0,0 @@ -## vim:ft=zsh -# Note: This function's behaviour differs hrom source. -# With source, parameters declared local are available to the sourcing script. -# With xsource, parameters declared local will NOT be available unless you use -# eval $(xsource -e file) -typeset -i eval=0 - -while [[ $1 == -* ]] { - case $1 in - -e) eval=1 ;; - esac - shift -} - - -if [[ -r $1 ]] { - if (( eval )) { - echo source $1 - } else { - source $1 - } -} diff --git a/etc/rc b/etc/rc index 7e15436..240b940 100644 --- a/etc/rc +++ b/etc/rc @@ -142,7 +142,71 @@ autoload -U compinit autoload zargs # own functions -autoload $ZDIR/functions/*(:t) +if [[ -e $ZDIR/functions ]] { + autoload $ZDIR/functions/*(:t) +} else { + zrc_info "No functions dir found, assuming standalone mode" + # The presence of rtab is generally assumed + function rtab { + print -P %~ + } +} + + +# This all belongs into the prompt, but since it only changes +# when changing directories, it's more efficient to do it here +function chpwd { + psvar[1]=$(dirinfo) + psvar[2]=$(rtab) +} + +## Collect some directory information for the prompt +function dirinfo { + typeset string + + [[ -r .todo ]] && string+='todo ' + [[ -f .fehindex.jpg ]] && string+='feh ' + [[ -d .hg ]] && string+='hg ' + [[ -d .git ]] && string+='git ' + [[ -d .svn ]] && string+='svn ' + [[ -f Makefile || -f makefile ]] && string+='make ' + + # if we're running in screen, we're the only one writing into the prompt + # -> no trailing whitespace + if [[ $TERM == screen ]] { + echo ${string% } + } else { + echo $string + } +} + +# Inspired by salias from the grml zshrc +function salias { + typeset key=${1%%\=*} val=${1#*\=} + + if (( EUID == 0 )) { + alias -- $key=$val + } else { + alias -- $key="sudo $val" + } +} + +# hash a directory only if it exists +function xhashd { + typeset directory=${~1#*\=} name=${1%%\=*} + + if [[ -d $directory ]] { + hash -d $name=$directory + } +} + +# source a file only if it exists. +# Note: local assignments (typeset foo=bar) are lost. export foo=bar works. +function xsource { + if [[ -r $1 ]] { + source $1 + } +} function Status Start Stop Restart Reload { typeset script sudo @@ -469,7 +533,10 @@ chpwd # {{{ Includes -source $ZDIR/../provided/includes +# no xsource here - typeset may be used +if [[ -e $ZDIR/../provided/includes ]] { + source $ZDIR/../provided/includes +} # local configuration, not in git xsource $ZDIR/local -- cgit v1.2.3