b4ffe5cf0a9e0a076fc1c52f6a46eefe05ad5627

Author
Markus Færevaag <mf@bitblueprint.com>
Committer
Markus Færevaag <mf@bitblueprint.com>
Date

Message

wd.plugin: Added checks, readme and completion

Diff

 1diff --git a/plugins/wd/README.md b/plugins/wd/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..f9f4e7ac1f5fd6ff0e9d606779fe052ea6d8458a
 4--- /dev/null
 5+++ b/plugins/wd/README.md
 6@@ -0,0 +1,38 @@
 7+## wd
 8+
 9+**Maintainer:** [mfaerevaag](https://github.com/mfaerevaag)
10+
11+`wd` (warp directory) lets you jump to custom directories in zsh, without using cd. Why? Because cd seems ineffecient when the folder is frequently visited or has a long path. [Source](https://github.com/mfaerevaag/wd)
12+
13+### Usage
14+
15+ * Add warp point to current working directory:
16+
17+        wd add test
18+
19+    If a warp point with the same name exists, use `add!` to overwrite it.
20+
21+ * From an other directory, warp to test with:
22+
23+        wd test
24+
25+ * You can warp back to previous directory, and so on, with the puncticulation syntax:
26+
27+        wd ..
28+        wd ...
29+
30+    This is a wrapper for the zsh `dirs` function.
31+
32+ * Remove warp point test point:
33+
34+        wd rm test
35+
36+ * List warp points to current directory (stored in `~/.warprc`):
37+
38+        wd show
39+
40+ * List all warp points (stored in `~/.warprc`):
41+
42+        wd ls
43+
44+ * Print usage with no opts or the `help` argument.
45diff --git a/plugins/wd/_wd.sh b/plugins/wd/_wd.sh
46new file mode 100644
47index 0000000000000000000000000000000000000000..9505644356e0146cbdb8dbd1e422de9bc156ab36
48--- /dev/null
49+++ b/plugins/wd/_wd.sh
50@@ -0,0 +1,48 @@
51+#compdef wd.sh
52+
53+zstyle ":completion:*:descriptions" format "%B%d%b"
54+
55+CONFIG=$HOME/.warprc
56+
57+local -a main_commands
58+main_commands=(
59+    add:'Adds the current working directory to your warp points'
60+    #add'\!':'Overwrites existing warp point' # TODO: Fix
61+    rm:'Removes the given warp point'
62+    ls:'Outputs all stored warp points'
63+    show:'Outputs warp points to current directory'
64+)
65+
66+local -a points
67+while read line
68+do
69+    points+=$(awk "{ gsub(/\/Users\/$USER|\/home\/$USER/,\"~\"); print }" <<< $line)
70+done < $CONFIG
71+
72+_wd()
73+{
74+    # init variables
75+    local curcontext="$curcontext" state line
76+    typeset -A opt_args
77+
78+    # init state
79+    _arguments \
80+        '1: :->command' \
81+        '2: :->argument'
82+
83+    case $state in
84+        command)
85+            compadd "$@" add rm ls show
86+            _describe -t warp-points 'Warp points:' points && ret=0
87+            ;;
88+        argument)
89+            case $words[2] in
90+                rm|add!)
91+                    _describe -t warp-points 'warp points' points && ret=0
92+                    ;;
93+                *)
94+            esac
95+    esac
96+}
97+
98+_wd "$@"