Add ranger plugin

This commit is contained in:
Ajeet D'Souza 2020-03-14 11:54:37 +05:30
parent eb21727868
commit f31fcf2d1f
2 changed files with 149 additions and 0 deletions

111
.gitignore vendored
View File

@ -10,3 +10,114 @@
**/*.rs.bk
# End of https://www.gitignore.io/api/rust
# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# End of https://www.gitignore.io/api/python

38
ranger_zoxide.py Normal file
View File

@ -0,0 +1,38 @@
import ranger.api
import ranger.core.fm
import ranger.ext.signals
import subprocess
hook_init_old = ranger.api.hook_init
def hook_init(fm: ranger.core.fm.FM):
def zoxide_add(signal: ranger.ext.signals.Signal):
path = signal.new.path
process = subprocess.Popen(["zoxide", "add", path])
process.wait()
fm.signal_bind("cd", zoxide_add)
return hook_init_old(fm)
ranger.api.hook_init = hook_init
class z(ranger.api.commands.Command):
def execute(self):
try:
output = subprocess.check_output(["zoxide", "query"] + self.args[1:])
output = output.decode("utf-8")
query_prefix = "query:"
if output.startswith(query_prefix):
directory = output[len(query_prefix) :].strip()
self.fm.cd(directory)
self.fm.notify(directory)
else:
self.fm.notify("no match found", bad=True)
except Exception as e:
self.fm.notify(e, bad=True)