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

3
function pj () {
Toon Claes's avatar
Toon Claes committed
4
5
6
7
    cmd="cd"
    file=$1

    if [[ "open" == "$file" ]] then
8
9
        shift
        file=$*
Toon Claes's avatar
Toon Claes committed
10
        cmd=(${(s: :)EDITOR})
11
12
    else
        file=$*
Toon Claes's avatar
Toon Claes committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    fi

    for project in $PROJECT_PATHS; do
        if [[ -d $project/$file ]] then
            $cmd "$project/$file"
            unset project # Unset project var
            return
        fi
    done

    echo "No such project $1"
}

function _pj () {
27
28
    # might be possible to improve this using glob, without the basename trick
    typeset -a projects
29
    projects=($PROJECT_PATHS/*)
Kravchuk S.V's avatar
Kravchuk S.V committed
30
31
    projects=$projects:t
    _arguments "*:file:($projects)"
Toon Claes's avatar
Toon Claes committed
32
33
}
compdef _pj pj