summaryrefslogtreecommitdiffstats
path: root/.config/ranger/ranger_new/commands.py
diff options
context:
space:
mode:
authorYigit Sever2019-03-17 23:09:49 +0300
committerYigit Sever2019-03-17 23:18:28 +0300
commitea211500227aa58f5e495777743c5d391cbc3110 (patch)
treeafa2b455f9fea40b45dbf8a742c0d0d498024edb /.config/ranger/ranger_new/commands.py
downloaddotfiles-ea211500227aa58f5e495777743c5d391cbc3110.tar.gz
dotfiles-ea211500227aa58f5e495777743c5d391cbc3110.tar.bz2
dotfiles-ea211500227aa58f5e495777743c5d391cbc3110.zip
Initial commit
Diffstat (limited to '.config/ranger/ranger_new/commands.py')
-rw-r--r--.config/ranger/ranger_new/commands.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/.config/ranger/ranger_new/commands.py b/.config/ranger/ranger_new/commands.py
new file mode 100644
index 0000000..97b7909
--- /dev/null
+++ b/.config/ranger/ranger_new/commands.py
@@ -0,0 +1,62 @@
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
7# A simple command for demonstration purposes follows.
8# -----------------------------------------------------------------------------
9
10from __future__ import (absolute_import, division, print_function)
11
12# You can import any python module as needed.
13import os
14
15# You always need to import ranger.api.commands here to get the Command class:
16from ranger.api.commands import Command
17
18
19# Any class that is a subclass of "Command" will be integrated into ranger as a
20# command. Try typing ":my_edit<ENTER>" in ranger!
21class my_edit(Command):
22 # The so-called doc-string of the class will be visible in the built-in
23 # help that is accessible by typing "?c" inside ranger.
24 """:my_edit <filename>
25
26 A sample command for demonstration purposes that opens a file in an editor.
27 """
28
29 # The execute method is called when you run this command in ranger.
30 def execute(self):
31 # self.arg(1) is the first (space-separated) argument to the function.
32 # This way you can write ":my_edit somefilename<ENTER>".
33 if self.arg(1):
34 # self.rest(1) contains self.arg(1) and everything that follows
35 target_filename = self.rest(1)
36 else:
37 # self.fm is a ranger.core.filemanager.FileManager object and gives
38 # you access to internals of ranger.
39 # self.fm.thisfile is a ranger.container.file.File object and is a
40 # reference to the currently selected file.
41 target_filename = self.fm.thisfile.path
42
43 # This is a generic function to print text in ranger.
44 self.fm.notify("Let's edit the file " + target_filename + "!")
45
46 # Using bad=True in fm.notify allows you to print error messages:
47 if not os.path.exists(target_filename):
48 self.fm.notify("The given file does not exist!", bad=True)
49 return
50
51 # This executes a function from ranger.core.acitons, a module with a
52 # variety of subroutines that can help you construct commands.
53 # Check out the source, or run "pydoc ranger.core.actions" for a list.
54 self.fm.edit_file(target_filename)
55
56 # The tab method is called when you press tab, and should return a list of
57 # suggestions that the user will tab through.
58 # tabnum is 1 for <TAB> and -1 for <S-TAB> by default
59 def tab(self, tabnum):
60 # This is a generic tab-completion function that iterates through the
61 # content of the current directory.
62 return self._tab_directory_content()