1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-22 15:49:47 +00:00

150 Commits

Author SHA1 Message Date
skywind3000
3875d774cb fixed nushell completion issue 2024-10-18 10:35:14 +08:00
skywind3000
dff590adc1 update docs 2024-10-18 03:09:39 +08:00
skywind3000
20c0494d44 update docs 2024-10-17 08:04:13 +08:00
skywind3000
67405d57e8 update gitignore 2024-10-16 00:31:50 +08:00
skywind3000
6e67a32520 fix: indentation consistency 2024-10-14 15:42:46 +08:00
Linwei
c334bc1ae5 Merge pull request #210 from brglng/feature/nushell
feat: add initial support for nushell (wip)
2024-10-10 15:17:31 +08:00
Zhaosheng Pan
0f6318ce4c fix(nushell): chdir failure 2024-10-09 14:59:05 +08:00
Zhaosheng Pan
3b55089ad8 improve README 2024-10-09 12:44:15 +08:00
Zhaosheng Pan
c58d31ec1d feat: add initial support for nushell 2024-10-08 18:11:32 +08:00
skywind3000
7c890c3645 Improve handling of the '--help' option in _zlua() function to improve
zsh compatibility.
2024-04-30 17:16:36 +08:00
skywind3000
7af012cc35 fixed: interpret _ZL_ZSH_NO_FZF in a wrong way. 2024-04-20 20:38:20 +08:00
skywind3000
019b2af475 add a return statement for nil case in os.interpreter() function. 2024-04-07 11:26:35 +08:00
Linwei
ef9a49d73d Merge pull request #158 from ibayramli/fig
Add Fig as an installation method to the README
2024-03-20 22:19:26 +08:00
skywind3000
7cd399b30d bloat version 2024-03-20 22:17:58 +08:00
Linwei
9112f0e9cc Merge pull request #189 from Arkaeriit/fix_pipes_in_filenames
Support '|' in path
2024-03-20 22:13:57 +08:00
Maxime Bouillot
cb4c9d3c8f Revert back to the old separator and improve db reading
A smarter reading function lets us support '|' in
filenames whilst still using it as the database
separator.
2024-03-20 14:38:04 +01:00
Maxime Bouillot
924f61a48b Change separator in data file
Using '|' as the data separator caused crashes if
a path with a '|' char in it was in the data file.
Changing that separator to a null byte ensures
that this kind of issue can never happen again as
the null byte can't be in a path.
2024-03-06 14:52:16 +01:00
skywind3000
30220996ca fix typo 2024-02-20 12:40:23 +08:00
skywind3000
d3ba781d4d Refactor the z.lua.plugin.zsh script to ensure proper initialization with or without FZF support 2024-02-20 11:43:00 +08:00
skywind3000
9a24fef334 Refactor logic to initialize fzf in zsh plugin to support a new condition where fzf can be disabled. 2024-02-19 11:29:04 +08:00
skywind3000
a9e034cb5c Update z.lua zsh plugin to allow customization of the fzf command used for fuzzy finding.
- Introduced new environment variable _ZL_ZSH_FZF to specify the fzf command
- Updated the eval statement to use the custom fzf command if provided by the user
2024-02-19 11:24:30 +08:00
Linwei
992134061a Merge pull request #196 from ilyagr/hyphens
Make z.lua try treating `-` as a normal character if there are no results
2023-12-11 01:11:14 +08:00
Ilya Grigoriev
b62784b66d Make z.lua try treating - as a normal character if there are no results
Previously, you needed to set `_ZL_HYPHEN=1` to treat `-` as a normal
character.  Otherwise, it was treated as a Lua regexp special character, see
https://www.lua.org/pil/20.2.html. Note that it is not super-useful to treat
`-` as a special character; it is almost the same as `*` and the difference
is not very useful in the context of fuzzy matching.

