Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
838 B

4 years ago
  1. import ranger.api
  2. from ranger.api.commands import *
  3. from os import getenv
  4. import re
  5. class z(Command):
  6. """:z
  7. Uses .z file to set the current directory.
  8. """
  9. def execute(self):
  10. # location of .z file
  11. z_loc = getenv("_Z_DATA") or getenv("HOME")+"/.z"
  12. with open(z_loc,"r") as fobj:
  13. flists = fobj.readlines()
  14. # user given directory
  15. req = re.compile(".*".join(self.args[1:]),re.IGNORECASE)
  16. directories = []
  17. for i in flists:
  18. if req.search(i):
  19. directories.append(i.split("|")[0])
  20. try:
  21. # smallest(length) directory will be the directory required
  22. self.fm.execute_console("cd " + min(directories,key=lambda x: len(x)))
  23. except Exception as e:
  24. raise Exception("Directory not found")