X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=d142ef04346b99d48248de139cc2549a56d120e5;hb=23c7c4da79c3253ea5f7bfcb6c55937f9866973d;hp=80d9255357f2f47e1d422a8d6389dfb15cbc605c;hpb=bc37cee39c352813cf3aa420eec5ae25dc77d9fd;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 80d9255..d142ef0 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -11,6 +11,18 @@ # 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 @@ -121,6 +133,11 @@ is43(){ 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 @@ -230,6 +247,8 @@ zrcautoload is-at-least || is-at-least() { return 1 } 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} @@ -446,6 +465,7 @@ xunfunction() { # 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 } @@ -455,8 +475,7 @@ zrclocal() { # 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 @@ -628,6 +647,14 @@ grml_toggle_abbrev() { zle -N grml_toggle_abbrev bindkey '^xA' grml_toggle_abbrev +# add a command line to the shells history without executing it +commit-to-history() { + print -s ${(z)BUFFER} + zle send-break +} +zle -N commit-to-history +bindkey "^x^h" commit-to-history + # }}} # a generic accept-line wrapper {{{ @@ -1021,6 +1048,95 @@ chpwd() { # }}} +# 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 @@ -1617,10 +1733,17 @@ VCS_INFO_git_get_data () { # {{{ } # }}} 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 } @@ -1681,7 +1804,7 @@ VCS_INFO_detect_by_dir() { #{{{ 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 @@ -1735,7 +1858,7 @@ VCS_INFO_git_detect() { #{{{ # }}} 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 $? } @@ -1905,6 +2028,19 @@ fi # }}} +# 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 @@ -1969,7 +2105,7 @@ preexec () { # 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 @@ -2193,6 +2329,11 @@ the zsh yet. :) "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 @@ -2255,9 +2396,9 @@ if [[ -r /etc/debian_version ]] ; then 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 @@ -2463,7 +2604,9 @@ grmlcomp() { # use generic completion system for programs not yet defined; (_gnu_generic works # with commands that provide a --help option with "standard" gnu-like output.) - compdef _gnu_generic tail head feh cp mv df stow uname ipacsum fetchipac + for compcom in tail head feh cp mv df stow uname ipacsum fetchipac; do + [[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom} + done; unset compcom # see upgrade function in this file compdef _hosts upgrade @@ -2923,10 +3066,6 @@ exit 0; 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 @@ -2995,11 +3134,6 @@ alias CO="./configure" #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}