Now, if `_ZL_HYPHEN` is not set, z.lua first tries to treat it as a regexp
character. If there are no results (which is likely if the user does not know
it's a special character), z.lua tries again, treating `-` as a normal
character this time.

If `_ZL_HYPHEN=0` or `_ZL_HYPHEN=1`, z.lua will always treat `-` as
either a regex symbol or as a normal character (respectively).

Hopefully, this will make the FAQ at
https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-input-a-hyphen---in-the-keyword-
unnecessary.  It took me weeks to look into the question of why `z
home-manager` refused to work and to find that FAQ. 

I only tested this briefly, but it seems to work.
2023-12-08 22:21:38 -08:00
Linwei
7f2bfcbfc1 Merge pull request #185 from kang8/feature/support-fzf-for-zsh-tab
ZSH: TAB complete using fzf
2023-07-13 11:02:56 +08:00
kang
86cb43af67 ZSH: TAB complete using fzf
Tested in Linux(ArchLinux) and MacOS

Close: #99, #77
2023-07-13 10:29:48 +08:00
skywind3000
71bae7fc0b refine window batch script initializing 2023-05-19 10:51:41 +08:00
Linwei
4d89b55363 Merge pull request #181 from chrisant996/clink_changes
Clink changes
2023-05-18 05:49:33 +08:00
Chris Antos
db1a863d40 Update z completions for Clink.
- Added description strings for the flags.
- Added dir completions for the `-x` flag.
2023-05-17 10:48:42 -07:00
Chris Antos
dff016528c z.lua was missing some lines for z.cmd.
The auto-init for z.cmd was missing a couple of lines.  The HomeDir
line, in particular, is important because it enables Lua to find the
z.lua script.
2023-05-17 10:48:05 -07:00
Linwei
6fe677aae4 Merge pull request #179 from Kosette/master
fix potential compatibilty issue for some fish shell versions and add…
2023-05-04 18:17:06 +08:00
Simsum
ba83bf67b2 fix potential compatibilty issue for some fish shell versions and add autocompletion for cmd options
1. `alias` command not available in some fishshell versions like 3.3.1. use fish-native `function` instead;
2. add autocompletion for cmd options benefitting from magic power of fish. just type `z -` and press tab. enjoy yourself.
2023-05-04 17:49:20 +08:00
skywind3000
0992ebf9f1 update z.lua 2022-09-29 15:48:52 +08:00
Linwei
83dfec0843 Merge pull request #170 from ilyagr/fuzzy-zb
Allow `z -b` to do fuzzy matching
2022-09-06 21:13:00 +08:00
Ilya Grigoriev
3703c5a0ea Put z -b foo bar in command summary, add regex docs 2022-08-27 22:00:52 -07:00
Ilya Grigoriev
3894a6b936 Reduce indentation and add comments 2022-08-27 22:00:52 -07:00
Ilya Grigoriev
0905165889 Allow z -b to do fuzzy matching
If `z -b foo bar` finds no exact match in the path to the current directory,
it tries a "fuzzy" substitution with a frecent directory. For example, if
we are in `~/github/jekyll/test` and run `z -b jek gh`, it will try to
substitute the entire `jekyll` path component with `gh`. The result will
be equivalent to running `z ~/github gh test`.
2022-08-27 22:00:52 -07:00
Linwei
3009e33176 Merge pull request #167 from FlTr/convert-string-to-float
Substitute comma with dot before conversion
2022-08-15 17:17:25 +08:00
FlTr
32786a0592 Substitute comma with dot before conversion 2022-08-15 09:37:36 +02:00
Linwei
47468a8588 Merge pull request #165 from ilyagr/ilya
Fixes and docs for the ranger plugin
2022-08-14 15:52:11 +08:00
Ilya Grigoriev
f347eaf1c8 Slight stylistic edits to ranger_zlua.py 2022-08-13 18:10:20 -07:00
Ilya Grigoriev
e11d2e2017 Fixes and docs for the ranger plugin
- Makes Ranger plugin use the standard `$ZLUA_LUAEXE` and `$ZLUA_SCRIPT`
  environment variables that `z.lua` itself uses.

- Better error handling; errors loading plugin no longer cause
  `ranger` to quit entirely.

- Briefly document the plugin
2022-08-13 16:14:50 -07:00
skywind3000
3ecc14747f prevent loading 2022-08-10 16:58:47 +08:00
skywind3000
632f722ee4 bloat version number 2022-07-21 22:12:50 +08:00
Linwei
9b9c0b82e6 Merge pull request #163 from jpcirrus/patch-1
Update fzf --inline-info option to --info=inline
2022-07-21 22:11:56 +08:00
John Purnell
08510fe6c6 Update fzf --inline-info option to --info=inline
fzf changed the option `--inline-info` to the equivalent `--info=inline` in release 0.19.0 with commit junegunn/fzf@d2fa470165 on 2019-11-14.
2022-07-21 15:30:21 +02:00
Ilkin Bayramli
4c05e0d911 Add Fig as an installation method to the README 2022-06-15 10:12:16 -07:00
Linwei
1ead694395 Merge pull request #157 from wtfzambo/patch-1
docs: added warning for powershell users
2022-06-14 20:35:45 +08:00
wtfzambo
ee6aa2c5ce docs: added warning for powershell users
`.zlua` file doesn't get created for Powershell users that use [Starship Prompt](https://starship.rs/) and place z.lua init command before starship init command in their `profile.ps1`.

Couldn't reproduce the bug in zsh. Didn't test other shells.
2022-06-14 06:16:58 -04:00
skywind3000
a8e92e0216 fix Monterey initialization issues 2022-03-27 21:51:29 +08:00
skywind3000
e2cce39ee4 bloat version to 1.8.14 2022-01-30 21:54:08 +08:00
skywind3000
3c88f8d8fa recognize %_ZL_CD% in cmd.exe 2022-01-30 10:55:40 +08:00
Linwei
786225005c Merge pull request #148 from phanirithvij/imgbot
[ImgBot] Optimize images
2022-01-29 18:37:34 +08:00
ImgBotApp
481c1774ed [ImgBot] Optimize images
*Total -- 161.14kb -> 53.31kb (66.92%)

/images/step1.png -- 27.95kb -> 7.53kb (73.06%)
/images/mru.png -- 38.12kb -> 10.42kb (72.68%)
/images/fzf.png -- 29.02kb -> 8.47kb (70.81%)
/images/complete-2.png -- 28.69kb -> 9.05kb (68.46%)
/images/complete-1.png -- 12.35kb -> 5.12kb (58.53%)
/images/step2.png -- 12.63kb -> 5.66kb (55.16%)
/images/step3.png -- 7.56kb -> 3.63kb (52.03%)
/images/step4.png -- 4.83kb -> 3.44kb (28.77%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
2022-01-29 07:03:13 +00:00
Linwei
35e1199eff Merge pull request #145 from doubleloop/zluaexec
Try luajit in zsh and fish, fix ZLUA_EXEC check
2021-11-14 01:40:55 +08:00
Jakub Łuczyński
99dbe7b677 Mention support for luajit in README 2021-11-13 11:29:00 +01:00
Jakub Łuczyński
c88746629b zsh plugin: fix ZLUA_EXEC check
Previous check required full path (even if value was available in PATH)
2021-11-13 10:33:41 +01:00
Jakub Łuczyński
336e95b05a Try luajit in zsh and fish 2021-11-13 10:32:59 +01:00
Linwei
a3d4f5db68 Merge pull request #138 from FlTr/path-exists-17
path valid if error code 17 by os.rename
2021-05-05 16:41:06 +08:00
TRF2SGM
a991162428 #136 path valid if error code 17 by os.rename 2021-05-03 12:13:34 +02:00
Linwei
8210c56414 Merge pull request #132 from ilyagr/patch-1
Improve Fish installation instructions
2021-03-08 23:16:40 +08:00
Ilya Grigoriev
a01b28a8d3 Fixup #2 2021-03-08 01:26:22 -08:00
Ilya Grigoriev
695533cee1 Fixup 2021-03-08 01:17:50 -08:00
Ilya Grigoriev
58425dad65 Improve Fish installation instructions
Most notably, this adds instructions of changing $_Z_CD.  I think many
`fish` users would find them useful.
See https://github.com/skywind3000/z.lua/pull/131 for more background.

This makes the installation instructions more conventional (`|source` 
instead of `psub`). This also deletes the second (equivalent) set of instructions.
If the warning in that sentence is important, we could add it back, but
it would apply to all the shells, wouldn't it?

Finally, some wording is improved.
2021-03-08 01:15:26 -08:00
Linwei
44a2489ba3 Merge pull request #131 from ilyagr/add_builtin_cd_doc
Add default to docs for $_ZL_CD
2021-03-04 22:28:18 +08:00
Ilya Grigoriev
6e01d4ad52 Add default to docs for $_ZL_CD
I don't know if the default of `builtin cd` is a good one, as opposed to simple `cd`. It took me quite a bit of debugging before I figured out why, on my `fish` shell, changing directories with `z.lua` messed up the `cdh` (cd history) command.

I think the best thing would be to change the default. However, if you have a good reason to stick with it, I thought that documenting this potentially unexpected behavior might help.
2021-03-04 00:56:51 -08:00
skywind3000
c3c15a3ca9 remove redundant comments 2021-02-15 05:13:24 +08:00
skywind3000
cfad8f54ce update doc 2021-02-15 00:06:38 +08:00
skywind3000
501f619f94 improve powershell 7 compatibility 2021-02-15 00:02:23 +08:00
skywind3000
7a8acd469d update z.lua to 1.8.11 2020-12-31 02:11:09 +08:00
skywind3000
52e066aae7 commit new z.lua 2020-12-31 02:05:46 +08:00
skywind3000
e1a44ee9a5 fix: pushd leak in windows cmd 2020-12-31 01:47:18 +08:00
Linwei
9c0eb6cfbc Merge pull request #127 from chrisant996/fixpushd
Fix leaked pushd
2020-12-30 23:01:17 +08:00
Chris Antos
e646d5baa5 A better fix for the final blank line. 2020-12-30 05:00:26 -08:00
Chris Antos
be90b1a528 Match original output.
Originally `z foo` printed a blank line after the command.  My recent
change accidentally changed how CMD interpreted the end of the file such
that CMD stopped printing the blank line.  This change adjusts the end
of the file to once again cause CMD to print a blank line on finish.
2020-12-30 04:50:29 -08:00
Chris Antos
bda94435fc Fix leaked pushd.
`z somedir` uses double `pushd` to tunnel the new path out past the
endlocal that restores the environment state.  But it ended up leaving
a pushd on the dir stack.

This change exploits normal variable expansion to restore the dir stack
to its initial state while still successfully tunneling the new path out
past the endlocal.
2020-12-30 04:42:05 -08:00
skywind3000
831d617cef improve clink 1.1 compatibility 2020-12-24 15:27:48 +08:00
Linwei
97fa941ac3 Merge pull request #126 from chrisant996/master
Add flags to the `z` arg matcher for Clink.
2020-12-24 10:36:57 +08:00
Chris Antos
c0ff299d67 Add flags to the z arg matcher for Clink. 2020-12-23 14:48:48 -08:00
skywind3000
3deb8c7b5c advance version number 2020-12-23 16:37:56 +08:00
Linwei
222b28571f Merge pull request #125 from fcying/master
add _ZL_CLINK_PROMPT_PRIORITY set clink prompt register priority.
2020-12-23 16:36:16 +08:00
fcying
48a77adf35 add _ZL_CLINK_PROMPT_PRIORITY set clink prompt register priority. 2020-12-23 14:41:27 +08:00
Linwei
72c3676344 Merge pull request #123 from kankaristo/patch-1
Fix `z -I` in ranger_zlua.py
2020-11-25 22:12:30 +08:00
Sami Kankaristo
9dc5875fa3 Fix z -I in ranger_zlua.py
`z -I` had 2 issues:
- it used  `subprocess.check_output()`, but didn't UTF-8 decode the string (like the `if mode` statement's `else` branch does on row 80)
- it wasn't actually interactive, like `-I` is supposed to be (subprocess.check_output()` is not interactive)

I'm not sure why `-I` mode was originally treated differently from e.g. `-i` mode, but the same code works for both.

I took the `redraw_window` console command from the original `-I` mode code, because without it the screen updates a bit slower, causing an ugly "flash".
2020-11-25 14:19:08 +02:00
skywind3000
c90279b677 expose '--add' in cmd.exe 2020-10-31 18:59:03 +08:00
Linwei
9fb8cadda3 Merge pull request #120 from azuwis/master
Use `command -v` to reduce zsh startup time
2020-10-22 11:50:19 +08:00
Zhong Jianxin
edd92d935d Use command -v to reduce zsh startup time 2020-10-22 10:55:23 +08:00
Linwei
7848a0a2f3 Merge pull request #114 from ayalhw/patch-1
Update Fisher compatibility
2020-08-09 14:59:25 +08:00
Coelacanthus
515da0a3d1 Update Fisher compatibility
更新 fisher 路径
https://github.com/jorgebucaran/fisher/pull/571
2020-08-09 13:14:07 +08:00
Linwei
aebd18cec4 Merge pull request #113 from 3usi9/master
Add Powershell support
2020-08-04 17:48:34 +08:00
3usi9
90223cf10b Add Powershell support 2020-08-04 17:37:46 +08:00
Linwei
d666c93ed9 Merge pull request #111 from stigkj/patch-1
Fix benchmark table markdown formatting
2020-08-01 02:45:46 +08:00
Stig Kleppe-Jørgensen
805e5c24f3 Fix benchmark table markdown formatting 2020-07-31 17:31:16 +02:00
skywind3000
65bfbf8dfb update lfs detection 2020-06-29 19:40:55 +08:00
skywind3000
1b9630e72d Merge branch 'master' of https://github.com/skywind3000/z.lua 2020-06-29 18:11:32 +08:00
skywind3000
c98d2d783e use lfs module or cffi in luajit if possible 2020-06-29 18:11:23 +08:00
Linwei
057e4f77f3 Merge pull request #108 from exic/patch-1
Update README.md
2020-05-29 17:34:37 +08:00
Jonas
8a90ca6df4 Update README.md
Fix typo
2020-05-29 11:14:38 +02:00
skywind3000
a4c51d8103 update doc 2020-03-28 19:48:20 +08:00
skywind3000
b40df870a6 update doc 2020-03-18 22:47:05 +08:00
skywind3000
a55bb87e1b update docs 2020-03-18 22:38:46 +08:00
skywind3000
c4512b47d2 update doc 2020-03-18 22:36:35 +08:00
skywind3000
6c567b60b3 update doc 2020-03-17 23:12:08 +08:00
skywind3000
8fff9e6471 update doc 2020-03-17 23:11:13 +08:00
skywind3000
f7a9104983 update z.lua 2020-03-17 16:38:30 +08:00
skywind3000
7b43a0afd6 Merge branch 'master' of https://github.com/skywind3000/z.lua 2020-03-17 16:37:48 +08:00
skywind3000
788c0f4b77 new --init option clean to skip hooks 2020-03-17 16:37:21 +08:00
skywind3000
47aa86b0f9 remove files 2020-03-17 11:37:04 +08:00
skywind3000
a1498c8672 update 2020-03-17 02:35:21 +08:00
skywind3000
4c34e29e08 update 2020-03-17 02:26:49 +08:00
skywind3000
3d188ab6d9 update 2020-03-17 02:05:41 +08:00
skywind3000
a5f4cb692c update 2020-03-17 00:50:27 +08:00
skywind3000
77a917d116 update czmod.z 2020-03-17 00:20:06 +08:00
skywind3000
93e9715e7d commit new iposix.c/.h 2020-03-16 23:11:09 +08:00
skywind3000
b7c3fbc4ee update new imembase.c 2020-03-16 22:44:24 +08:00
skywind3000
ebda4aa061 update module 2020-03-16 22:30:50 +08:00
skywind3000
168ec49849 update 2020-03-16 18:48:26 +08:00
skywind3000
ec123de01a update 2020-03-12 18:35:03 +08:00
skywind3000
a0d4750431 commit czmod 2020-03-11 16:23:14 +08:00
skywind3000
d615051a10 improve compinit handling 2020-03-08 00:14:04 +08:00
skywind3000
f448f2ab1f suppress compdef error message if compinit hasn't been invoked. 2020-03-05 18:09:21 +08:00
Linwei
8ed3422670 Merge pull request #93 from Aloxaf/no_compctl
Improve zsh's completion
2020-02-28 17:26:27 +08:00
Aloxaf
3edbda89a0 Improve zsh's completion 2020-02-28 15:32:30 +08:00
Linwei
c9b50b3c50 Merge pull request #92 from kidonng/add-fisher-compatibility
添加 Fisher 支持
2020-02-23 17:28:34 +08:00
Kid
228addbc49 Add Fisher compatibility 2020-02-23 13:48:37 +08:00
skywind3000
bca25eba12 fish shell: set $_ZL_ECHO in global scope 2020-02-10 19:26:22 +08:00
skywind3000
097ca07ecd update fish script 2020-02-10 18:24:20 +08:00
skywind3000
4ee783956d update doc 2020-02-10 10:52:03 +08:00
skywind3000
0effba4021 polish: 1.8.3 2020-02-10 00:14:09 +08:00
skywind3000
cada42e5ea z.lua 1.8.3: polish interactive mode in z -b -i 2020-02-10 00:09:08 +08:00
skywind3000
b8b6d1afd6 z.lua 1.8.2 2020-02-09 23:46:35 +08:00
skywind3000
4abe97f989 jump backwards 2020-02-09 23:39:36 +08:00
skywind3000
756d13d8fa zlua 1.8.1: new -b -i and -b -I for interactive backwards cd 2020-02-09 23:34:37 +08:00
skywind3000
4900651af3 Merge branch 'master' of https://github.com/skywind3000/z.lua 2019-12-29 04:59:20 +08:00
skywind3000
836efd3973 1.7.4: new $_ZL_HYPHEN option 2019-12-29 04:59:08 +08:00
Linwei
3b8b4c1fbb Merge pull request #87 from davidosomething/no-aliases
Introduce _ZL_NO_ALIASES to skip creating aliases
2019-12-26 00:35:12 +08:00
David O'Trakoun
8eaebca04a Introduce _ZL_NO_ALIASES to skip creating aliases 2019-12-25 00:16:44 -05:00
Linwei
fdd037acf8 Merge pull request #85 from rongmu/_zl_fzf_flag-fix
[zsh plugin] allow the user to customize _ZL_FZF_FLAG beforehand
2019-12-10 17:45:04 +08:00
Shaoyun Yu
a817cf6ed2 allow the user to custom _ZL_FZF_FLAG beforehand
increase flexibility: allow the user to custom _ZL_FZF_FLAG before the zsh plugin is loaded
2019-12-10 10:50:55 +09:00
skywind3000
5c36d55698 use lua-filesystem package if possible when $_ZL_USE_LFS is 1 2019-09-07 01:02:48 +08:00
skywind3000
bdab27db1b fixed wrong return value from os.path.exists 2019-09-06 01:21:28 +08:00
skywind3000
e08f5beca4 update doc 2019-08-01 20:06:05 +08:00
skywind3000
a245db0d93 update doc 2019-08-01 19:54:34 +08:00
skywind3000
dd721703c3 1.7.2: improve bash / zsh shell compatibility 2019-08-01 19:46:23 +08:00
Linwei
7920d56c89 Merge pull request #71 from barlik/prompt-command
Do not append semicolon to PROMPT_COMMAND
2019-08-01 17:45:54 +08:00
Linwei
645818ccc8 Merge pull request #72 from barlik/zsh-hooks 2019-08-01 02:41:19 +08:00
Rastislav Barlik
b98911a227 Setting zsh-hooks to be unique is not necessary 2019-07-31 14:46:28 +01:00
Rastislav Barlik
671830059b Do not append semicolon to PROMPT_COMMAND 2019-07-31 13:47:55 +01:00
skywind3000
0fad96124b commit new README.md 2019-06-07 22:17:42 +08:00
skywind3000
465f2b8e62 fixed linux $_ZL_DATA failure 2019-06-07 22:13:29 +08:00
skywind3000
ff9d874ef4 update doc 2019-03-09 17:24:53 +08:00
17 changed files with 812 additions and 226 deletions

1
.gitignore vendored
View File

@@ -39,3 +39,4 @@ luac.out
*.x86_64
*.hex
/.vscode/*

View File

@@ -14,11 +14,11 @@ z.lua 是一个快速路径切换工具,它会跟踪你在 shell 下访问过
- 性能比 **z.sh** 快三倍,比 **fasd** / **autojump** 快十倍以上。
- 支持 Posix Shellbash, zsh, dash, sh, ash, busybox 等等。
- 支持 Fish ShellPower Shell 和 Windows cmd。
- 使用增强匹配算法,更准确的带你去到你想去的地方。
- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1
- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。
- 集成 fzf (可选),可以用来做可视化选择或者参数补全。
- 支持 Fish ShellPower Shell 和 Windows cmd。
- 使用增强匹配算法,更准确的带你去到你想去的地方。
- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1
- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。
- 集成 fzf (可选),可以用来做可视化选择或者参数补全。
- 快速跳转到父目录,或者项目根目录,代替反复 “cd ../../.." 。
- 兼容 lua 5.1, 5.2 和 5.3 以上版本。
- 自包含且无额外依赖,单个 `z.lua` 文件完成所有工作。
@@ -42,10 +42,10 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
## Install
- Posix ShellsBash、zsh、dash、sh 或 BusyBox 等):
在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句:
- Posix ShellsBash、zsh、dash、sh 或 BusyBox 等):
在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句:
eval "$(lua /path/to/z.lua --init bash)" # BASH 初始化
eval "$(lua /path/to/z.lua --init zsh)" # ZSH 初始化
eval "$(lua /path/to/z.lua --init posix)" # Posix shell 初始化
@@ -65,7 +65,12 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
antigen bundle skywind3000/z.lua
就可以了(主要要放在 antigen apply 语句之前)。
**注意**:使用 WSL-1 的用户,需要安装 `lua-filesystem` 包:
sudo apt-get install lua-filesystem
这是由于 wsl-1 的 [bug](https://github.com/microsoft/WSL/issues/5505) 引起的,使用 lua-filesystem 可以避免该问题。
- Fish Shell:
@@ -79,18 +84,29 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
但是第二种方法需要记得在 z.lua 位置改变或者 lua 版本升级后需要重新生成。
- Power Shell:
- Nushell:
`env.nu` 中加入如下代码:
lua /path/to/z.lua --init nushell | save -f ~/.cache/zlua.nu
然后在 `config.nu` 中加入如下代码:
source ~/.cache/zlua.nu
alias z = _zlua
- Power Shell:
在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句:
iex ($(lua /path/to/z.lua --init powershell) -join "`n")
Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
- Windows cmd (with clink):
- 将 z.lua 和 z.cmd 拷贝到 clink 的安装目录。
- 将 clink 的安装目录添加到 `%PATH%` (z.cmd 可以被任意位置调用到)。
- 保证 lua 命令在你的 `%PATH%` 环境变量中。
- 保证 lua 命令在你的 `%PATH%` 环境变量中。
- Windows cmder:
@@ -111,6 +127,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
- 设置 `$_ZL_HYPHEN` 为 1 可以允许关键字中包含横线 (横线默认是 lua 正则关键字,要转写成 `%-`)。
## Aging
@@ -161,7 +178,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
2. 最后一个关键字可以和路径名的最后一段相匹配。
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
@@ -175,14 +192,14 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
30 /home/user/workspace/project2
40 /home/user/workspace/project3
在增强模式下使用 `"z wo"` 的话,只有 `/home/user/work` 满足匹配,因为按照第二条规则,这是唯一一条最有一段名称匹配 `wo` 的路径。
在增强模式下使用 `"z wo"` 的话,只有 `/home/user/workspace` 满足匹配,因为按照第二条规则,这是唯一一条最有一段名称匹配 `wo` 的路径。
因为最后一级目录名称总是最容易记住的,所以给到它比较高的优先级。在默认匹配算法中,你同样可以用 `"z space$"` 来达到相同的目的,但是 `"z wo"` 可以打更少的字。
小技巧:
- 如果你在增强匹配算法下,想让最后一个关键字不当匹配最后一段路径名,还可以像默认匹配算法中一样匹配路径的其他部分的话,你可以在最后加一个独立的 '$' 参数,比如:`"z wo $"`
- 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。
- 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。
- 如果没法匹配,同时又存在一条路径名和关键字相同,那么 cd 过去:
@@ -265,7 +282,7 @@ PS你可以使用 `$_ZL_FZF` 环境变量来精确指明 fzf 的可执行路
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
- **(没有参数)**`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
- **(没有参数)**`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
- **(单个参数)**`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
@@ -302,6 +319,8 @@ export _ZL_ROOT_MARKERS=".git,.svn,.hg,.root,package.json"
**Bonus**`zb ..` 相当于 `cd ..``zb ...` 相当于 `cd ../..`,而 `zb ....` 相当于 `cd ../../..` 等等。 最后 `zb ..20` 等同于调用 `cd ..` 二十次。
**Bonus**: 试试 `z -b -i` 以及 `z -b -I`,推荐把他们取个别名成 `zbi` 和 `zbf`。
## 补全功能
@@ -317,7 +336,13 @@ zsh/fish 的补全系统是比较完善的,使用 `z foo<tab>` 就能触发补
eval "$(lua /path/to/z.lua --init bash enhanced once echo fzf)"
```
然后你在 bash 中,输入部分关键字后按 tab就能把匹配的路径列出来
如果你想在 zsh 中使用 fzf 补全,初始化时在 `--init` 后追加 `fzf` 关键字
```zsh
eval "$(lua /path/to/z.lua --init zsh enhanced once echo fzf)"
```
然后你在 bash/zsh 中,输入部分关键字后按 tab就能把匹配的路径列出来
![](images/complete-2.png)
@@ -430,15 +455,13 @@ sys 0m0.030s
描述力强,可以更好的实现核心功能,同时速度更快,纯 shell 开发的话,太多语句是通过子进程 shell 的模式运行,所以性能很差,而 Python 开发的话启动速度又太慢,我在 Cygwin/msys 下用 z.sh 都觉得很卡autojump/fasd 卡到不能用。
最关键的一点Lua 速度很快 200 KB 的可执行程序,启动速度是 python 的 3倍perl 的 2 倍,很多命令行工具 go/rust 写成,动不动就 2MB / 3MB他们都还没有完成加载lua 脚本可能都运行完了。
最关键的一点Lua 速度很快 200 KB 的可执行程序,启动速度是 python 的 3 perl 的 2 倍,很多命令行工具 go/rust 写成,动不动就 2MB / 3MB他们都还没有完成加载lua 脚本可能都运行完了。
## Credit
Releated projects:
- [rupa/z](https://github.com/rupa/z): origin z.sh implementation
- [JannesMeyer/z.ps](https://github.com/JannesMeyer/z.ps): z for powershell
我的推特https://x.com/skywind3000
个人博客: https://skywind.me/blog
## License

174
README.md
View File

@@ -13,40 +13,60 @@ z.lua is a faster way to navigate your filesystem. It tracks your most used dire
For example, `z foo bar` would match `/foo/bar` but not `/bar/foo`.
## Reputation
From people using z.lua:
- I like this in principal. Im pretty damn predictable at the command line and far too lazy to make shortcuts
- It feels far more intuitive and it's so incredibly convenient to be able to jump between folders I'm working in without having to traverse an entire tree. The shell used to feel so constraining for me, but tools like this are making me enjoy it so much more.
- I can finally have autojump-like functionality on my Raspberry Pi 1 without waiting 30 seconds every time I open a new shell. Thanks z.lua devs.
- Anyway, z.lua is a promising project. If you only need directory jumping, it may be the best choice.
## Features
- **10x** times faster than **fasd** and **autojump**, **3x** times faster than **z.sh**.
- Gain the ultimate speed with an optional [native module](https://github.com/skywind3000/czmod) written in C.
- Available for **posix shells**: bash, zsh, dash, sh, ash, ksh, busybox and etc.
- Available for Fish Shell, Power Shell and Windows cmd.
- [Enhanced matching algorithm](#enhanced-matching) takes you to where ever you want precisely.
- Allow updating database only if `$PWD` changed with "$_ZL_ADD_ONCE" set to 1.
- Interactive selection enables you to choose where to go before cd.
- Intergrated with FZF (optional) for interactive selection and completion.
- Integrated with FZF (optional) for interactive selection and completion.
- Quickly go back to a parent directory instead of typing "cd ../../..".
- Corresponding experience in different shells and operating systems.
- Compatible with Lua 5.1, 5.2 and 5.3+
- Compatible with Lua (5.1, 5.2, 5.3+) and luajit.
- Self contained, distributed as a single `z.lua` script, no other dependence.
## Examples
```bash
z foo # cd to most frecent dir matching foo
z foo bar # cd to most frecent dir matching foo and bar
z -r foo # cd to the highest ranked dir matching foo
z -t foo # cd to most recently accessed dir matching foo
z -l foo # list matches instead of cd
z -c foo # restrict matches to subdirs of $PWD
z -e foo # echo the best match, don't cd
z -i foo # cd with interactive selection
z -I foo # cd with interactive selection using fzf
z -b foo # cd to the parent directory starting with foo
z foo # cd to most frecent dir matching foo
z foo bar # cd to most frecent dir matching foo and bar
z -r foo # cd to the highest ranked dir matching foo
z -t foo # cd to most recently accessed dir matching foo
z -l foo # list matches instead of cd
z -c foo # restrict matches to subdirs of $PWD
z -e foo # echo the best match, don't cd
z -i foo # cd with interactive selection
z -I foo # cd with interactive selection using fzf
z -b foo # cd to the parent directory starting with foo
z -b foo bar # replace foo with bar in cwd and cd there
```
## 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:
put something like this in your `.bashrc`:
@@ -59,13 +79,19 @@ z -b foo # cd to the parent directory starting with foo
and perhaps this:
export _ZL_ECHO=1
eval "$(lua /path/to/z.lua --init bash enhanced once echo)"
if you want `z.lua` print the new directory after cd.
If you want `fzf` tab completion use:
For `fzf` tab completion use:
eval "$(lua /path/to/z.lua --init bash enhanced once fzf)"
**NOTE**: For wsl-1 users, `lua-filesystem` must be installed:
sudo apt-get install lua-filesystem
To avoid a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
- Zsh:
@@ -73,7 +99,9 @@ z -b foo # cd to the parent directory starting with foo
eval "$(lua /path/to/z.lua --init zsh)"
Options like "enhanced" and "once" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh).
Options like "enhanced", "once" and "fzf" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh).
**NOTE**: for wsl-1 users, `lua-filesystem` must be installed.
- Posix Shells:
@@ -87,37 +115,58 @@ z -b foo # cd to the parent directory starting with foo
To generate old posix compatible script.
- Fish Shell:
- Fish Shell (version `2.4.0` or above):
Create `~/.config/fish/conf.d/z.fish` with following code
source (lua /path/to/z.lua --init fish | psub)
lua /path/to/z.lua --init fish | source
Fish version `2.4.0` or above is required.
If you'd like `z.lua` to cooperate with fish's own [directory history](https://fishshell.com/docs/3.2/index.html#id34), you can put
lua /path/to/z.lua --init fish > ~/.config/fish/conf.d/z.fish
set -gx _ZL_CD cd
This is another way to initialize z.lua in fish shell, but remember to regenerate z.fish if z.lua has been updated or moved.
into the same file.
- Nushell
Put something like this in your `env.nu`:
lua /path/to/z.lua --init nushell | save -f ~/.cache/zlua.nu
Then put something like this in your `config.nu`:
source ~/.cache/zlua.nu
alias z = _zlua
- Power Shell:
> ⚠️ **WARNING**: users of [Starship Prompt](https://starship.rs/) should add the following command *after* `starship init`.
put something like this in your `profile.ps1`:
iex ($(lua /path/to/z.lua --init powershell) -join "`n")
Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
- Windows cmd (with clink):
- copy z.lua and z.cmd to clink's home directory
- Copy z.lua and z.cmd to clink's home directory
- Add clink's home to `%PATH%` (z.cmd can be called anywhere)
- Ensure that "lua" can be called in `%PATH%`
- Windows cmder:
- copy z.lua and z.cmd to cmder/vendor
- Copy z.lua and z.cmd to cmder/vendor
- Add cmder/vendor to `%PATH%`
- Ensure that "lua" can be called in `%PATH%`
- Windows WSL-1:
Install `lua-filesystem` module before init z.lua:
sudo apt-get install lua-filesystem
This module is required due to a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
## Options
@@ -127,10 +176,17 @@ z -b foo # cd to the parent directory starting with foo
- set `$_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude.
- set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed.
- set `$_ZL_MAXAGE` to define a aging threshold (default is 5000).
- set `$_ZL_CD` to specify your own cd command.
- set `$_ZL_CD` to specify your own cd command (default is `builtin cd` in Unix shells).
- set `$_ZL_ECHO` to 1 to display new directory name after cd.
- set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
- set `$_ZL_HYPHEN` to 0 to treat a hyphen (`-`) as a
[lua regexp special character](https://www.lua.org/pil/20.2.html),
set `$_ZL_HYPHEN` to 1 to treat a hyphen as a normal character.
If `$_ZL_HYPHEN` is not set or if it is set to `auto`, z.lua tries to treat `-`
as a lua regexp special character first. If there are no matches, z.lua tries
again, this time treating `-` as a normal character.
- set `$_ZL_CLINK_PROMPT_PRIORITY` change clink prompt register priority (default 99).
## Aging
@@ -146,16 +202,12 @@ To z.lua, a directory that has low ranking but has been accessed recently will q
## Default Matching
By default, z.lua uses default matching algorithm similar to the original z.sh. Paths must be match all of the regexes in order.
By default, `z.lua` uses default matching algorithm similar to the original `z.sh`. Paths must be match all of the regexes in order.
- cd to a directory contains foo:
z foo
- cd to a directory ends with foo:
z foo$
- use multiple arguments:
Assuming the following database:
@@ -165,6 +217,15 @@ By default, z.lua uses default matching algorithm similar to the original z.sh.
`"z in"` would cd into `/home/user/mail/inbox` as the higher weighted entry. However you can pass multiple arguments to z.lua to prefer a different entry. In the above example, `"z w in"` would then change directory to `/home/user/work/inbox`.
- use regexes:
```bash
z foo$ # cd to a directory ends with foo
z %d # cd to a directory that contains a digit
```
Unlike `z.sh`, `z.lua` uses the [Lua regular expression syntax](https://www.lua.org/pil/20.2.html).
## Enhanced Matching
Enhanced matching can be enabled by exporting the environment:
@@ -195,7 +256,7 @@ If no match is found, it will fall back to default matching method.
30 /home/user/workspace/project2
40 /home/user/workspace/project3
If you use `"z wo"` in enhanced matching mode, only the `/home/user/work` will be matched, because according to rule No.2 it is the only path whose last segment matches `"wo"`.
If you use `"z wo"` in enhanced matching mode, only the `/home/user/workspace` will be matched, because according to rule No.2 it is the only path whose last segment matches `"wo"`.
Since the last segment of a path is always easier to be recalled, it is sane to give it higher priority. You can also achieve this by typing `"z space$"` in both methods, but `"z wo"` is easier to type.
@@ -240,7 +301,7 @@ To enable this, you can set `$_ZL_ADD_ONCE` to `1` before init z.lua. Or you can
````bash
eval "$(lua /path/to/z.lua --init bash once)"
eval "$(lua /path/to/z.lua --init zsh once)"
source (lua /path/to/z.lua --init fish once | psub)
lua /path/to/z.lua --init fish once | source
````
With `add once` mode off (default), z.lua will consider the time you spent in the directory (like z.sh). When this mode is on, consider the times you accessed the directory (like autojump), and that could be much faster on slow hardware.
@@ -289,6 +350,7 @@ New option `"-b"` can quickly go back to a specific parent directory in bash ins
- **(No argument)**: `cd` into the project root, the project root the nearest parent directory with `.git`/`.hg`/`.svn` in it.
- **(One argument)**: `cd` into the closest parent starting with keyword, if not find, go to the parent containing keyword.
- **(Two arguments)**: replace the first value with the second one (in the current path).
If simple substitution does not work, falls back to fuzzily replacing path components.
Let's start by aliasing `z -b` to `zb`:
@@ -308,6 +370,11 @@ Let's start by aliasing `z -b` to `zb`:
# substitute jekyll with ghost
~/github/jekyll/test$ zb jekyll ghost
=> cd ~/github/ghost/test
# same as above, but fuzzy
~/github/jekyll/test$ zb jek gh
=> z ~/github/ gh /test
=> cd ~/github/ghost/test # Assuming that's the most frecent match
```
Backward jumping can also be used with `$_ZL_ECHO` option (echo $PWD after cd), which makes it possible to combine them with other tools without actually changing the working directory (eg. ``ls `zb git` ``).
@@ -322,6 +389,7 @@ If you want `zb` jump back to a parent directory contains a `.root` or `package.
**Bonus**: `zb ..` equals to `cd ..`, `zb ...` equals to `cd ../..` and `zb ....` equals to `cd ../../..`, and so on. Finally, `zb ..20` equals to `cd (..)x20`.
**Bonus**: try `z -b -i` and `z -b -I` and you can alias them to `zbi` and `zbf`.
## Completion
@@ -337,6 +405,12 @@ Bash is not as powerful as zsh/fish, so we introduced fzf-completion for bash, i
eval "$(lua /path/to/z.lua --init bash enhanced once echo fzf)"
```
If you want use fzf completion in zsh, initalize your z.lua and append `fzf` keyword after `--init`:
```zsh
eval "$(lua /path/to/z.lua --init zsh enhanced once echo fzf)"
```
Then press `<tab>` after `z xxx`:
![](images/complete-2.png)
@@ -389,6 +463,14 @@ At last, press `<enter>` to accept or `<ESC>` to give up.
Remember to enable the [enhanced matching](#enhanced-matching) algorithm, the current working directory can be skipped with it.
## Ranger integration
To add a `:z` command to the [`ranger` file manager], copy the `ranger_zlua.py` file to `~/.config/ranger/plugins/`.
You can then use `:z foo`, `:z -b foo`, etc. from ranger. Use `:z -h` for help.
[`ranger` file manager]: https://github.com/ranger/ranger
To define additional commands (`:zb` for example) in ranger, you can put `alias zb z -b` into `~/.config/ranger/rc.conf`.
## Tips
@@ -446,19 +528,33 @@ sys 0m0.030s
As you see, z.lua is the fastest one and requires less resource.
## Native Module
z.lua is fast enough for most case, the path tracking action will be triggered each time when you change your current directory.
## Reputation
So I still recommend the pure lua script for portability and flexibility, but for someone who really care about `10ms` or `1ms` things, this module can help them to gain the ultimate speed.
- [czmod](https://github.com/skywind3000/czmod): native module to boost `z.lua`.
Average performance:
| Name | czmod | z.lua |
|-|-|-|
| **Update Time** | 1.6ms | 13.2ms |
| **Query Time** | 1.5ms | 9.8ms |
- "I like this in principal. Im pretty damn predictable at the command line and far too lazy to make shortcuts"
- "It feels far more intuitive and it's so incredibly convenient to be able to jump between folders I'm working in without having to traverse an entire tree. The shell used to feel so constraining for me, but tools like this are making me enjoy it so much more. "
- "I can finally have autojump-like functionality on my Raspberry Pi 1 without waiting 30 seconds every time I open a new shell. Thanks z.lua devs."
- "Anyway, z.lua is a promising project. If you only need directory jumping, it may be the best choice."
## History
- 1.7.0 (2019-03-09): Support ranger, fix ReplaceFile issue in luajit (windows).
- 1.8.7 (2020-06-29): use lfs or luajit's cffi if possible.
- 1.8.4 (2020-02-10): fish shell: set `$_ZL_ECHO` to global scope.
- 1.8.3 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode.
- 1.7.4 (2019-12-29): new: `$_ZL_HYPHEN` to treat hyphen as a normal character, see [here](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-input-a-hyphen---in-the-keyword-).
- 1.7.3 (2019-09-07): use [lua-filesystem](http://keplerproject.github.io/luafilesystem/) package if possible when `$_ZL_USE_LFS` is `1`.
- 1.7.2 (2019-08-01): Improve bash/zsh shell compatibility by [@barlik](https://github.com/barlik).
- 1.7.1 (2019-06-07): Fixed: `$_ZL_DATA` failure on Linux sometimes.
- 1.7.0 (2019-03-09): Support [ranger](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-integrate-zlua-to-ranger-), fix ReplaceFile issue in luajit (windows).
- 1.6.0 (2019-03-04): optimize with ffi module (luajit builtin module).
- 1.5.11 (2019-03-02): fixed: os.path.isdir doesn't work for symbol link folders.
- 1.5.10 (2019-03-01): Prevent writing file racing.
@@ -510,6 +606,8 @@ This project needs help for the tasks below:
- Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish Shell porting.
- Thanks to [@manhong2112](https://github.com/manhong2112) for Power Shell porting.
- Thanks to [@BarbUk](https://github.com/BarbUk) for fzf completion in Bash.
- Thanks to [@barlik](https://github.com/barlik) for many improvements.
- Thanks to [@brglng](https://github.com/brglng) for nushell porting.
And many others.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@@ -17,11 +17,18 @@ end
set -x _ZL_DATA "$_ZL_DATA"
set _zlua_dir (dirname (status --current-filename))
set -q XDG_DATA_HOME; or set XDG_DATA_HOME ~/.local/share
if functions -q fisher
set _zlua_dir $XDG_DATA_HOME/fisher/github.com/skywind3000/z.lua
else
set _zlua_dir (dirname (status --current-filename))
end
if test -e $_zlua_dir/z.lua
if type -q lua
lua $_zlua_dir/z.lua --init fish enhanced once echo | source
else if type -q luajit
luajit $_zlua_dir/z.lua --init fish enhanced once echo | source
else if type -q lua5.3
lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source
else if type -q lua5.2
@@ -35,6 +42,8 @@ if test -e $_zlua_dir/z.lua
alias zz='z -i' # cd with interactive selection
alias zf='z -I' # use fzf to select in multiple matches
alias zb='z -b' # quickly cd to the parent directory
alias zbi='z -b -i' # interactive jump backward
alias zbf='z -b -I' # interactive jump backward with fzf
set -U ZLUA_SCRIPT "$ZLUA_SCRIPT" 2> /dev/null
set -U ZLUA_LUAEXE "$ZLUA_LUAEXE" 2> /dev/null
end

View File

@@ -2,41 +2,45 @@ import time, sys, os
import ranger.api
import subprocess
old_hook_init = ranger.api.hook_init
# $RANGER_LUA and $RANGER_ZLUA variables are deprecated, do not use them.
ZLUA_LUAEXE = os.environ.get('RANGER_LUA') or os.environ.get('ZLUA_LUAEXE')
ZLUA_SCRIPT = os.environ.get('RANGER_ZLUA') or os.environ.get('ZLUA_SCRIPT')
PATH_LUA = os.environ.get('RANGER_LUA')
PATH_ZLUA = os.environ.get('RANGER_ZLUA')
if not PATH_LUA:
if not ZLUA_LUAEXE:
for path in os.environ.get('PATH', '').split(os.path.pathsep):
for name in ('lua', 'luajit', 'lua5.3', 'lua5.2', 'lua5.1'):
test = os.path.join(path, name)
test = test + (sys.platform[:3] == 'win' and ".exe" or "")
if os.path.exists(test):
PATH_LUA = test
ZLUA_LUAEXE = test
break
if not PATH_LUA:
sys.stderr.write('Please install lua or set $RANGER_LUA.\n')
sys.exit()
def _report_error(msg):
sys.stderr.write('ranger_zlua: ' + msg)
raise RuntimeError(msg)
if (not PATH_ZLUA) or (not os.path.exists(PATH_ZLUA)):
sys.stderr.write('Not find z.lua, please set $RANGER_ZLUA to absolute path of z.lua.\n')
sys.exit()
if not ZLUA_LUAEXE:
_report_error('Please install lua in $PATH or make sure $ZLUA_LUAEXE points to a lua executable.\n')
if (not ZLUA_SCRIPT) or (not os.path.exists(ZLUA_SCRIPT)):
_report_error('Could not find z.lua, please make sure $ZLUA_SCRIPT is set to absolute path of z.lua.\n')
# Inform z.lua about directories the user browses to inside ranger
old_hook_init = ranger.api.hook_init
def hook_init(fm):
def update_zlua(signal):
import os, random
os.environ['_ZL_RANDOM'] = str(random.randint(0, 0x7fffffff))
p = subprocess.Popen([PATH_LUA, PATH_ZLUA, "--add", signal.new.path])
p = subprocess.Popen([ZLUA_LUAEXE, ZLUA_SCRIPT, "--add", signal.new.path])
p.wait()
if PATH_ZLUA and PATH_LUA and os.path.exists(PATH_ZLUA):
if ZLUA_SCRIPT and ZLUA_LUAEXE and os.path.exists(ZLUA_SCRIPT):
fm.signal_bind('cd', update_zlua)
return old_hook_init(fm)
ranger.api.hook_init = hook_init
class z(ranger.api.commands.Command):
def execute (self):
import sys, os, time
@@ -52,13 +56,13 @@ class z(ranger.api.commands.Command):
elif arg[:1] != '-':
break
if mode:
cmd = '"%s" "%s" '%(PATH_LUA, PATH_ZLUA)
cmd = '"%s" "%s" '%(ZLUA_LUAEXE, ZLUA_SCRIPT)
if mode in ('-I', '-i', '--'):
cmd += ' --cd'
for arg in args:
cmd += ' "%s"'%arg
if mode in ('-e', '-x'):
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
path = subprocess.check_output([ZLUA_LUAEXE, ZLUA_SCRIPT, '--cd'] + args)
path = path.decode("utf-8", "ignore")
path = path.rstrip('\n')
self.fm.notify(path)
@@ -69,18 +73,14 @@ class z(ranger.api.commands.Command):
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
stdout, stderr = p.communicate()
else:
if mode == '-I':
os.environ['_ZL_FZF_HEIGHT'] = '0'
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
self.fm.execute_console('redraw_window')
else:
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
path = stdout.rstrip('\n')
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
path = stdout.rstrip('\n')
self.fm.execute_console('redraw_window')
if path and os.path.exists(path):
self.fm.cd(path)
else:
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
path = subprocess.check_output([ZLUA_LUAEXE, ZLUA_SCRIPT, '--cd'] + args)
path = path.decode("utf-8", "ignore")
path = path.rstrip('\n')
if path and os.path.exists(path):

26
z.cmd
View File

@@ -1,10 +1,8 @@
@echo off
setlocal EnableDelayedExpansion
set "HomeDir=%~dp0"
set "PathSave=%PATH%"
set "LuaExe=lua"
set "LuaScript=%HomeDir%z.lua"
set "LuaScript=%~dp0z.lua"
set "MatchType=-n"
set "StrictSub=-n"
set "RunMode=-n"
@@ -54,6 +52,12 @@ if /i "%1"=="-x" (
goto parse
)
if /i "%1"=="--add" (
set "RunMode=--add"
shift /1
goto parse
)
if "%1"=="-i" (
set "InterMode=-i"
shift /1
@@ -100,13 +104,27 @@ if /i "%RunMode%"=="-n" (
pushd !NewPath!
pushd !NewPath!
endlocal
popd
goto popdir
)
)
) else (
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
)
goto end
:popdir
rem -- Exploits variable expansion and the pushd stack to set the current
rem -- directory without leaking a pushd.
popd
setlocal
set "NewPath=%CD%"
set "CDCmd=cd /d"
if /i not "%_ZL_CD%"=="" (
set "CDCmd=%_ZL_CD%"
)
endlocal & popd & %CDCmd% "%NewPath%"
:end
echo.

660
z.lua

File diff suppressed because it is too large Load Diff

View File

@@ -2,33 +2,38 @@
ZLUA_SCRIPT="${0:A:h}/z.lua"
[[ -n "$ZLUA_EXEC" ]] && [[ ! -x "$ZLUA_EXEC" ]] && ZLUA_EXEC=""
if [[ -n "$ZLUA_EXEC" ]] && ! which "$ZLUA_EXEC" &>/dev/null; then
echo "$ZLUA_EXEC not found"
ZLUA_EXEC=""
fi
# search lua executable
if [[ -z "$ZLUA_EXEC" ]]; then
if [[ -x "$(command which lua)" ]]; then
ZLUA_EXEC="$(command which lua)"
elif [[ -x "$(command which lua5.3)" ]]; then
ZLUA_EXEC="$(command which lua5.3)"
elif [[ -x "$(command which lua5.2)" ]]; then
ZLUA_EXEC="$(command which lua5.2)"
elif [[ -x "$(command which lua5.1)" ]]; then
ZLUA_EXEC="$(command which lua5.1)"
else
for lua in lua luajit lua5.4 lua5.3 lua5.2 lua5.1; do
ZLUA_EXEC="$(command -v "$lua")"
[[ -n "$ZLUA_EXEC" ]] && break
done
if [[ -z "$ZLUA_EXEC" ]]; then
echo "Not find lua in your $PATH, please install it."
return
fi
fi
export _ZL_FZF_FLAG="-e"
export _ZL_FZF_FLAG=${_ZL_FZF_FLAG:-"-e"}
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
alias zz='z -i'
alias zc='z -c'
alias zf='z -I'
alias zb='z -b'
alias zh='z -I -t .'
alias zzc='zz -c'
if [[ -z "$_ZL_ZSH_NO_FZF" ]]; then
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced fzf)"
else
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
fi
if [[ -z "$_ZL_NO_ALIASES" ]]; then
alias zz='z -i'
alias zc='z -c'
alias zf='z -I'
alias zb='z -b'
alias zbi='z -b -i'
alias zbf='z -b -I'
alias zh='z -I -t .'
alias zzc='zz -c'
fi