X-Git-Url: https://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=541eced0c0243ce632c5e31dc2556e0806f27292;hb=cf57d776c87d5b8c35cbfb6a3c4a0c04f180d561;hp=b414c936e7ed6c9528bb937aa7106c5d027006f6;hpb=595dd1e6e42c6fb8a005465c3c547c2f77a36f0c;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index b414c93..541eced 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -3,7 +3,7 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Mon Feb 11 18:00:55 CET 2008 [mika] +# Latest change: Wed Aug 06 23:50:53 CEST 2008 [mika] ################################################################################ # This file is sourced only for interactive shells. It # should contain commands to set up aliases, functions, @@ -258,6 +258,29 @@ salias() { return 0 } +# a "print -l ${(u)foo}"-workaround for pre-4.2.0 shells +# usage: uprint foo +# Where foo is the *name* of the parameter you want printed. +# Note that foo is no typo; $foo would be wrong here! +if ! is42 ; then + uprint () { + local -a u + local w + local parameter=${1} + + if [[ -z ${parameter} ]] ; then + printf 'usage: uprint \n' + return 1 + fi + + for w in ${(P)parameter} ; do + [[ -z ${(M)u:#${w}} ]] && u=( ${u} ${w} ) + done + + builtin print -l ${u} + } +fi + # Check if we can read given files and source those we can. xsource() { if (( ${#argv} < 1 )) ; then @@ -329,7 +352,7 @@ zrcautoload is-at-least || is-at-least() { return 1 } # locale setup {{{ if [[ -z "$LANG" ]] ; then - xsource "/etc/default/locale" + xsource "/etc/default/locale" fi export LANG=${LANG:-en_US.iso885915} @@ -479,6 +502,24 @@ bindkey '^Xi' insert-unicode-char # bindkey . rationalise-dot # bindkey '\eq' push-line-or-edit + +## toggle the ,. abbreviation feature on/off +# NOABBREVIATION: default abbreviation-state +# 0 - enabled (default) +# 1 - disabled +NOABBREVIATION=${NOABBREVIATION:-0} + +grml_toggle_abbrev() { + if (( ${NOABBREVIATION} > 0 )) ; then + NOABBREVIATION=0 + else + NOABBREVIATION=1 + fi +} + +zle -N grml_toggle_abbrev +bindkey '^xA' grml_toggle_abbrev + # }}} # a generic accept-line wrapper {{{ @@ -706,6 +747,12 @@ abk=( globalias() { local MATCH + + if (( NOABBREVIATION > 0 )) ; then + LBUFFER="${LBUFFER},." + return 0 + fi + matched_chars='[.-|_a-zA-Z0-9]#' LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#} LBUFFER+=${abk[$MATCH]:-$MATCH} @@ -931,21 +978,21 @@ isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history # dirstack handling {{{ -# TODO: the is42 tests are in place, because (u) requires at least 4.2.0 -# of zsh. We also disable loading potentielly old .zdir files when -# starting a pre-4.2.0 zsh. -# Implementing a workaround-(u) for older shells is the obvious -# solution here, if we want this for all supported shells. +DIRSTACKSIZE=${DIRSTACKSIZE:-20} +DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs} -DIRSTACKSIZE=20 -if is42 && [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then - dirstack=( ${(f)"$(< ~/.zdirs)"} ) +if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then + dirstack=( ${(f)"$(< $DIRSTACKFILE)"} ) # "cd -" won't work after login by just setting $OLDPWD, so [[ -d $dirstack[0] ]] && cd $dirstack[0] && cd $OLDPWD fi chpwd() { - is42 && builtin print -l ${(u)dirstack} >! ~/.zdirs + if is42 ; then + builtin print -l ${(u)dirstack} >! ${DIRSTACKFILE} + else + uprint dirstack >! ${DIRSTACKFILE} + fi } # }}} @@ -1523,6 +1570,9 @@ grmlcomp() { # Ignore completion functions for commands you don't have: zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*' + # Provide more processes in completion of programs like killall: + zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' + # complete manual by their section zstyle ':completion:*:manuals' separate-sections true zstyle ':completion:*:manuals.*' insert-sections true @@ -1558,6 +1608,9 @@ grmlcomp() { # zstyle ':completion:*' completer _complete _correct _approximate # zstyle ':completion:*' expand prefix suffix + # complete shell aliases + # zstyle ':completion:*' completer _expand_alias _complete _approximate + # command for process lists, the local web server details and host completion zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html' @@ -1804,9 +1857,33 @@ compdef _functions edfunc #m# f6 Stop() \kbd{/etc/init.d/\em{process}}\quad\kbd{stop} #m# f6 Reload() \kbd{/etc/init.d/\em{process}}\quad\kbd{reload} #m# f6 Force-Reload() \kbd{/etc/init.d/\em{process}}\quad\kbd{force-reload} -if [[ -d /etc/init.d ]] ; then +if [[ -d /etc/init.d || -d /etc/service ]] ; then + __start_stop() { + local action_="${1:l}" # e.g Start/Stop/Restart + local service_="$2" + local param_="$3" + + local service_target_="$(readlink /etc/init.d/$service_)" + if [[ $service_target_ == "/usr/bin/sv" ]]; then + # runit + case "${action_}" in + start) if [[ ! -e /etc/service/$service_ ]]; then + $SUDO ln -s "/etc/sv/$service_" "/etc/service/" + else + $SUDO "/etc/init.d/$service_" "${action_}" "$param_" + fi ;; + # there is no reload in runits sysv emulation + reload) $SUDO "/etc/init.d/$service_" "force-reload" "$param_" ;; + *) $SUDO "/etc/init.d/$service_" "${action_}" "$param_" ;; + esac + else + # sysvinit + $SUDO "/etc/init.d/$service_" "${action_}" "$param_" + fi + } + for i in Start Restart Stop Force-Reload Reload ; do - eval "$i() { $SUDO /etc/init.d/\$1 ${i:l} \$2 ; }" + eval "$i() { __start_stop $i \"\$1\" \"\$2\" ; }" done fi @@ -1996,6 +2073,7 @@ for color in BLUE RED GREEN CYAN WHITE ; unset $color # source another config file if present {{{ xsource "/etc/zsh/zshrc.local" +xsource "${HOME}/.zshenv" # }}} # "persistent history" {{{