pj.plugin.zsh 721 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
6
pj () {
    emulate -L zsh
    setopt shwordsplit

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

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

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

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

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

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

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

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