summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-11 19:30:26 +0200
committerhut <hut@lavabit.com>2011-10-11 19:30:26 +0200
commitde28d6df4179500c9048f177dcc1f94214fdad00 (patch)
tree59c3bb39967a751fc30462b0ac663e3cb58f2132
parent96912a0ca559871ae3420e96c12781dd2713b78d (diff)
downloadranger-de28d6df4179500c9048f177dcc1f94214fdad00.tar.gz
defaults.commands: replaced introduction
-rw-r--r--ranger/defaults/commands.py125
1 files changed, 73 insertions, 52 deletions
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index c16deeda..613d1bba 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -1,59 +1,80 @@
+# -*- coding: utf-8 -*-
 # Copyright (C) 2009, 2010, 2011  Roman Zimbelmann <romanz@lavabit.com>
+# This configuration file is licensed under the same terms as ranger.
+# ===================================================================
+# This file contains ranger's commands.
+# It's all in python; lines beginning with # are comments.
 #
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# Note that additional commands are automatically generated from the methods
+# of the class ranger.core.actions.Actions.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# You can customize commands in the file ~/.config/ranger/commands.py.
+# It has the same syntax as this file.  In fact, you can just copy this
+# file there with `ranger --copy-config=commands' and make your modifications.
+# But make sure you update your configs when you update ranger.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-'''
-This is the default file for command definitions.
-
-Each command is a subclass of `Command'.  Several methods are defined
-to interface with the console:
-	execute: call this method when the command is executed.
-	cancel: call this method when closing the console without executing.
-	tab: call this method when tab is pressed.
-	quick: call this method after each keypress.
-
-The return values for tab() can be either:
-	None: There is no tab completion
-	A string: Change the console to this string
-	A list/tuple/generator: cycle through every item in it
-The return value for quick() can be:
-	False: Nothing happens
-	True: Execute the command afterwards
-The return value for execute() doesn't matter.
-
-If you want to add custom commands, you can create a file
-~/.config/ranger/commands.py, add the line:
-	from ranger.api.commands import *
-
-and write some command definitions, for example:
-
-	class tabnew(Command):
-		def execute(self):
-			self.fm.tab_new()
-
-	class tabgo(Command):
-		"""
-		:tabgo <n>
-
-		Go to the nth tab.
-		"""
-		def execute(self):
-			num = self.line.split()[1]
-			self.fm.tab_open(int(num))
-
-For a list of all actions, check /ranger/core/actions.py.
-'''
+# ===================================================================
+# Every class defined here which is a subclass of `Command' will be used as a
+# command in ranger.  Several methods are defined to interface with ranger:
+#   execute(): called when the command is executed.
+#   cancel():  called when closing the console.
+#   tab():     called when <TAB> is pressed.
+#   quick():   called after each keypress.
+#
+# The return values for tab() can be either:
+#   None: There is no tab completion
+#   A string: Change the console to this string
+#   A list/tuple/generator: cycle through every item in it
+#
+# The return value for quick() can be:
+#   False: Nothing happens
+#   True: Execute the command afterwards
+#
+# The return value for execute() and cancel() doesn't matter.
+#
+# ===================================================================
+# Commands have certain attributes and methods that facilitate parsing of
+# the arguments:
+#
+# self.line: The whole line that was written in the console.
+# self.args: A list of all (space-separated) arguments to the command.
+# self.quantifier: If this command was mapped to the key "X" and
+#      the user pressed 6X, self.quantifier will be 6.
+# self.arg(n): The n-th argument, or an empty string if it doesn't exist.
+# self.rest(n): The n-th argument plus everything that followed.  For example,
+#      If the command was "search foo bar a b c", rest(2) will be "bar a b c"
+# self.start(n): The n-th argument and anything before it.  For example,
+#      If the command was "search foo bar a b c", rest(2) will be "bar a b c"
+#
+# ===================================================================
+# And this is a little reference for common ranger functions and objects:
+#
+# self.fm: A reference to the "fm" object which contains most information
+#      about ranger.
+# self.fm.notify(string): Print the given string on the screen.
+# self.fm.notify(string, bad=True): Print the given string in RED.
+# self.fm.reload_cwd(): Reload the current working directory.
+# self.fm.env.cwd: The current working directory. (A File object.)
+# self.fm.env.cf: The current file. (A File object too.)
+# self.fm.env.cwd.get_selection(): A list of all selected files.
+# self.fm.execute_console(string): Execute the string as a ranger command.
+# self.fm.open_console(string): Open the console with the given string
+#      already typed in for you.
+# self.fm.move(direction): Moves the cursor in the given direction, which
+#      can be something like down=3, up=5, right=1, left=1, to=6, ...
+#
+# File objects (for example self.fm.env.cf) have these useful attributes and
+# methods:
+#
+# cf.path: The path to the file.
+# cf.basename: The base name only.
+# cf.load_content(): Force a loading of the directories content (which
+#      obviously works with directories only)
+# cf.is_directory: True/False depending on whether it's a directory.
+#
+# For advanced commands it is unavoidable to dive a bit into the source code
+# of ranger.
+# ===================================================================
 
 from ranger.api.commands import *
 from ranger.ext.get_executables import get_executables
> ^
d4030624 ^

5a702544 ^















































863f52e8 ^

b24eb476 ^
863f52e8 ^




ac0e9db5 ^
b24eb476 ^
c58e2368 ^
23679883 ^
5b5ef63b ^

6573fe1f ^
5b5ef63b ^






df37108f ^
5b5ef63b ^



5b5ef63b ^
1a33d221 ^
5b5ef63b ^


c1a46edf ^
5b5ef63b ^








5b5ef63b ^





c58e2368 ^
5a6645bc ^
6573fe1f ^
5a6645bc ^



74262581 ^

5a6645bc ^






f603d9f2 ^
5a6645bc ^





f603d9f2 ^
5a6645bc ^



795f5244 ^







91abd257 ^




795f5244 ^
87374384 ^


795f5244 ^
f3760b0f ^







c58e2368 ^
08cf048f ^


c58e2368 ^
08cf048f ^


ac0e9db5 ^
b39ceb27 ^
385ff136 ^
d98e1a18 ^
385ff136 ^
b39ceb27 ^





385ff136 ^
b39ceb27 ^
10f415a6 ^
385ff136 ^
b39ceb27 ^
fd72ec75 ^
514f0e34 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264