2e7a247cab663fbc0aafdefa15bf10eb4dd64563
- Author
- Bas Nijholt <basnijholt@gmail.com>
- Committer
- Carlo Sala <carlosalag@protonmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/z/LICENSE b/plugins/z/LICENSE
2index d1cca7ae51c47ff22d34bec29b679d04ca191831..6af13b9e09c9a1d3ce3958d9056b5a030322b235 100644
3--- a/plugins/z/LICENSE
4+++ b/plugins/z/LICENSE
5@@ -1,6 +1,6 @@
6 MIT License
7
8-Copyright (c) 2018-2022 Alexandros Kozak
9+Copyright (c) 2018-2023 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
13diff --git a/plugins/z/MANUAL.md b/plugins/z/MANUAL.md
14index dcca3c452878619249adef3daeea5e6fc2e7e269..d367c3026b7a06b0681ac963ac0e7c63cc027155 100644
15--- a/plugins/z/MANUAL.md
16+++ b/plugins/z/MANUAL.md
17@@ -1,5 +1,9 @@
18 # Zsh-z
19
20+[](https://opensource.org/licenses/MIT)
21+
22+[](https://github.com/agkozak/zsh-z/stargazers)
23+
24diff --git a/plugins/z/_z b/plugins/z/_z
25index 9891a52ed51827c47a781269aab3aa9008d299ba..a493f35bade0096449e28708afa8f82794a8dc71 100644
26--- a/plugins/z/_z
27+++ b/plugins/z/_z
28@@ -5,7 +5,7 @@
29 #
30 # https://github.com/agkozak/zsh-z
31 #
32-# Copyright (c) 2018-2022 Alexandros Kozak
33+# Copyright (c) 2018-2023 Alexandros Kozak
34 #
35 # Permission is hereby granted, free of charge, to any person obtaining a copy
36 # of this software and associated documentation files (the "Software"), to deal
37diff --git a/plugins/z/img/mit_license.svg b/plugins/z/img/mit_license.svg
38new file mode 100644
39index 0000000000000000000000000000000000000000..1c02079d7d0473f7b78aa0e1ccd77bc234530ff3
40--- /dev/null
41+++ b/plugins/z/img/mit_license.svg
42@@ -0,0 +1 @@
43diff --git a/plugins/z/img/zsh_4.3.11_plus.svg b/plugins/z/img/zsh_4.3.11_plus.svg
44new file mode 100644
45index 0000000000000000000000000000000000000000..f46d947d0947abafb255102329e0b56aca0e3a3d
46--- /dev/null
47+++ b/plugins/z/img/zsh_4.3.11_plus.svg
48@@ -0,0 +1 @@
49diff --git a/plugins/z/z.plugin.zsh b/plugins/z/z.plugin.zsh
50index 209edfea7d41facdded9097137edfebe83443ce3..60a630624d027593206376f38cded3ff98fb7531 100644
51--- a/plugins/z/z.plugin.zsh
52+++ b/plugins/z/z.plugin.zsh
53@@ -4,7 +4,7 @@
54 #
55 # https://github.com/agkozak/zsh-z
56 #
57-# Copyright (c) 2018-2022 Alexandros Kozak
58+# Copyright (c) 2018-2023 Alexandros Kozak
59 #
60 # Permission is hereby granted, free of charge, to any person obtaining a copy
61 # of this software and associated documentation files (the "Software"), to deal
62@@ -52,6 +52,7 @@
63 # ZSHZ_CASE -> if `ignore', pattern matching is case-insensitive; if `smart',
64 # pattern matching is case-insensitive only when the pattern is all
65 # lowercase
66+# ZSHZ_CD -> the directory-changing command that is used (default: builtin cd)
67 # ZSHZ_CMD -> name of command (default: z)
68 # ZSHZ_COMPLETION -> completion method (default: 'frecent'; 'legacy' for
69 # alphabetic sorting)
70@@ -129,6 +130,7 @@ is-at-least 5.3.0 && ZSHZ[PRINTV]=1
71 # Globals:
72 # ZSHZ
73 # ZSHZ_CASE
74+# ZSHZ_CD
75 # ZSHZ_COMPLETION
76 # ZSHZ_DATA
77 # ZSHZ_DEBUG
78@@ -149,9 +151,19 @@ zshz() {
79 local REPLY
80 local -a lines
81
82- # Allow the user to specify the datafile name in $ZSHZ_DATA (default: ~/.z)
83+ # Allow the user to specify a custom datafile in $ZSHZ_DATA (or legacy $_Z_DATA)
84+ local custom_datafile="${ZSHZ_DATA:-$_Z_DATA}"
85+
86+ # If a datafile was provided as a standalone file without a directory path
87+ # print a warning and exit
88+ if [[ -n ${custom_datafile} && ${custom_datafile} != */* ]]; then
89+ print "ERROR: You configured a custom Zsh-z datafile (${custom_datafile}), but have not specified its directory." >&2
90+ exit
91+ fi
92+
93+ # If the user specified a datafile, use that or default to ~/.z
94 # If the datafile is a symlink, it gets dereferenced
95- local datafile=${${ZSHZ_DATA:-${_Z_DATA:-${HOME}/.z}}:A}
96+ local datafile=${${custom_datafile:-$HOME/.z}:A}
97
98 # If the datafile is a directory, print a warning and exit
99 if [[ -d $datafile ]]; then
100@@ -161,7 +173,7 @@ zshz() {
101
102 # Make sure that the datafile exists before attempting to read it or lock it
103 # for writing
104- [[ -f $datafile ]] || touch "$datafile"
105+ [[ -f $datafile ]] || { mkdir -p "${datafile:h}" && touch "$datafile" }
106
107 # Bail if we don't own the datafile and $ZSHZ_OWNER is not set
108 [[ -z ${ZSHZ_OWNER:-${_Z_OWNER}} && -f $datafile && ! -O $datafile ]] &&
109@@ -620,7 +632,7 @@ zshz() {
110 *)
111 # Frecency routine
112 (( dx = EPOCHSECONDS - time_field ))
113- rank=$(( 10000 * rank_field * (3.75/((0.0001 * dx + 1) + 0.25)) ))
114+ rank=$(( 10000 * rank_field * (3.75/( (0.0001 * dx + 1) + 0.25)) ))
115 ;;
116 esac
117
118@@ -756,6 +768,26 @@ zshz() {
119 [[ $output_format != 'completion' ]] && output_format='list'
120 }
121
122+ #########################################################
123+ # Allow the user to specify directory-changing command
124+ # using $ZSHZ_CD (default: builtin cd).
125+ #
126+ # Globals:
127+ # ZSHZ_CD
128+ #
129+ # Arguments:
130+ # $* Path
131+ #########################################################
132+ zshz_cd() {
133+ setopt LOCAL_OPTIONS NO_WARN_CREATE_GLOBAL
134+
135+ if [[ -z $ZSHZ_CD ]]; then
136+ builtin cd "$*"
137+ else
138+ ${=ZSHZ_CD} "$*"
139+ fi
140+ }
141+
142 #########################################################
143 # If $ZSHZ_ECHO == 1, display paths as you jump to them.
144 # If it is also the case that $ZSHZ_TILDE == 1, display
145@@ -773,7 +805,7 @@ zshz() {
146
147 if [[ ${@: -1} == /* ]] && (( ! $+opts[-e] && ! $+opts[-l] )); then
148 # cd if possible; echo the new path if $ZSHZ_ECHO == 1
149- [[ -d ${@: -1} ]] && builtin cd ${@: -1} && _zshz_echo && return
150+ [[ -d ${@: -1} ]] && zshz_cd ${@: -1} && _zshz_echo && return
151 fi
152