7e3231b846dec87fcf6537f6e45c9c1be9f718fe
- Author
- Carlo <carlosalag@protonmail.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/z/LICENSE b/plugins/z/LICENSE
2new file mode 100644
3index 0000000000000000000000000000000000000000..d1cca7ae51c47ff22d34bec29b679d04ca191831
4--- /dev/null
5+++ b/plugins/z/LICENSE
6@@ -0,0 +1,21 @@
7+MIT License
8+
9+Copyright (c) 2018-2022 Alexandros Kozak
10+
11+Permission is hereby granted, free of charge, to any person obtaining a copy
12+of this software and associated documentation files (the "Software"), to deal
13+in the Software without restriction, including without limitation the rights
14+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+copies of the Software, and to permit persons to whom the Software is
16+furnished to do so, subject to the following conditions:
17+
18+The above copyright notice and this permission notice shall be included in all
19+copies or substantial portions of the Software.
20+
21+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+SOFTWARE.
28diff --git a/plugins/z/MANUAL.md b/plugins/z/MANUAL.md
29new file mode 100644
30index 0000000000000000000000000000000000000000..dcca3c452878619249adef3daeea5e6fc2e7e269
31--- /dev/null
32+++ b/plugins/z/MANUAL.md
33@@ -0,0 +1,343 @@
34+# Zsh-z
35+
36diff --git a/plugins/z/Makefile b/plugins/z/Makefile
37deleted file mode 100644
38index dcf433d40179ea59391a76aa506382d5949b59a3..0000000000000000000000000000000000000000
39--- a/plugins/z/Makefile
40+++ /dev/null
41@@ -1,4 +0,0 @@
42-readme:
43- @groff -man -Tascii z.1 | col -bx
44-
45-.PHONY: readme
46diff --git a/plugins/z/README b/plugins/z/README
47deleted file mode 100644
48index 47e54c57a43e74218f3e19ff72cbb2f59f5b63a8..0000000000000000000000000000000000000000
49--- a/plugins/z/README
50+++ /dev/null
51@@ -1,148 +0,0 @@
52-Z(1) User Commands Z(1)
53-
54-
55-
56-NAME
57- z - jump around
58-
59-SYNOPSIS
60- z [-chlrtx] [regex1 regex2 ... regexn]
61-
62-AVAILABILITY
63- bash, zsh
64-
65-DESCRIPTION
66- Tracks your most used directories, based on 'frecency'.
67-
68- After a short learning phase, z will take you to the most 'frecent'
69- directory that matches ALL of the regexes given on the command line, in
70- order.
71-
72- For example, z foo bar would match /foo/bar but not /bar/foo.
73-
74-OPTIONS
75- -c restrict matches to subdirectories of the current directory
76-
77- -e echo the best match, don't cd
78-
79- -h show a brief help message
80-
81- -l list only
82-
83- -r match by rank only
84-
85- -t match by recent access only
86-
87- -x remove the current directory from the datafile
88-
89-EXAMPLES
90- z foo cd to most frecent dir matching foo
91-
92- z foo bar cd to most frecent dir matching foo, then bar
93-
94- z -r foo cd to highest ranked dir matching foo
95-
96- z -t foo cd to most recently accessed dir matching foo
97-
98- z -l foo list all dirs matching foo (by frecency)
99-
100-NOTES
101- Installation:
102- Put something like this in your $HOME/.bashrc or $HOME/.zshrc:
103-
104- . /path/to/z.sh
105-
106- cd around for a while to build up the db.
107-
108- PROFIT!!
109-
110- Optionally:
111- Set $_Z_CMD to change the command name (default z).
112- Set $_Z_DATA to change the datafile (default $HOME/.z).
113- Set $_Z_MAX_SCORE lower to age entries out faster (default
114- 9000).
115- Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
116- Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd your-
117- self.
118- Set $_Z_EXCLUDE_DIRS to an array of directory trees to exclude.
119- Set $_Z_OWNER to allow usage when in 'sudo -s' mode.
120- (These settings should go in .bashrc/.zshrc before the line
121- added above.)
122- Install the provided man page z.1 somewhere in your MANPATH,
123- like /usr/local/man/man1.
124-
125- Aging:
126- The rank of directories maintained by z undergoes aging based on a sim-
127- ple formula. The rank of each entry is incremented every time it is
128- accessed. When the sum of ranks is over 9000, all ranks are multiplied
129- by 0.99. Entries with a rank lower than 1 are forgotten.
130-
131- Frecency:
132- Frecency is a portmanteau of 'recent' and 'frequency'. It is a weighted
133- rank that depends on how often and how recently something occurred. As
134- far as I know, Mozilla came up with the term.
135-
136- To z, a directory that has low ranking but has been accessed recently
137- will quickly have higher rank than a directory accessed frequently a
138- long time ago.
139-
140- Frecency is determined at runtime.
141-
142- Common:
143- When multiple directories match all queries, and they all have a common
144- prefix, z will cd to the shortest matching directory, without regard to
145- priority. This has been in effect, if undocumented, for quite some
146- time, but should probably be configurable or reconsidered.
147-
148- Tab Completion:
149- z supports tab completion. After any number of arguments, press TAB to
150- complete on directories that match each argument. Due to limitations of
151diff --git a/plugins/z/README.md b/plugins/z/README.md
152index ea8d4610a038ed380928eb0fea47c9b2ee382fc0..5b7d6f64904de144a484e47a80705d4436ebfe4a 100644
153--- a/plugins/z/README.md
154+++ b/plugins/z/README.md
155@@ -1,8 +1,9 @@
156 # z - jump around
157
158-This plugin defines the [z command](https://github.com/rupa/z) that tracks your most visited directories and allows you to access them with very few keystrokes.
159+This plugin defines the [z command](https://github.com/agkozak/zsh-z) that tracks your most visited directories and allows you to access them with very few keystrokes.
160
161 ### Example
162+
163 Assume that you have previously visited directory `~/.oh-my-zsh/plugins`. From any folder in your command line, you can quickly access it by using a regex match to this folder:
164
165 ```bash
166@@ -11,6 +12,7 @@ Assume that you have previously visited directory `~/.oh-my-zsh/plugins`. From a
167 ```
168
169 ### Setup
170+
171 To enable z, add `z` to your `plugins` array in your zshrc file:
172
173 ```zsh
174@@ -19,5 +21,4 @@ plugins=(... z)
175
176 ### Further reading
177
178-For advanced usage and details of z, see [README](./README) (in man page format, copied from [rupa/z](https://github.com/rupa/z)).
179-
180+For advanced usage and details of z, see [MANUAL](./MANUAL.md) (copied from [agkozak/zsh-z](https://github.com/agkozak/zsh-z)).
181diff --git a/plugins/z/_z b/plugins/z/_z
182new file mode 100644
183index 0000000000000000000000000000000000000000..9891a52ed51827c47a781269aab3aa9008d299ba
184--- /dev/null
185+++ b/plugins/z/_z
186@@ -0,0 +1,82 @@
187+#compdef zshz ${ZSHZ_CMD:-${_Z_CMD:-z}}
188+#
189+# Zsh-z - jump around with Zsh - A native Zsh version of z without awk, sort,
190+# date, or sed
191+#
192+# https://github.com/agkozak/zsh-z
193+#
194+# Copyright (c) 2018-2022 Alexandros Kozak
195+#
196+# Permission is hereby granted, free of charge, to any person obtaining a copy
197+# of this software and associated documentation files (the "Software"), to deal
198+# in the Software without restriction, including without limitation the rights
199+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
200+# copies of the Software, and to permit persons to whom the Software is
201+# furnished to do so, subject to the following conditions:
202+#
203+# The above copyright notice and this permission notice shall be included in all
204+# copies or substantial portions of the Software.
205+#
206+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
207+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
209+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
210+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
211+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
212+# SOFTWARE.
213+#
214+# z (https://github.com/rupa/z) is copyright (c) 2009 rupa deadwyler and
215+# licensed under the WTFPL license, Version 2.a
216+#
217+# shellcheck shell=ksh
218+
219+############################################################
220+# Zsh-z COMPLETIONS
221+############################################################
222+emulate -L zsh
223+(( ZSHZ_DEBUG )) &&
224+ setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL NO_WARN_NESTED_VAR 2> /dev/null
225+
226+# TODO: This routine currently reproduces z's feature of allowing spaces to be
227+# used as wildcards in completions, so that
228+#
229+# z us lo bi
230+#
231+# can expand to
232+#
233+# z /usr/local/bin
234+#
235+# but it also reproduces z's buggy display on the commandline, viz.
236+#
237+# z us lo /usr/local/bin
238+#
239+# Address.
240+
241+local completions expl completion
242+local -a completion_list
243+
244+completions=$(zshz --complete ${(@)words:1})
245+[[ -z $completions ]] && return 1
246+
247+for completion in ${(f)completions[@]}; do
248+ if (( ZSHZ_TILDE )) && [[ $completion == ${HOME}* ]]; then
249+ completion="~${(q)${completion#${HOME}}}"
250+ else
251+ completion="${(q)completion}"
252+ fi
253+ completion_list+=( $completion )
254+done
255+
256+_description -V completion_list expl 'directories'
257+
258+if [[ $ZSHZ_COMPLETION == 'legacy' ]]; then
259+ compadd "${expl[@]}" -QU -- "${completion_list[@]}"
260+else
261+ compadd "${expl[@]}" -QU -V zsh-z -- "${completion_list[@]}"
262+fi
263+
264+compstate[insert]=menu
265+
266+return 0
267+
268+# vim: ft=zsh:fdm=indent:ts=2:et:sts=2:sw=2:
269diff --git a/plugins/z/z.1 b/plugins/z/z.1
270deleted file mode 100644
271index 182f981764647c19c80360d8356b4203097def67..0000000000000000000000000000000000000000
272--- a/plugins/z/z.1
273+++ /dev/null
274@@ -1,173 +0,0 @@
275-.TH "Z" "1" "January 2013" "z" "User Commands"
276-.SH
277-NAME
278-z \- jump around
279-.SH
280-SYNOPSIS
281-z [\-chlrtx] [regex1 regex2 ... regexn]
282-.SH
283-AVAILABILITY
284-bash, zsh
285-.SH
286-DESCRIPTION
287-Tracks your most used directories, based on 'frecency'.
288-.P
289-After a short learning phase, \fBz\fR will take you to the most 'frecent'
290-directory that matches ALL of the regexes given on the command line, in order.
291-
292-For example, \fBz foo bar\fR would match \fB/foo/bar\fR but not \fB/bar/foo\fR.
293-.SH
294-OPTIONS
295-.TP
296-\fB\-c\fR
297-restrict matches to subdirectories of the current directory
298-.TP
299-\fB\-e\fR
300-echo the best match, don't cd
301-.TP
302-\fB\-h\fR
303-show a brief help message
304-.TP
305-\fB\-l\fR
306-list only
307-.TP
308-\fB\-r\fR
309-match by rank only
310-.TP
311-\fB\-t\fR
312-match by recent access only
313-.TP
314-\fB\-x\fR
315-remove the current directory from the datafile
316-.SH EXAMPLES
317-.TP 14
318-\fBz foo\fR
319-cd to most frecent dir matching foo
320-.TP 14
321-\fBz foo bar\fR
322-cd to most frecent dir matching foo, then bar
323-.TP 14
324-\fBz -r foo\fR
325-cd to highest ranked dir matching foo
326-.TP 14
327-\fBz -t foo\fR
328-cd to most recently accessed dir matching foo
329-.TP 14
330-\fBz -l foo\fR
331-list all dirs matching foo (by frecency)
332-.SH
333-NOTES
334-.SS
335-Installation:
336-.P
337-Put something like this in your \fB$HOME/.bashrc\fR or \fB$HOME/.zshrc\fR:
338-.RS
339-.P
340-\fB. /path/to/z.sh\fR
341-.RE
342-.P
343-\fBcd\fR around for a while to build up the db.
344-.P
345-PROFIT!!
346-.P
347-Optionally:
348-.RS
349-Set \fB$_Z_CMD\fR to change the command name (default \fBz\fR).
350-.RE
351-.RS
352-Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR).
353-.RE
354-.RS
355-Set \fB$_Z_MAX_SCORE\fR lower to age entries out faster (default \fB9000\fR).
356-.RE
357-.RS
358-Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution.
359-.RE
360-.RS
361-Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself.
362-.RE
363-.RS
364-Set \fB$_Z_EXCLUDE_DIRS\fR to an array of directory trees to exclude.
365-.RE
366-.RS
367-Set \fB$_Z_OWNER\fR to allow usage when in 'sudo -s' mode.
368-.RE
369-.RS
370-(These settings should go in .bashrc/.zshrc before the line added above.)
371-.RE
372-.RS
373-Install the provided man page \fBz.1\fR somewhere in your \f$MANPATH, like
374diff --git a/plugins/z/z.plugin.zsh b/plugins/z/z.plugin.zsh
375index 7d3eacac097c683eef1d39511ce6d7afd47ce969..209edfea7d41facdded9097137edfebe83443ce3 100644
376--- a/plugins/z/z.plugin.zsh
377+++ b/plugins/z/z.plugin.zsh
378@@ -1,6 +1,968 @@
379-# Handle $0 according to the standard:
380-# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
381-0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
382-0="${${(M)0:#/*}:-$PWD/$0}"
383+################################################################################
384+# Zsh-z - jump around with Zsh - A native Zsh version of z without awk, sort,
385+# date, or sed
386+#
387+# https://github.com/agkozak/zsh-z
388+#
389+# Copyright (c) 2018-2022 Alexandros Kozak
390+#
391+# Permission is hereby granted, free of charge, to any person obtaining a copy
392+# of this software and associated documentation files (the "Software"), to deal
393+# in the Software without restriction, including without limitation the rights
394+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
395+# copies of the Software, and to permit persons to whom the Software is
396+# furnished to do so, subject to the following conditions:
397+#
398+# The above copyright notice and this permission notice shall be included in all
399+# copies or substantial portions of the Software.
400+#
401+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
402+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
403+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
404+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
405+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
406+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
407+# SOFTWARE.
408+#
409+# z (https://github.com/rupa/z) is copyright (c) 2009 rupa deadwyler and
410+# licensed under the WTFPL license, Version 2.
411+#
412+# Zsh-z maintains a jump-list of the directories you actually use.
413+#
414+# INSTALL:
415+# * put something like this in your .zshrc:
416+# source /path/to/zsh-z.plugin.zsh
417+# * cd around for a while to build up the database
418+#
419+# USAGE:
420+# * z foo cd to the most frecent directory matching foo
421+# * z foo bar cd to the most frecent directory matching both foo and bar
422+# (e.g. /foo/bat/bar/quux)
423+# * z -r foo cd to the highest ranked directory matching foo
424+# * z -t foo cd to most recently accessed directory matching foo
425+# * z -l foo List matches instead of changing directories
426+# * z -e foo Echo the best match without changing directories
427+# * z -c foo Restrict matches to subdirectories of PWD
428+# * z -x Remove a directory (default: PWD) from the database
429+# * z -xR Remove a directory (default: PWD) and its subdirectories from
430+# the database
431+#
432+# ENVIRONMENT VARIABLES:
433+#
434+# ZSHZ_CASE -> if `ignore', pattern matching is case-insensitive; if `smart',
435+# pattern matching is case-insensitive only when the pattern is all
436+# lowercase
437+# ZSHZ_CMD -> name of command (default: z)
438+# ZSHZ_COMPLETION -> completion method (default: 'frecent'; 'legacy' for
439+# alphabetic sorting)
440+# ZSHZ_DATA -> name of datafile (default: ~/.z)
441+# ZSHZ_EXCLUDE_DIRS -> array of directories to exclude from your database
442+# (default: empty)
443+# ZSHZ_KEEP_DIRS -> array of directories that should not be removed from the
444+# database, even if they are not currently available (default: empty)
445+# ZSHZ_MAX_SCORE -> maximum combined score the database entries can have
446+# before beginning to age (default: 9000)
447+# ZSHZ_NO_RESOLVE_SYMLINKS -> '1' prevents symlink resolution
448+# ZSHZ_OWNER -> your username (if you want use Zsh-z while using sudo -s)
449+# ZSHZ_UNCOMMON -> if 1, do not jump to "common directories," but rather drop
450+# subdirectories based on what the search string was (default: 0)
451+################################################################################
452
453-source "${0:h}/z.sh"
454+autoload -U is-at-least
455+
456+if ! is-at-least 4.3.11; then
457+ print "Zsh-z requires Zsh v4.3.11 or higher." >&2 && exit
458+fi
459+
460+############################################################
461+# The help message
462+#
463+# Globals:
464+# ZSHZ_CMD
465+############################################################
466+_zshz_usage() {
467+ print "Usage: ${ZSHZ_CMD:-${_Z_CMD:-z}} [OPTION]... [ARGUMENT]
468+Jump to a directory that you have visited frequently or recently, or a bit of both, based on the partial string ARGUMENT.
469+
470+With no ARGUMENT, list the directory history in ascending rank.
471+
472+ --add Add a directory to the database
473+ -c Only match subdirectories of the current directory
474+ -e Echo the best match without going to it
475+ -h Display this help and exit
476+ -l List all matches without going to them
477+ -r Match by rank
478diff --git a/plugins/z/z.sh b/plugins/z/z.sh
479deleted file mode 100644
480index 67f504e27f34cc706340a4995dbbbfbb4fcd9d36..0000000000000000000000000000000000000000
481--- a/plugins/z/z.sh
482+++ /dev/null
483@@ -1,267 +0,0 @@
484-# Copyright (c) 2009 rupa deadwyler. Licensed under the WTFPL license, Version 2
485-
486-# maintains a jump-list of the directories you actually use
487-#
488-# INSTALL:
489-# * put something like this in your .bashrc/.zshrc:
490-# . /path/to/z.sh
491-# * cd around for a while to build up the db
492-# * PROFIT!!
493-# * optionally:
494-# set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
495-# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).
496-# set $_Z_MAX_SCORE lower to age entries out faster (default 9000).
497-# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
498-# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
499-# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
500-# set $_Z_OWNER to your username if you want use z while sudo with $HOME kept
501-#
502-# USE:
503-# * z foo # cd to most frecent dir matching foo
504-# * z foo bar # cd to most frecent dir matching foo and bar
505-# * z -r foo # cd to highest ranked dir matching foo
506-# * z -t foo # cd to most recently accessed dir matching foo
507-# * z -l foo # list matches instead of cd
508-# * z -e foo # echo the best match, don't cd
509-# * z -c foo # restrict matches to subdirs of $PWD
510-# * z -x # remove the current directory from the datafile
511-# * z -h # show a brief help message
512-
513-[ -d "${_Z_DATA:-$HOME/.z}" ] && {
514- echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory."
515-}
516-
517-_z() {
518-
519- local datafile="${_Z_DATA:-$HOME/.z}"
520-
521- # if symlink, dereference
522- [ -h "$datafile" ] && datafile=$(readlink "$datafile")
523-
524- # bail if we don't own ~/.z and $_Z_OWNER not set
525- [ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return
526-
527- _z_dirs () {
528- [ -f "$datafile" ] || return
529-
530- local line
531- while read line; do
532- # only count directories
533- [ -d "${line%%\|*}" ] && echo "$line"
534- done < "$datafile"
535- return 0
536- }
537-
538- # add entries
539- if [ "$1" = "--add" ]; then
540- shift
541-
542- # $HOME and / aren't worth matching
543- [ "$*" = "$HOME" -o "$*" = '/' ] && return
544-
545- # don't track excluded directory trees
546- if [ ${#_Z_EXCLUDE_DIRS[@]} -gt 0 ]; then
547- local exclude
548- for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
549- case "$*" in "$exclude"*) return;; esac
550- done
551- fi
552-
553- # maintain the data file
554- local tempfile="$datafile.$RANDOM"
555- local score=${_Z_MAX_SCORE:-9000}
556- _z_dirs | awk -v path="$*" -v now="$(date +%s)" -v score=$score -F"|" '
557- BEGIN {
558- rank[path] = 1
559- time[path] = now
560- }
561- $2 >= 1 {
562- # drop ranks below 1
563- if( $1 == path ) {
564- rank[$1] = $2 + 1
565- time[$1] = now
566- } else {
567- rank[$1] = $2
568- time[$1] = $3
569- }
570- count += $2
571- }
572- END {
573- if( count > score ) {
574- # aging
575- for( x in rank ) print x "|" 0.99*rank[x] "|" time[x]
576- } else for( x in rank ) print x "|" rank[x] "|" time[x]
577- }
578- ' 2>/dev/null >| "$tempfile"
579- # do our best to avoid clobbering the datafile in a race condition.
580- if [ $? -ne 0 -a -f "$datafile" ]; then
581- env rm -f "$tempfile"
582- else