Closed rif closed 5 years ago
Sorry for reply late, I was studying writing plugins for ranger, because I seldom use it.
here is the first script for path tracking:
import ranger.api
import subprocess
old_hook_init = ranger.api.hook_init
PATH_LUA='/usr/bin/lua'
PATH_ZLUA='/home/skywind/.local/etc/z.lua'
def hook_init(fm):
def update_zlua(signal):
subprocess.Popen([PATH_LUA, PATH_ZLUA, "--add", signal.new.path])
fm.signal_bind('cd', update_zlua)
return old_hook_init(fm)
ranger.api.hook_init = hook_init
Remember to change PATH_LUA
and PATH_ZLUA
, and I still need time to implement a z
command in ranger.
OK, finished, ranger_zlua.py
, copy it to ~/.config/ranger/plugins
:
import ranger.api
import subprocess
old_hook_init = ranger.api.hook_init
PATH_LUA='/usr/bin/lua'
PATH_ZLUA='/home/skywind/.local/etc/z.lua'
def hook_init(fm):
def update_zlua(signal):
subprocess.Popen([PATH_LUA, PATH_ZLUA, "--add", signal.new.path])
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):
args = self.args[1:]
if args:
directory = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
directory = directory.decode("utf-8", "ignore")
directory = directory.rstrip('\n')
self.fm.cd(directory)
return True
I submitted a ranger_zlua.py
file here:
https://github.com/skywind3000/z.lua/blob/master/ranger_zlua.py
You can use it in your ~/.config/ranger/plugins
directly, remember to set environment variable:
export RANGER_ZLUA="/path/to/z.lua"
I mention it in the FAQ
Thank you very much!
Can you explain more how this works? I followed the instructions but don't see a z
command in ranger that overrides the existing one. Can you add a little explanation?
Can you explain more how this works? I followed the instructions but don't see a
z
command in ranger that overrides the existing one. Can you add a little explanation?
It's just like ranger-autojump
.
Using :z
in ranger to invoke the z
command.
What would be the equivalent command for z.lua to integrate with ranger directory switch?
https://github.com/ranger/ranger/wiki/Integration-with-other-programs#fasd
Great tool, by the way!
Thanks, -rif