82f02e80a669d099d79a531cf8fb6a0e34d4478c
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/wd/README.md b/plugins/wd/README.md
2index 91d5d0ae79c15bd539b2f6071ec8fd8b49d7ce66..a454a6c1eb43b8dc47807647452154c0b6e6c5ad 100644
3--- a/plugins/wd/README.md
4+++ b/plugins/wd/README.md
5@@ -1,5 +1,4 @@
6-wd
7-==
8+# wd
9
10 [](https://travis-ci.org/mfaerevaag/wd)
11
12@@ -9,150 +8,232 @@ wd
13
14 *NEWS*: If you are not using zsh, check out the c-port, [wd-c](https://github.com/mfaerevaag/wd-c), which works with all shells using wrapper functions.
15
16-### Setup
17+## Setup
18
19 ### oh-my-zsh
20
21-`wd` comes bundled with [oh-my-zshell](https://github.com/ohmyzsh/ohmyzsh)!
22+`wd` comes bundled with [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)!
23
24 Just add the plugin in your `~/.zshrc` file:
25
26- plugins=(... wd)
27+```zsh
28+plugins=(... wd)
29+```
30
31+### [Antigen](https://github.com/zsh-users/antigen)
32
33-#### Automatic
34+In your `.zshrc`:
35
36-Run either in terminal:
37+```zsh
38+antigen bundle mfaerevaag/wd
39+```
40+
41+### [Antibody](https://github.com/getantibody/antibody)
42+
43+In your `.zshrc`:
44+
45+```zsh
46+antibody bundle mfaerevaag/wd
47+```
48
49- * `curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh`
50+### Arch ([AUR](https://aur.archlinux.org/packages/zsh-plugin-wd-git/))
51
52- * `wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh`
53+```zsh
54+yay -S zsh-plugin-wd-git
55+# or use any other AUR helper
56+```
57
58-##### Arch ([AUR](https://aur.archlinux.org/))
59+### [zplug](https://github.com/zplug/zplug)
60
61- # yaourt -S zsh-plugin-wd-git
62+```zsh
63+zplug "mfaerevaag/wd", as:command, use:"wd.sh", hook-load:"wd() { . $ZPLUG_REPOS/mfaerevaag/wd/wd.sh }"
64+```
65+
66+### Automatic
67+
68+Run either in terminal:
69
70+```zsh
71+curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh
72+```
73
74-#### Manual
75+or
76
77- * Clone this repo to your liking
78+```zsh
79+wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh
80+```
81
82- * Add `wd` function to `.zshrc` (or `.profile` etc.):
83+### Manual
84
85- wd() {
86- . ~/path/to/cloned/repo/wd/wd.sh
87- }
88+* Clone this repo to your liking
89
90- * Install manpage. From `wd`'s base directory (requires root permissions):
91+* Add `wd` function to `.zshrc` (or `.profile` etc.):
92
93- # cp wd.1 /usr/share/man/man1/wd.1
94- # chmod 644 /usr/share/man/man1/wd.1
95+ ```zsh
96+ wd() {
97+ . ~/path/to/cloned/repo/wd/wd.sh
98+ }
99+ ```
100
101- Note, when pulling and updating `wd`, you'll need to do this again in case of changes to the manpage.
102+* Install manpage. From `wd`'s base directory (requires root permissions):
103
104+ ```zsh
105diff --git a/plugins/wd/_wd.sh b/plugins/wd/_wd.sh
106index 4354a71f4be441ed9d32222a7dd2ed752f251193..8d5cf15a2633fcaa2475f5fd2ba18350e7f89d74 100644
107--- a/plugins/wd/_wd.sh
108+++ b/plugins/wd/_wd.sh
109@@ -1,6 +1,6 @@
110 #compdef wd
111
112-zstyle ':completion:*:descriptions' format '%B%d%b'
113+zstyle ':completion::complete:wd:*:descriptions' format '%B%d%b'
114 zstyle ':completion::complete:wd:*:commands' group-name commands
115 zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
116 zstyle ':completion::complete:wd::' list-grouped
117@@ -8,13 +8,13 @@ zstyle ':completion::complete:wd::' list-grouped
118 zmodload zsh/mapfile
119
120 function _wd() {
121- local CONFIG=$HOME/.warprc
122+ local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
123 local ret=1
124
125 local -a commands
126 local -a warp_points
127
128- warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
129+ warp_points=( "${(f)mapfile[$WD_CONFIG]//$HOME/~}" )
130
131 typeset -A points
132 while read -r line
133@@ -27,11 +27,12 @@ function _wd() {
134 target_path=${target_path/#\~/$HOME}
135
136 points[$name]=$target_path
137- done < $CONFIG
138+ done < $WD_CONFIG
139
140 commands=(
141 'add:Adds the current working directory to your warp points'
142 'add!:Overwrites existing warp point'
143+ 'export:Export warp points as static named directories'
144 'rm:Removes the given warp point'
145 'list:Outputs all stored warp points'
146 'ls:Show files from given warp point'
147@@ -72,8 +73,12 @@ function _wd() {
148 _describe -t points "Warp points" warp_points && ret=0
149 ;;
150 *)
151- # complete sub directories from the warp point
152- _path_files -W "(${points[$target]})" -/ && ret=0
153+ if [[ -v points[$target] ]]; then
154+ # complete sub directories from the warp point
155+ _path_files -W "(${points[$target]})" -/ && ret=0
156+ fi
157+
158+ # don't complete anything if warp point is not valid
159 ;;
160 esac
161 ;;
162diff --git a/plugins/wd/wd.plugin.zsh b/plugins/wd/wd.plugin.zsh
163index 4b7cd3c19d4b470c8f7903921ea2550272f0d0a8..87d1d085874756a47425c058a5e77d8fdffd196e 100644
164--- a/plugins/wd/wd.plugin.zsh
165+++ b/plugins/wd/wd.plugin.zsh
166@@ -1,6 +1,9 @@
167+#!/bin/zsh
168+
169 # WARP DIRECTORY
170 # ==============
171-# oh-my-zsh plugin
172+# Jump to custom directories in terminal
173+# because `cd` takes too long...
174 #
175 # @github.com/mfaerevaag/wd
176
177diff --git a/plugins/wd/wd.sh b/plugins/wd/wd.sh
178index 3d68583f107218bb3d04e634c3498a98c0f146f9..802ed10ee1f14156048b4c22296b2dc01cefbbcd 100644
179--- a/plugins/wd/wd.sh
180+++ b/plugins/wd/wd.sh
181@@ -36,11 +36,11 @@ wd_yesorno()
182 read -r answer
183
184 case ${answer:=${default}} in
185- Y|y|YES|yes|Yes )
186+ "Y"|"y"|"YES"|"yes"|"Yes" )
187 RETVAL=${yes_RETVAL} && \
188 break
189 ;;
190- N|n|NO|no|No )
191+ "N"|"n"|"NO"|"no"|"No" )
192 RETVAL=${no_RETVAL} && \
193 break
194 ;;
195@@ -75,6 +75,8 @@ wd_print_usage()
196 Usage: wd [command] [point]
197
198 Commands:
199+ <point> Warps to the directory specified by the warp point
200+ <point> <path> Warps to the directory specified by the warp point with path appended
201 add <point> Adds the current working directory to your warp points
202 add Adds the current working directory to your warp points with current directory's name
203 add! <point> Overwrites existing warp point
204@@ -182,6 +184,8 @@ wd_add()
205 wd_remove $point > /dev/null
206 printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG
207
208+ wd_export_static_named_directories
209+
210 wd_print_msg $WD_GREEN "Warp point added"
211
212 # override exit code in case wd_remove did not remove any points
213@@ -203,8 +207,9 @@ wd_remove()
214
215 if [[ ${points[$point]} != "" ]]
216 then
217- local config_tmp=$WD_CONFIG.tmp
218- if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && mv $config_tmp $WD_CONFIG
219+ local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX")
220+ # Copy and delete in two steps in order to preserve symlinks
221+ if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && cp $config_tmp $WD_CONFIG && rm $config_tmp
222 then
223 wd_print_msg $WD_GREEN "Warp point removed"
224 else
225@@ -334,7 +339,16 @@ wd_clean() {
226 fi
227 }
228
229-local WD_CONFIG=$HOME/.warprc
230+wd_export_static_named_directories() {
231+ if [[ -z $WD_SKIP_EXPORT ]]
232+ then
233+ grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read warpdir ; do
234+ hash -d "$warpdir"
235+ done
236+ fi
237+}
238+
239+local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
240 local WD_QUIET=0
241 local WD_EXIT_CODE=0
242 local WD_DEBUG=0
243@@ -364,6 +378,8 @@ if [ ! -e $WD_CONFIG ]
244 then
245 # if not, create config file
246 touch $WD_CONFIG
247+else
248+ wd_export_static_named_directories
249 fi
250
251 # load warp points
252@@ -396,52 +412,57 @@ then
253 else
254
255 # parse rest of options
256- for o
257+ local wd_o
258+ for wd_o
259 do
260- case "$o"
261+ case "$wd_o"
262 in
263- -a|--add|add)
264+ "-a"|"--add"|"add")
265 wd_add false $2
266 break
267 ;;
268- -a!|--add!|add!)
269+ "-a!"|"--add!"|"add!")
270 wd_add true $2
271 break
272 ;;
273- -r|--remove|rm)
274+ "-e"|"export")
275+ wd_export_static_named_directories
276+ break
277+ ;;
278+ "-r"|"--remove"|"rm")
279 wd_remove $2
280 break