My dotfiles for my Linux rice managed with stow and make
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.

commands.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # This is a sample commands.py. You can add your own commands here.
  2. #
  3. # Please refer to commands_full.py for all the default commands and a complete
  4. # documentation. Do NOT add them all here, or you may end up with defunct
  5. # commands when upgrading ranger.
  6. # You always need to import ranger.api.commands here to get the Command class:
  7. from ranger.api.commands import *
  8. # A simple command for demonstration purposes follows.
  9. # -----------------------------------------------------------------------------
  10. # You can import any python module as needed.
  11. import os
  12. # Any class that is a subclass of "Command" will be integrated into ranger as a
  13. # command. Try typing ":my_edit<ENTER>" in ranger!
  14. class my_edit(Command):
  15. # The so-called doc-string of the class will be visible in the built-in
  16. # help that is accessible by typing "?c" inside ranger.
  17. """:my_edit <filename>
  18. A sample command for demonstration purposes that opens a file in an editor.
  19. """
  20. # The execute method is called when you run this command in ranger.
  21. def execute(self):
  22. # self.arg(1) is the first (space-separated) argument to the function.
  23. # This way you can write ":my_edit somefilename<ENTER>".
  24. if self.arg(1):
  25. # self.rest(1) contains self.arg(1) and everything that follows
  26. target_filename = self.rest(1)
  27. else:
  28. # self.fm is a ranger.core.filemanager.FileManager object and gives
  29. # you access to internals of ranger.
  30. # self.fm.thisfile is a ranger.container.file.File object and is a
  31. # reference to the currently selected file.
  32. target_filename = self.fm.thisfile.path
  33. # This is a generic function to print text in ranger.
  34. self.fm.notify("Let's edit the file " + target_filename + "!")
  35. # Using bad=True in fm.notify allows you to print error messages:
  36. if not os.path.exists(target_filename):
  37. self.fm.notify("The given file does not exist!", bad=True)
  38. return
  39. # This executes a function from ranger.core.acitons, a module with a
  40. # variety of subroutines that can help you construct commands.
  41. # Check out the source, or run "pydoc ranger.core.actions" for a list.
  42. self.fm.edit_file(target_filename)
  43. # The tab method is called when you press tab, and should return a list of
  44. # suggestions that the user will tab through.
  45. # tabnum is 1 for <TAB> and -1 for <S-TAB> by default
  46. def tab(self, tabnum):
  47. # This is a generic tab-completion function that iterates through the
  48. # content of the current directory.
  49. return self._tab_directory_content()