mirror of
https://github.com/jchook/ranger-zoxide.git
synced 2026-05-13 16:38:41 +08:00
Initial commit
This commit is contained in:
commit
72d17d34c8
3 changed files with 86 additions and 0 deletions
18
LICENSE.md
Normal file
18
LICENSE.md
Normal file
|
|
@ -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.
|
||||
41
README.md
Normal file
41
README.md
Normal file
|
|
@ -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 <partial-name>
|
||||
```
|
||||
|
||||
## 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
|
||||
27
zoxide.py
Normal file
27
zoxide.py
Normal file
|
|
@ -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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue