cannot get ranger_zlua.py working
Hi, thanks for all the work on z.lua. Nice to see the repository still active and the tool cared for. I love it and have been using all these years
I am trying to use it with ranger.
I read what the ranger wiki says, https://github.com/ranger/ranger. And what z.lua says, /usr/share/z.lua/README.md,
copy the `ranger_zlua.py` file to `~/.config/ranger/plugins/`.
Question 1 I am not 100% sure. Should I also chmod +x it ? I did it anyway
Question 2
# $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')
No matter what I tried I cannot have it working.
ranger_zlua: Could not find z.lua, please make sure $ZLUA_SCRIPT is set to absolute path of z.lua.
Error while loading plugin 'ranger_zlua'
I have a standard Archlinux installation. No hacks, not customizations. I have on my bashrc
eval "$(lua /usr/share/z.lua/z.lua --init bash enhanced once )"
On my shell
$ echo $ZLUA_LUAEXE
/usr/bin/lua
$ echo $ZLUA_SCRIPT
/usr/share/z.lua/z.lua
Are correctly displayed.
The only way I found was to hardcode and change in ranger_zlua.py both
ZLUA_LUAEXE = "/usr/bin/lua"
ZLUA_SCRIPT = "/usr/share/z.lua/z.lua"
Then it works.
I am not a developer. Not very proficient with git. The only possibly related stuff I found were these commits from 2 years ago,
f347eaf 2Y Ilya Grigoriev o Slight stylistic edits to `ranger_zlua.py`
e11d2e2 2Y Ilya Grigoriev o Fixes and docs for the ranger plugin
9dc5875 4Y Sami Kankaristo o Fix `z -I` in ranger_zlua.py
1e0e352 5Y skywind3000 I add ranger plugin for z.lua
-PATH_LUA = os.environ.get('RANGER_LUA') or os.environ.get('ZLUA_LUAEXE')
-PATH_ZLUA = os.environ.get('RANGER_ZLUA') or os.environ.get('ZLUA_SCRIPT')
+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')
Could you confirm me that "ranger_lua.py" is up to date and properly working on your own system ?
By the way. You have
......
# class z(ranger.api.commands.Command):
def execute (self):
import sys, os, time
.....
When youu press "?" for help, and then "c" for commands in ranger, a help page shows up for that :command.
You could add something for example,
# class z(ranger.api.commands.Command):
"""
:z <foo>
:z -i <foo>
You can also put `alias zb z -b` into `~/.config/ranger/rc.conf`.
Bla bla bla ... does this and that ....
Bla bla bla ... does this and that ....
Example usage ... foo ... bar
"""
def execute (self):
import sys, os, time
....
Thanks in advance.
for my occasion of ohmyzsh,
it's because i has use ohmyzsh with plugin https://github.com/skywind3000/z.lua/blob/master/z.lua.plugin.zsh,
which set
ZLUA_SCRIPT="${0:A:h}/z.lua"
https://github.com/skywind3000/z.lua/blob/f80e22498cf23cce7fb0f240900360f96193a5b6/z.lua.plugin.zsh#L3
since env varibles only take effect on current shell when set without export
https://stackoverflow.com/questions/19070615/python-os-getenv-and-os-environ-dont-see-environment-variables-of-my-bash-she
Method 1: So just replace this expression in ~/.oh-my-zsh/custom/plugins/z.lua/z.lua.plugin.zsh to
export ZLUA_SCRIPT="${0:A:h}/z.lua"
then everything is going to be all right.
Method 2 (Recommanded): If you doesn‘t use ohmyzsh, just add this to your bashrc(or zshrc) file manually.
export ZLUA_SCRIPT=<your_zlua_place>/z.lua"
or use
export RANGER_ZLUA="/path/to/z.lua"
https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-integrate-zlua-to-ranger-
Additionally:
1.How does ranger find z command?
Inside a plugin file of ~/.config/ranger/plugins/, if you define a class that inherits from ranger.api.commands.Command, ranger will automatically register it as a :command.
2. ranger z has not deal with no arguments situation,so won‘t show cd history
https://github.com/skywind3000/z.lua/blob/f80e22498cf23cce7fb0f240900360f96193a5b6/ranger_zlua.py#L48