631a8473e2f3f20e1414dff4e409fe07cbb41aea

Author
Toon Claes <toon@tonotdo.com>
Committer
Toon Claes <toon@tonotdo.com>
Date

Message

added pj.plugin

Diff

 1diff --git a/plugins/pj/pj.plugin.zsh b/plugins/pj/pj.plugin.zsh
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..ba3765b83ce12893215ea45c10665ccd2517f2ef
 4--- /dev/null
 5+++ b/plugins/pj/pj.plugin.zsh
 6@@ -0,0 +1,42 @@
 7+#!/bin/zsh
 8+
 9+#
10+# Original idea by DefV (Jan De Poorter)
11+# Source: https://gist.github.com/pjaspers/368394#comment-1016
12+#
13+# Usage:
14+#  - Set `$PROJECT_PATHS` in your ~/.zshrc
15+#    e.g.: PROJECT_PATHS=(~/src ~/work)
16+#  - In ZSH you now can open a project directory with the command: `pj my-project`
17+#    the plugin will locate the `my-project` directory in one of the $PROJECT_PATHS
18+#    Also tab completion is supported.
19+#  - `pjo my-project` will open the directory in $EDITOR
20+# 
21+
22+function pj() {
23+    cmd="cd"
24+    file=$1
25+
26+    if [[ "open" == "$file" ]] then
27+        file=$2
28+        cmd=(${(s: :)EDITOR})
29+    fi
30+
31+    for project in $PROJECT_PATHS; do
32+        if [[ -d $project/$file ]] then
33+            $cmd "$project/$file"
34+            unset project # Unset project var
35+            return
36+        fi
37+    done
38+
39+    echo "No such project $1"
40+}
41+
42+alias pjo="pj open"
43+
44+function _pj () {
45+    compadd `/bin/ls -l $PROJECT_PATHS 2>/dev/null | awk '{ print $9 }'`
46+}
47+
48+compdef _pj pj