summaryrefslogtreecommitdiff
path: root/.zsh/zshrc/90_profiles
blob: a10aa0091523a509453c1e7ab5d48d1486e59fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# zshrc/90_profiles
#
# set up directory specific variables and options
#
# http://michael-prokop.at/blog/2009/05/30/directory-specific-shell-configuration-with-zsh
#
# chpwd_profiles taken from grml zshrc
#
# Copyright © 2010-2017 Tobias Klauser <tklauser@distanz.ch>
# Released under the terms of the Artistic Licence 2.0
#
# Source repository: git://git.distanz.ch/dotfiles/zsh.git

CHPWD_PROFILE='default'

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/src/isovalent(|/|/*)'                 profile isovalent
zstyle ':chpwd:profiles:/home/tklauser/src/cilium/cilium.io(|/|/*)'          profile cilium
zstyle ':chpwd:profiles:/home/tklauser/go(|/|/*)'                            profile distanz
zstyle ':chpwd:profiles:/home/tklauser/src(|/|/*)'                           profile distanz

chpwd_profile_distanz()
{
	[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
	print "chpwd(): Switching to profile: $profile"

	export GIT_AUTHOR_EMAIL="tklauser@distanz.ch"
	export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
}

chpwd_profile_cilium()
{
	[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
	print "chpwd(): Switching to profile: $profile"

	export GIT_AUTHOR_EMAIL="tobias@cilium.io"
	export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
}

chpwd_profile_isovalent()
{
	[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
	print "chpwd(): Switching to profile: $profile"

	export GIT_AUTHOR_EMAIL="tobias@isovalent.com"
	export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
}

function chpwd_profiles() {
    local profile context
    local -i reexecute

    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}"
    return 0
}
chpwd_functions=( ${chpwd_functions} chpwd_profiles )


# vim:ft=zsh