mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-11-10 15:20:55 +00:00
Update ranger plugin
This commit is contained in:
parent
f4cf811155
commit
aab37dfab9
@ -1,3 +1,4 @@
|
||||
import os.path
|
||||
import ranger.api
|
||||
import ranger.core.fm
|
||||
import ranger.ext.signals
|
||||
@ -22,15 +23,24 @@ 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")
|
||||
zoxide = subprocess.Popen(
|
||||
["zoxide", "query"] + self.args[1:],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = zoxide.communicate()
|
||||
|
||||
if zoxide.returncode == 0:
|
||||
output = stdout.decode("utf-8").strip()
|
||||
if output:
|
||||
self.fm.notify(output)
|
||||
if os.path.isdir(output):
|
||||
self.fm.cd(output)
|
||||
else:
|
||||
self.fm.notify("zoxide: unexpected exit", bad=True)
|
||||
else:
|
||||
output = stderr.decode("utf-8").strip() or "zoxide: unknown error"
|
||||
self.fm.notify(output, bad=True)
|
||||
|
||||
directory = output.strip()
|
||||
self.fm.cd(directory)
|
||||
self.fm.notify(directory)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if e.returncode == 1:
|
||||
pass
|
||||
except Exception as e:
|
||||
self.fm.notify(e, bad=True)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user