]> gitweb.pimeys.fr Git - config-20-100.git/blob - .zsh/rc/extra/03_profiling
Ajout du zshrc, même s'il manque encore de commentaires etc.
[config-20-100.git] / .zsh / rc / extra / 03_profiling
1 #!/bin/zsh
2
3 # directory based profiles {{{
4
5 CHPWD_PROFILE='default'
6 function chpwd_profiles() {
7 # Say you want certain settings to be active in certain directories.
8 # This is what you want.
9 #
10 # zstyle ':chpwd:profiles:/usr/src/grml(|/|/*)' profile grml
11 # zstyle ':chpwd:profiles:/usr/src/debian(|/|/*)' profile debian
12 #
13 # When that's done and you enter a directory that matches the pattern
14 # in the third part of the context, a function called chpwd_profile_grml,
15 # for example, is called (if it exists).
16 #
17 # If no pattern matches (read: no profile is detected) the profile is
18 # set to 'default', which means chpwd_profile_default is attempted to
19 # be called.
20 #
21 # A word about the context (the ':chpwd:profiles:*' stuff in the zstyle
22 # command) which is used: The third part in the context is matched against
23 # ${PWD}. That's why using a pattern such as /foo/bar(|/|/*) makes sense.
24 # Because that way the profile is detected for all these values of ${PWD}:
25 # /foo/bar
26 # /foo/bar/
27 # /foo/bar/baz
28 # So, if you want to make double damn sure a profile works in /foo/bar
29 # and everywhere deeper in that tree, just use (|/|/*) and be happy.
30 #
31 # The name of the detected profile will be available in a variable called
32 # 'profile' in your functions. You don't need to do anything, it'll just
33 # be there.
34 #
35 # Then there is the parameter $CHPWD_PROFILE is set to the profile, that
36 # was is currently active. That way you can avoid running code for a
37 # profile that is already active, by running code such as the following
38 # at the start of your function:
39 #
40 # function chpwd_profile_grml() {
41 # [[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
42 # ...
43 # }
44 #
45 # The initial value for $CHPWD_PROFILE is 'default'.
46 #
47 # Version requirement:
48 # This feature requires zsh 4.3.3 or newer.
49 # If you use this feature and need to know whether it is active in your
50 # current shell, there are several ways to do that. Here are two simple
51 # ways:
52 #
53 # a) If knowing if the profiles feature is active when zsh starts is
54 # good enough for you, you can put the following snippet into your
55 # .zshrc.local:
56 #
57 # (( ${+functions[chpwd_profiles]} )) && print "directory profiles active"
58 #
59 # b) If that is not good enough, and you would prefer to be notified
60 # whenever a profile changes, you can solve that by making sure you
61 # start *every* profile function you create like this:
62 #
63 # function chpwd_profile_myprofilename() {
64 # [[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
65 # print "chpwd(): Switching to profile: $profile"
66 # ...
67 # }
68 #
69 # That makes sure you only get notified if a profile is *changed*,
70 # not everytime you change directory, which would probably piss
71 # you off fairly quickly. :-)
72 #
73 # There you go. Now have fun with that.
74 local -x profile
75
76 zstyle -s ":chpwd:profiles:${PWD}" profile profile || profile='default'
77 if (( ${+functions[chpwd_profile_$profile]} )) ; then
78 chpwd_profile_${profile}
79 fi
80
81 CHPWD_PROFILE="${profile}"
82 return 0
83 }
84 # When pwd changes, the functions in this array are
85 # executed.
86 chpwd_functions=( ${chpwd_functions} chpwd_profiles )