mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-22 23:59:48 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef9a49d73d | ||
|
|
7cd399b30d | ||
|
|
9112f0e9cc | ||
|
|
cb4c9d3c8f | ||
|
|
924f61a48b | ||
|
|
4c05e0d911 |
@@ -58,6 +58,15 @@ z -b foo bar # replace foo with bar in cwd and cd there
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
- Fig (works with all shells)
|
||||||
|
|
||||||
|
[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
|
||||||
|
|
||||||
|
|
||||||
|
Install `z.lua` in just one click.
|
||||||
|
|
||||||
|
<a href="https://fig.io/plugins/other/z.lua" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
|
||||||
|
|
||||||
- Bash:
|
- Bash:
|
||||||
|
|
||||||
put something like this in your `.bashrc`:
|
put something like this in your `.bashrc`:
|
||||||
|
|||||||
27
z.lua
27
z.lua
@@ -4,7 +4,7 @@
|
|||||||
-- z.lua - a cd command that learns, by skywind 2018-2022
|
-- z.lua - a cd command that learns, by skywind 2018-2022
|
||||||
-- Licensed under MIT license.
|
-- Licensed under MIT license.
|
||||||
--
|
--
|
||||||
-- Version 1.8.17, Last Modified: 2022/09/29 15:47
|
-- Version 1.8.18, Last Modified: 2024/03/20 22:17
|
||||||
--
|
--
|
||||||
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
||||||
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
||||||
@@ -128,6 +128,7 @@ Z_MATCHMODE = 0
|
|||||||
Z_MATCHNAME = false
|
Z_MATCHNAME = false
|
||||||
Z_SKIPPWD = false
|
Z_SKIPPWD = false
|
||||||
Z_HYPHEN = "auto"
|
Z_HYPHEN = "auto"
|
||||||
|
Z_DATA_SEPARATOR = "|"
|
||||||
|
|
||||||
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
|
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
|
||||||
|
|
||||||
@@ -1061,6 +1062,26 @@ function path_case_insensitive()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
-- Read a line of the database and return a list of the 3 fields in it
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
function read_data_line(line)
|
||||||
|
local part = string.split(line, Z_DATA_SEPARATOR)
|
||||||
|
if #part <= 3 then
|
||||||
|
return part
|
||||||
|
end
|
||||||
|
-- If the part is made of more than 3 elements, it's probably because the
|
||||||
|
-- path element contains '|' that have been split. Thus, we want to
|
||||||
|
-- reconstruct it and keep the 2 last elements of part intact as the end
|
||||||
|
-- of the returned part.
|
||||||
|
local path = part[1]
|
||||||
|
for i=2,#part-2 do
|
||||||
|
path = path .. Z_DATA_SEPARATOR .. part[i]
|
||||||
|
end
|
||||||
|
return {path, part[#part-1], part[#part]}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- load and split data
|
-- load and split data
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
@@ -1073,7 +1094,7 @@ function data_load(filename)
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
for line in fp:lines() do
|
for line in fp:lines() do
|
||||||
local part = string.split(line, '|')
|
local part = read_data_line(line)
|
||||||
local item = {}
|
local item = {}
|
||||||
if part and part[1] and part[2] and part[3] then
|
if part and part[1] and part[2] and part[3] then
|
||||||
local key = insensitive and part[1]:lower() or part[1]
|
local key = insensitive and part[1]:lower() or part[1]
|
||||||
@@ -1135,7 +1156,7 @@ function data_save(filename, M)
|
|||||||
end
|
end
|
||||||
for i = 1, #M do
|
for i = 1, #M do
|
||||||
local item = M[i]
|
local item = M[i]
|
||||||
local text = item.name .. '|' .. item.rank .. '|' .. item.time
|
local text = item.name .. Z_DATA_SEPARATOR .. item.rank .. Z_DATA_SEPARATOR .. item.time
|
||||||
fp:write(text .. '\n')
|
fp:write(text .. '\n')
|
||||||
end
|
end
|
||||||
fp:close()
|
fp:close()
|
||||||
|
|||||||
Reference in New Issue
Block a user