pj.plugin.zsh 701 Bytes
Newer Older
1
alias pjo="pj open"
Toon Claes's avatar
Toon Claes committed
2

Marc Cornellà's avatar
Marc Cornellà committed
3
4
5
pj () {
    emulate -L zsh

Toon Claes's avatar
Toon Claes committed
6
    cmd="cd"
Marc Cornellà's avatar
Marc Cornellà committed
7
    project=$1
Toon Claes's avatar
Toon Claes committed
8

Marc Cornellà's avatar
Marc Cornellà committed
9
    if [[ "open" == "$project" ]]; then
10
        shift
Marc Cornellà's avatar
Marc Cornellà committed
11
        project=$*
12
        cmd=${=EDITOR}
13
    else
Marc Cornellà's avatar
Marc Cornellà committed
14
        project=$*
Toon Claes's avatar
Toon Claes committed
15
16
    fi

17
18
19
20
21
    if [[ -z "$project" ]]; then
        echo "You have to specify a project name."
        return
    fi

Marc Cornellà's avatar
Marc Cornellà committed
22
23
24
    for basedir ($PROJECT_PATHS); do
        if [[ -d "$basedir/$project" ]]; then
            $cmd "$basedir/$project"
Toon Claes's avatar
Toon Claes committed
25
26
27
28
            return
        fi
    done

Marc Cornellà's avatar
Marc Cornellà committed
29
    echo "No such project '${project}'."
Toon Claes's avatar
Toon Claes committed
30
31
}

Marc Cornellà's avatar
Marc Cornellà committed
32
_pj () {
Marc Cornellà's avatar
Marc Cornellà committed
33
34
    emulate -L zsh

35
    typeset -a projects
Marc Cornellà's avatar
Marc Cornellà committed
36
37
38
39
40
    for basedir ($PROJECT_PATHS); do
        projects+=(${basedir}/*(/N))
    done

    compadd ${projects:t}
Toon Claes's avatar
Toon Claes committed
41
42
}
compdef _pj pj