summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2020-05-06 20:28:41 +0200
committerTobias Klauser <tklauser@distanz.ch>2020-05-06 20:28:41 +0200
commitf43fa69cbc865b2ca03cbcabf88985668d4ffc9b (patch)
tree8d79cde34578fc4dcfd0ec0a9297aba0c356bf56
parent5940685a9501343c6d39512372b520af5ae76b66 (diff)
zshrc: update chpwd_profiles to latest verison from grml etc-core
See https://github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc Also replace zhinst by isovalent profile and drop some zhinst specific profile paths.
-rw-r--r--.zsh/zshrc/90_profiles103
1 files changed, 22 insertions, 81 deletions
diff --git a/.zsh/zshrc/90_profiles b/.zsh/zshrc/90_profiles
index 18ecf00..813082f 100644
--- a/.zsh/zshrc/90_profiles
+++ b/.zsh/zshrc/90_profiles
@@ -13,14 +13,10 @@
CHPWD_PROFILE='default'
-zstyle ':chpwd:profiles:/home/tklauser/go(|/|/*)' profile distanz
-zstyle ':chpwd:profiles:/home/tobiask/go(|/|/*)' profile distanz
-zstyle ':chpwd:profiles:/home/tklauser/src(|/|/*)' profile distanz
-zstyle ':chpwd:profiles:/home/tobiask/src(|/|/*)' profile distanz
-zstyle ':chpwd:profiles:/scratch/tobiask/go(|/|/*)' profile distanz
-zstyle ':chpwd:profiles:/home/tobiask/zi(|/|/*)' profile zhinst
-zstyle ':chpwd:profiles:/scratch/tobiask/zi(|/|/*)' profile zhinst
-zstyle ':chpwd:profiles:/scratch/yocto-zi(|/|/*)' profile zhinst
+zstyle ':chpwd:profiles:/home/tklauser/go/src/github.com/isovalent(|/|/*)' profile isovalent
+zstyle ':chpwd:profiles:/home/tklauser/go/src/github.com/covalentio(|/|/*)' profile isovalent
+zstyle ':chpwd:profiles:/home/tklauser/go(|/|/*)' profile distanz
+zstyle ':chpwd:profiles:/home/tklauser/src(|/|/*)' profile distanz
chpwd_profile_distanz()
{
@@ -31,88 +27,33 @@ chpwd_profile_distanz()
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
}
-chpwd_profile_zhinst()
+chpwd_profile_isovalent()
{
[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
print "chpwd(): Switching to profile: $profile"
- export GIT_AUTHOR_EMAIL="tobias.klauser@zhinst.com"
+ export GIT_AUTHOR_EMAIL="tobias@isovalent.com"
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
}
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
+ local profile context
+ local -i reexecute
- zstyle -s ":chpwd:profiles:${PWD}" profile profile || profile='default'
- if (( ${+functions[chpwd_profile_$profile]} )) ; then
- chpwd_profile_${profile}
+ context=":chpwd:profiles:$PWD"
+ zstyle -s "$context" profile profile || profile='default'
+ zstyle -T "$context" re-execute && reexecute=1 || reexecute=0
+
+ if (( ${+parameters[CHPWD_PROFILE]} == 0 )); then
+ typeset -g CHPWD_PROFILE
+ local CHPWD_PROFILES_INIT=1
+ (( ${+functions[chpwd_profiles_init]} )) && chpwd_profiles_init
+ elif [[ $profile != $CHPWD_PROFILE ]]; then
+ (( ${+functions[chpwd_leave_profile_$CHPWD_PROFILE]} )) \
+ && chpwd_leave_profile_${CHPWD_PROFILE}
+ fi
+ if (( reexecute )) || [[ $profile != $CHPWD_PROFILE ]]; then
+ (( ${+functions[chpwd_profile_$profile]} )) && chpwd_profile_${profile}
fi
CHPWD_PROFILE="${profile}"