From 72d17d34c82bfddf25411c0548051de08d14e0a4 Mon Sep 17 00:00:00 2001 From: Wes Roberts Date: Sun, 1 Nov 2020 18:44:43 -0500 Subject: [PATCH] Initial commit --- LICENSE.md | 18 ++++++++++++++++++ README.md | 41 +++++++++++++++++++++++++++++++++++++++++ zoxide.py | 27 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 zoxide.py diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..cf73c27 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,18 @@ +Copyright 2020 Wesley Roberts + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..079d979 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# ranger-zoxide + +A [`zoxide`](https://github.com/ajeetdsouza/zoxide) (aka `z`) plugin for +[`ranger`](https://github.com/ranger/ranger). + +Easily jump between commonly visited directories by running this in ranger: + +``` +:z +``` + +## Features + +- Very simple & fast thanks to zoxide +- Supports tab completion + +## Install + +Simply copy `zoxide.py` to your `~/.config/ranger/plugins` folder. For example: + +``` +mkdir -p ~/.config/ranger/plugins +wget -O ~/.config/ranger/plugins/zoxide.py https://raw.githubusercontent.com/jchook/ranger-zoxide/master/zoxide.py +``` + +## Keyboard Shortcut + +You may wish to add a keyboard shortcut to quickly `z` between common directories. +Simply add a binding to your `~/.config/ranger/rc.conf` file: + +``` +map cz console z%space +``` + +## More Info + +This plugin was inspired by [ranger-zjumper](https://github.com/ask1234560/ranger-zjumper). + +## License + +MIT diff --git a/zoxide.py b/zoxide.py new file mode 100644 index 0000000..0181d20 --- /dev/null +++ b/zoxide.py @@ -0,0 +1,27 @@ +from ranger.api.commands import Command +from subprocess import check_output, CalledProcessError + +class z(Command): + """ + :z + + Jump around with zoxide (z) + """ + def execute(self): + results = self.query(self.args[1]) + self.fm.cd(results[0]) + + def query(self, req): + try: + return check_output(['zoxide', 'query', req]).splitlines() + except CalledProcessError as e: + if e.returncode == 1: + self.fm.notify("No matches found", bad=True) + else: + self.fm.notify("zoxide exited with status: %i".format(e.returncode), bad=True) + except Exception as e: + self.fm.notify("zoxide not found", bad=True) + + def tab(self, tabnum): + results = self.query(self.args[1]) + return ["z {}".format(x) for x in results]