Coder Social home page Coder Social logo

Integration with ranger about z.lua HOT 7 CLOSED

skywind3000 avatar skywind3000 commented on May 18, 2024
Integration with ranger

from z.lua.

Comments (7)

skywind3000 avatar skywind3000 commented on May 18, 2024 1

I mention it in the FAQ

from z.lua.

skywind3000 avatar skywind3000 commented on May 18, 2024

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.

from z.lua.

skywind3000 avatar skywind3000 commented on May 18, 2024

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

from z.lua.

skywind3000 avatar skywind3000 commented on May 18, 2024

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"

from z.lua.

rif avatar rif commented on May 18, 2024

Thank you very much!

from z.lua.

nedludd avatar nedludd commented on May 18, 2024

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?

from z.lua.

hengstchon avatar hengstchon commented on May 18, 2024

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.

from z.lua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.