X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=cce085906711bfaea80918fa0f441f217d5e28d6;hb=1f3015211e686da1dcae9dd7af35e40df24afe7d;hp=7773ed91a34920d50a4b305f5fc19396771f1014;hpb=1cf274b4162d9b93013c1738e26fed76186217ce;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 7773ed9..cce0859 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -1031,6 +1031,55 @@ chpwd() { # }}} +# directory based profiles {{{ + +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 patches (read: no profile is detected) the profile is + # set to 'default', which means chpwd_profile_default is attempted to + # be called. + # + # 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'. + # + # 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 ) + +# }}} + # {{{ display battery status on right side of prompt via running 'BATTERY=1 zsh' if [[ $BATTERY -gt 0 ]] ; then if ! check_com -c acpi ; then