# Global Order: zshenv, zprofile, zshrc, zlogin
################################################################################
+# Contributing:
+# If you want to help to improve grml's zsh setup, clone the grml-etc-core
+# repository from git.grml.org:
+# git clone git://git.grml.org/grml-etc-core.git
+#
+# Make your changes, commit them; use 'git format-patch' to create a series
+# of patches and send those to the following address via 'git send-email':
+# grml-etc-core@grml.org
+#
+# Doing so makes sure the right people get your patches for review and
+# possibly inclusion.
+
# zsh-refcard-tag documentation: {{{
# You may notice strange looking comments in this file.
# These are there for a purpose. grml's zsh-refcard can now be
return 1
}
+is433(){
+ [[ $ZSH_VERSION == 4.3.<3->* || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
#f1# Checks whether or not you're running grml
isgrml(){
[[ -f /etc/grml_version ]] && return 0
NOCOR=${NOCOR:-0}
NOMENU=${NOMENU:-0}
NOPRECMD=${NOPRECMD:-0}
+COMMAND_NOT_FOUND=${COMMAND_NOT_FOUND:-0}
+GRML_ZSH_CNF_HANDLER=${GRML_ZSH_CNF_HANDLER:-/usr/share/command-not-found/command-not-found}
BATTERY=${BATTERY:-0}
GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
GRML_ALWAYS_LOAD_ALL=${GRML_ALWAYS_LOAD_ALL:-0}
# this function checks if a command exists and returns either true
# or false. This avoids using 'which' and 'whence', which will
# avoid problems with aliases for which on certain weird systems. :-)
+# Usage: check_com [-c|-g] word
+# -c only checks for external commands
+# -g does the usual tests and also checks for global aliases
check_com() {
- local -i comonly
+ local -i comonly gatoo
if [[ ${1} == '-c' ]] ; then
(( comonly = 1 ))
shift
+ elif [[ ${1} == '-g' ]] ; then
+ (( gatoo = 1 ))
else
(( comonly = 0 ))
+ (( gatoo = 0 ))
fi
if (( ${#argv} != 1 )) ; then
return 0
fi
+ if (( gatoo > 0 )) && [[ -n ${galiases[$1]} ]] ; then
+ return 0
+ fi
+
return 1
}
# this allows us to stay in sync with grml's zshrc and put own
# modifications in ~/.zshrc.local
zrclocal() {
+ xsource "/etc/zsh/zshrc.local"
xsource "${HOME}/.zshrc.local"
return 0
}
# locale setup {{{
xsource "/etc/default/locale"
-export LANG=${LANG:-en_US.iso885915}
-for var in LC_ALL LC_MESSAGES ; do
+for var in LANG LC_ALL LC_MESSAGES ; do
[[ -n ${(P)var} ]] && export $var
done
fi
fi
+# support colors in less
+export LESS_TERMCAP_mb=$'\E[01;31m'
+export LESS_TERMCAP_md=$'\E[01;31m'
+export LESS_TERMCAP_me=$'\E[0m'
+export LESS_TERMCAP_se=$'\E[0m'
+export LESS_TERMCAP_so=$'\E[01;44;33m'
+export LESS_TERMCAP_ue=$'\E[0m'
+export LESS_TERMCAP_us=$'\E[01;32m'
+
# automatically remove duplicates from these arrays
typeset -U path cdpath fpath manpath
# }}}
zrcautoload run-help # use via 'esc-h'
# completion system
-if zrcautoload compinit && compinit 2>/dev/null ; then
- compinit 2>/dev/null || print 'Notice: no compinit available :('
+if zrcautoload compinit ; then
+ compinit || print 'Notice: no compinit available :('
else
print 'Notice: no compinit available :('
function zstyle { }
# }}}
+# directory based profiles {{{
+
+if is433 ; then
+
+CHPWD_PROFILE='default'
+function chpwd_profiles() {
+ # Say you want certain settings to be active in certain directories.
+ # This is what you want.
+ #
+ # zstyle ':chpwd:profiles:/usr/src/grml(|/|/*)' profile grml
+ # zstyle ':chpwd:profiles:/usr/src/debian(|/|/*)' profile debian
+ #
+ # When that's done and you enter a directory that matches the pattern
+ # in the third part of the context, a function called chpwd_profile_grml,
+ # for example, is called (if it exists).
+ #
+ # If no pattern matches (read: no profile is detected) the profile is
+ # set to 'default', which means chpwd_profile_default is attempted to
+ # be called.
+ #
+ # A word about the context (the ':chpwd:profiles:*' stuff in the zstyle
+ # command) which is used: The third part in the context is matched against
+ # ${PWD}. That's why using a pattern such as /foo/bar(|/|/*) makes sense.
+ # Because that way the profile is detected for all these values of ${PWD}:
+ # /foo/bar
+ # /foo/bar/
+ # /foo/bar/baz
+ # So, if you want to make double damn sure a profile works in /foo/bar
+ # and everywhere deeper in that tree, just use (|/|/*) and be happy.
+ #
+ # The name of the detected profile will be available in a variable called
+ # 'profile' in your functions. You don't need to do anything, it'll just
+ # be there.
+ #
+ # Then there is the parameter $CHPWD_PROFILE is set to the profile, that
+ # was is currently active. That way you can avoid running code for a
+ # profile that is already active, by running code such as the following
+ # at the start of your function:
+ #
+ # function chpwd_profile_grml() {
+ # [[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
+ # ...
+ # }
+ #
+ # The initial value for $CHPWD_PROFILE is 'default'.
+ #
+ # Version requirement:
+ # This feature requires zsh 4.3.3 or newer.
+ # If you use this feature and need to know whether it is active in your
+ # current shell, there are several ways to do that. Here are two simple
+ # ways:
+ #
+ # a) If knowing if the profiles feature is active when zsh starts is
+ # good enough for you, you can put the following snippet into your
+ # .zshrc.local:
+ #
+ # (( ${+functions[chpwd_profiles]} )) && print "directory profiles active"
+ #
+ # b) If that is not good enough, and you would prefer to be notified
+ # whenever a profile changes, you can solve that by making sure you
+ # start *every* profile function you create like this:
+ #
+ # function chpwd_profile_myprofilename() {
+ # [[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
+ # print "chpwd(): Switching to profile: $profile"
+ # ...
+ # }
+ #
+ # That makes sure you only get notified if a profile is *changed*,
+ # not everytime you change directory, which would probably piss
+ # you off fairly quickly. :-)
+ #
+ # There you go. Now have fun with that.
+ local -x profile
+
+ zstyle -s ":chpwd:profiles:${PWD}" profile profile || profile='default'
+ if (( ${+functions[chpwd_profile_$profile]} )) ; then
+ chpwd_profile_${profile}
+ fi
+
+ CHPWD_PROFILE="${profile}"
+ return 0
+}
+chpwd_functions=( ${chpwd_functions} chpwd_profiles )
+
+fi # is433
+
+# }}}
+
# {{{ display battery status on right side of prompt via running 'BATTERY=1 zsh'
if [[ $BATTERY -gt 0 ]] ; then
if ! check_com -c acpi ; then
}
# }}}
VCS_INFO_hg_get_data () { # {{{
- local hgbranch hgbase
+ local hgbranch hgbase file
hgbase=${vcs_comm[basedir]}
- hgbranch=$(< ${hgbase}/.hg/branch)
+
+ file="${hgbase}/.hg/branch"
+ if [[ -r ${file} ]] ; then
+ hgbranch=$(< ${file})
+ else
+ hgbranch='default'
+ fi
+
VCS_INFO_formats '' "${hgbranch}" "${hgbase}"
return 0
}
while [[ ${realbasedir} != '/' ]]; do
if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
[[ -d ${basedir}/${dirname} ]] && \
- [[ -f ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
+ [[ -e ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
break
else
[[ -d ${basedir}/${dirname} ]] && break
# }}}
VCS_INFO_hg_detect() { #{{{
VCS_INFO_check_com hg || return 1
- vcs_comm[detect_need_file]=branch
+ vcs_comm[detect_need_file]=store
VCS_INFO_detect_by_dir '.hg'
return $?
}
# }}}
+# command not found handling {{{
+
+(( ${COMMAND_NOT_FOUND} == 1 )) &&
+function command_not_found_handler() {
+ setopt localoptions no_sh_wordsplit
+ if [[ -x ${GRML_ZSH_CNF_HANDLER} ]] ; then
+ ${GRML_ZSH_CNF_HANDLER} $1
+ fi
+ return 1
+}
+
+# }}}
+
# {{{ set prompt
if zrcautoload promptinit && promptinit 2>/dev/null ; then
promptinit # people should be able to use their favourite prompt
# adjust title of xterm
[[ ${NOTITLE} -gt 0 ]] && return 0
case $TERM in
- (xterm*|rxvt)
+ (xterm*|rxvt*)
print -Pn "\e]0;%n@%m: $1\a"
;;
esac
alias term2utf="echo 'Setting terminal to utf-8 mode'; print -n '\e%G'"
# make sure it is not assigned yet
-[[ $(whence -w utf2iso &>/dev/null) == 'utf2iso: alias' ]] && unalias utf2iso
-
+[[ -n ${aliases[utf2iso]} ]] && unalias utf2iso
utf2iso() {
if isutfenv ; then
for ENV in $(env | command grep -i '.utf') ; do
}
# make sure it is not assigned yet
-[[ $(whence -w iso2utf &>/dev/null) == 'iso2utf: alias' ]] && unalias iso2utf
+[[ -n ${aliases[iso2utf]} ]] && unalias iso2utf
iso2utf() {
if ! isutfenv ; then
for ENV in $(env | command grep -i '\.iso') ; do
"NOTITLE=1 zsh" => disable setting the title of xterms without disabling
preexec() and precmd() completely
"BATTERY=1 zsh" => activate battery status (via acpi) on right side of prompt
+ "COMMAND_NOT_FOUND=1 zsh"
+ => Enable a handler if an external command was not found
+ The command called in the handler can be altered by setting
+ the GRML_ZSH_CNF_HANDLER variable, the default is:
+ "/usr/share/command-not-found/command-not-found"
A value greater than 0 is enables a feature; a value equal to zero
disables it. If you like one or the other of these settings, you can
fi
#a1# Take a look at the syslog: \kbd{\$PAGER /var/log/syslog}
- alias llog="$PAGER /var/log/syslog" # take a look at the syslog
+ salias llog="$PAGER /var/log/syslog" # take a look at the syslog
#a1# Take a look at the syslog: \kbd{tail -f /var/log/syslog}
- alias tlog="tail -f /var/log/syslog" # follow the syslog
+ salias tlog="tail -f /var/log/syslog" # follow the syslog
fi
# sort installed Debian-packages by size
# use generic completion system for programs not yet defined; (_gnu_generic works
# with commands that provide a --help option with "standard" gnu-like output.)
- for compcom in tail head feh cp mv df stow uname ipacsum fetchipac; do
+ for compcom in cp deborphan df feh fetchipac head hnb ipacsum mv \
+ pal stow tail uname ; do
[[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
done; unset compcom
for color in BLUE RED GREEN CYAN YELLOW MAGENTA WHITE ; unset $color
# }}}
-# source another config file if present {{{
-xsource "/etc/zsh/zshrc.local"
-# }}}
-
# "persistent history" {{{
# just write important commands you always need to ~/.important_commands
if [[ -r ~/.important_commands ]] ; then
#a2# Execute \kbd{./configure --help}
alias CH="./configure --help"
-# http://conkeror.mozdev.org/
-# TODO: I think this should be removed, as conkeror is not a simple extension anymore
-#a2# Run a keyboard driven firefox
-alias conkeror='firefox -chrome chrome://conkeror/content'
-
# arch/tla stuff
if check_com -c tla ; then
#a2# Execute \kbd{tla what-changed --diffs | less}
# Use 'g' instead of 'git':
check_com g || alias g='git'
-# use colors when browsing man pages, but only if not using LESS_TERMCAP_* from /etc/zsh/zshenv:
-if [[ -z "$LESS_TERMCAP_md" ]] ; then
- [[ -d ~/.terminfo/ ]] && alias man='TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man'
-fi
-
# check whether Debian's package management (dpkg) is running
if check_com salias ; then
#a2# Check whether a dpkg instance is currently running
#a2# Execute \kbd{grep -i -{}-color=auto}
alias GREP='grep -i --color=auto'
-# one blank line between each line
-if [[ -r ~/.terminfo/m/mostlike ]] ; then
- #f5# Watch manpages in a stretched style
- man2() { PAGER='dash -c "sed G | /usr/bin/less"' TERM=mostlike /usr/bin/man "$@" ; }
-fi
+#f5# Watch manpages in a stretched style
+man2() { PAGER='dash -c "sed G | /usr/bin/less"' command man "$@" ; }
# d():Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
# note: option AUTO_PUSHD has to be set