fcd55f3a9202ca8d47a82b4a0274bdd114d745d1

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #2845 from mfaerevaag/master

[wd] New minor release

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/wd/README.md b/plugins/wd/README.md
  2index f9f4e7ac1f5fd6ff0e9d606779fe052ea6d8458a..bc0ebe334ed4ed556d93c2a4c0876cd610f76579 100644
  3--- a/plugins/wd/README.md
  4+++ b/plugins/wd/README.md
  5@@ -2,37 +2,39 @@
  6 
  7 **Maintainer:** [mfaerevaag](https://github.com/mfaerevaag)
  8 
  9-`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)
 10+`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)
 11 
 12 ### Usage
 13 
 14  * Add warp point to current working directory:
 15 
 16-        wd add test
 17+        $ wd add foo
 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+    Note, a warp point cannot contain colons, or only consist of only spaces and dots. The first will conflict in how `wd` stores the warp points, and the second will conflict other features, as below.
 23 
 24-        wd test
 25+ * From an other directory (not necessarily), warp to `foo` with:
 26 
 27- * You can warp back to previous directory, and so on, with the puncticulation syntax:
 28+        $ wd foo
 29 
 30-        wd ..
 31-        wd ...
 32+ * You can warp back to previous directory, and so on, with this dot syntax:
 33+
 34+        $ wd ..
 35+        $ wd ...
 36 
 37     This is a wrapper for the zsh `dirs` function.
 38 
 39  * Remove warp point test point:
 40 
 41-        wd rm test
 42+        $ wd rm foo
 43 
 44- * List warp points to current directory (stored in `~/.warprc`):
 45+ * List all warp points (stored in `~/.warprc`):
 46 
 47-        wd show
 48+        $ wd ls
 49 
 50- * List all warp points (stored in `~/.warprc`):
 51+ * List warp points to current directory
 52 
 53-        wd ls
 54+        $ wd show
 55 
 56  * Print usage with no opts or the `help` argument.
 57diff --git a/plugins/wd/_wd.sh b/plugins/wd/_wd.sh
 58index 29df63520684f00cdb86adfea6c5785a816d6c9d..0b03d8fff3b7f5a2578742736445b922da523df6 100644
 59--- a/plugins/wd/_wd.sh
 60+++ b/plugins/wd/_wd.sh
 61@@ -5,23 +5,16 @@ zstyle ':completion::complete:wd:*:commands' group-name commands
 62 zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
 63 zstyle ':completion::complete:wd::' list-grouped
 64 
 65-# Call `_wd()` when when trying to complete the command `wd`
 66-
 67 zmodload zsh/mapfile
 68+
 69 function _wd() {
 70-  local ret=1
 71   local CONFIG=$HOME/.warprc
 72-
 73-  # Stolen from
 74-  # http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands
 75-
 76-  # local curcontext="$curcontext" state line
 77-  # typeset -A opt_args
 78+  local ret=1
 79 
 80   local -a commands
 81   local -a warp_points
 82-  warp_points=( "${(f)mapfile[$CONFIG]}" )
 83-  # LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it
 84+
 85+  warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
 86 
 87   commands=(
 88     'add:Adds the current working directory to your warp points'
 89diff --git a/plugins/wd/wd.plugin.zsh b/plugins/wd/wd.plugin.zsh
 90index 9800335fc6584ea2ffaed1d81b766c5095a68e18..c0559293d1184e956a6da01691d98b10c88c063d 100644
 91--- a/plugins/wd/wd.plugin.zsh
 92+++ b/plugins/wd/wd.plugin.zsh
 93@@ -1,7 +1,7 @@
 94 #!/bin/zsh
 95 
 96-# WARP
 97-# ====
 98+# WARP DIRECTORY
 99+# ==============
100 # oh-my-zsh plugin
101 #
102 # @github.com/mfaerevaag/wd
103diff --git a/plugins/wd/wd.sh b/plugins/wd/wd.sh
104index 9ebad68082e0eb1c1eb595cb582b7edfdc1cd950..dfb9ad89a4dc3478112eb053a4f70088b34ec280 100755
105--- a/plugins/wd/wd.sh
106+++ b/plugins/wd/wd.sh
107@@ -1,7 +1,7 @@
108 #!/bin/zsh
109 
110-# WARP
111-# ====
112+# WARP DIRECTORY
113+# ==============
114 # Jump to custom directories in terminal
115 # because `cd` takes too long...
116 #
117@@ -9,26 +9,28 @@
118 
119 
120 ## variables
121-CONFIG=$HOME/.warprc
122+readonly CONFIG=$HOME/.warprc
123 
124-## colors
125-BLUE="\033[96m"
126-GREEN="\033[92m"
127-YELLOW="\033[93m"
128-RED="\033[91m"
129-NOC="\033[m"
130+# colors
131+readonly BLUE="\033[96m"
132+readonly GREEN="\033[92m"
133+readonly YELLOW="\033[93m"
134+readonly RED="\033[91m"
135+readonly NOC="\033[m"
136 
137 
138+## init
139+
140 # check if config file exists
141-if [[ ! -a $CONFIG ]]
142+if [ ! -e $CONFIG ]
143 then
144-  # if not: create config file
145-  touch $CONFIG
146+    # if not, create config file
147+    touch $CONFIG
148 fi
149 
150-## load warp points
151+# load warp points
152 typeset -A points
153-while read line
154+while read -r line
155 do
156     arr=(${(s,:,)line})
157     key=${arr[1]}
158@@ -39,72 +41,78 @@ done < $CONFIG
159 
160 
161 ## functions
162-# prepended wd_ to not conflict with your environment (no sub shell)
163 
164 wd_warp()
165 {
166-    if [[ $1 =~ "^\.+$" ]]
167+    local point=$1
168+
169+    if [[ $point =~ "^\.+$" ]]
170     then
171-        if [[ $#1 < 2 ]]
172+        if [ $#1 < 2 ]
173         then
174             wd_print_msg $YELLOW "Warping to current directory?"
175         else
176             (( n = $#1 - 1 ))
177-            #wd_print_msg $BLUE "Warping..."
178             cd -$n > /dev/null
179         fi
180-    elif [[ ${points[$1]} != "" ]]
181+    elif [[ ${points[$point]} != "" ]]
182     then
183-        #wd_print_msg $BLUE "Warping..."
184-        cd ${points[$1]}
185+        cd ${points[$point]}
186     else
187-        wd_print_msg $RED "Unknown warp point '$1'"
188+        wd_print_msg $RED "Unknown warp point '${point}'"
189     fi
190 }
191 
192 wd_add()
193 {
194-    if [[ $2 =~ "^\.+$" || $2 =~ "^\s*$" ]]
195+    local force=$1
196+    local point=$2
197+
198+    if [[ $point =~ "^[\.]+$" ]]
199+    then
200+        wd_print_msg $RED "Warp point cannot be just dots"
201+    elif [[ $point =~ "(\s|\ )+" ]]
202     then
203-        wd_print_msg $RED "Illegal warp point (see README)."
204-    elif [[ ${points[$2]} == "" ]] || $1
205+        wd_print_msg $RED "Warp point should not contain whitespace"
206+    elif [[ $point == *:* ]]