about summary refs log tree commit diff stats
path: root/arc
Commit message (Expand)AuthorAgeFilesLines
* 4203Kartik K. Agaram2018-02-031-2/+5
* 4202Kartik K. Agaram2018-02-031-2/+2
* 4201Kartik K. Agaram2018-02-031-0/+4
* 3166Kartik K. Agaram2016-08-121-0/+7
* 1310Kartik K. Agaram2015-05-081-11/+11
* 1306Kartik K. Agaram2015-05-071-2/+0
* 1276 - make C++ version the defaultKartik K. Agaram2015-05-05301-0/+2010224
70aec44f ^
5645f266 ^
70aec44f ^
adcdb2d3 ^

70aec44f ^


adcdb2d3 ^



70aec44f ^
06aefcf5 ^

e65cebe4 ^
70aec44f ^


e65cebe4 ^
70aec44f ^


5645f266 ^
23236d0c ^
6a5d09b8 ^
70aec44f ^
d309f218 ^
6f43de0a ^

adcdb2d3 ^

70aec44f ^




3d566884 ^
e92fe17a ^






70aec44f ^

e92fe17a ^

70aec44f ^






e92fe17a ^
f1352f40 ^

2efce540 ^
f1352f40 ^
2efce540 ^
06aefcf5 ^

2efce540 ^
70aec44f ^


7ec262f8 ^
23236d0c ^

70aec44f ^
adcdb2d3 ^
b5493fe4 ^
3d566884 ^
70aec44f ^














a56455bd ^
70aec44f ^
0b8a9d79 ^
6874e0ea ^

70aec44f ^


6874e0ea ^
3d566884 ^
70aec44f ^
adcdb2d3 ^
70aec44f ^

adcdb2d3 ^
70aec44f ^




3d566884 ^
c1033553 ^
6f43de0a ^
c1033553 ^
5645f266 ^

5645f266 ^


70aec44f ^

5645f266 ^
0f337fce ^
2c9a912e ^
5645f266 ^
70aec44f ^

5645f266 ^



70aec44f ^

5645f266 ^
0f337fce ^

5645f266 ^
70aec44f ^

356592fa ^
b5393406 ^
ddf828fb ^
0c0b9489 ^
3d566884 ^
e6dfc442 ^
0c0b9489 ^
728fb838 ^
0c0b9489 ^
70aec44f ^
e6dfc442 ^

70aec44f ^











5715beca ^
e6dfc442 ^

70aec44f ^




728fb838 ^
e65cebe4 ^
70aec44f ^

728fb838 ^
7ec262f8 ^
70aec44f ^
e6dfc442 ^
0c0b9489 ^
ddf828fb ^
b5393406 ^

ddf828fb ^
70aec44f ^

ddf828fb ^
70aec44f ^



b5393406 ^

ddf828fb ^
b5393406 ^
4e01caf1 ^
b5393406 ^
06aefcf5 ^



5715beca ^
06aefcf5 ^
45076ed4 ^
5715beca ^
45076ed4 ^




06aefcf5 ^
06aefcf5 ^
75c3e884 ^







6f43de0a ^
06aefcf5 ^

6f43de0a ^

ddf828fb ^
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




























                                                                  
 
                                      
                                                                 
 
                                                     
 
                                             

                                                   


                                                         



                                                                
                                 

                                  
 


                                                 
 


                             
 
                                             
 
                                         
 

                                         

                                                                              




                                                                 
 






                                

                                                      

                                                                                 






                                                                                  
 

                                  
                      
                                                                                   
 

                                    
                            


                                                                
 

                                                                          
                                                             
                                                     
 
                                                             














                                               
                                           
                                                    
 

                                         


                                                                  
 
                          
                                      
                                  

                                       
                                                      




                                                       
 
                      
                                         
                       

                                                       


                                                                        

                                                                                  
 
                          
                         
 

                                                                                



                                                                     

                                                                                      
 

                                  
 

                                                             
 
                                                        
 
                                    
 
 
                                              
                                                                 
 
                                                     

                  











                                                           
                                                                      

                          




                                                 
 
                   

                                          
 
                                             
                                 
 
                                    
 

                                                             
 

                                                     
 



                                                   

                                    
 
                                     
                                            
                                                               



                                            
                                                     
                                                        
 
                                                                        




                                                     
 
                                                   







                                                                       
 

                                                   

                                                                         
                                    
"""
Syntax for binding keys: bind(*keys, fnc)

keys are one or more key-combinations which are either:
* a string
* an integer which represents an ascii code
* a tuple of integers

fnc is a function which is called with the CommandArgument object.

The CommandArgument object has these methods:
cmdarg.fm: the file manager instance
cmdarg.wdg: the widget or ui instance
cmdarg.n: the number typed before the key combination (if allowed)
cmdarg.keys: the string representation of the used key combination
cmdarg.keybuffer: the keybuffer instance

Check ranger.keyapi for more information
"""

from ranger.keyapi import *

def system_functions(command_list):
	"""Each commandlist should have those."""
	bind, hint = make_abbreviations(command_list)

	bind(KEY_RESIZE, fm.resize())
	bind(KEY_MOUSE, fm.handle_mouse())
	bind(ctrl('L'), fm.redraw_window())

def initialize_commands(command_list):
	"""Initialize the commands for the main user interface"""

	bind, hint = make_abbreviations(command_list)

	bind('l', KEY_RIGHT, fm.move_right())
	bind(KEY_END, fm.move_pointer(absolute=-1))
	bind(KEY_HOME, fm.move_pointer(absolute=0))
	bind(KEY_ENTER, ctrl('j'), fm.move_right(mode=1))
	bind('H', fm.history_go(-1))
	bind('L', fm.history_go(1))
	bind('J', ctrl('d'), fm.move_pointer_by_pages(0.5))
	bind('K', ctrl('u'), fm.move_pointer_by_pages(-0.5))
	bind(KEY_NPAGE, ctrl('f'), fm.move_pointer_by_pages(1))
	bind(KEY_PPAGE, ctrl('b'), fm.move_pointer_by_pages(-1))
	bind('E', fm.edit_file())
	bind('b', fm.tag_toggle())
	bind('B', fm.tag_remove())

	bind(' ', fm.mark(toggle=True))
	bind('v', fm.mark(all=True, toggle=True))
	bind('V', fm.mark(all=True, val=False))

	bind('yy', fm.copy())
	bind('dd', fm.cut())
	bind('p', fm.paste())

	bind('s', fm.execute_command('bash'))

	bind(TAB, fm.search(order='tag'))

	bind(ctrl('p'), fm.display_log())

	hint('t', "show_//h//idden //p//review_files //d//irectories_first " \
			"//a//uto_load_preview //c//ollapse_preview")
	bind('th', fm.toggle_boolean_option('show_hidden'))
	bind('tp', fm.toggle_boolean_option('preview_files'))
	bind('td', fm.toggle_boolean_option('directories_first'))
	bind('ta', fm.toggle_boolean_option('auto_load_preview'))
	bind('tc', fm.toggle_boolean_option('collapse_preview'))

	sort_dict = {
		's': 'size',
		'b': 'basename',
		'n': 'basename',
		'm': 'mtime',
		't': 'type',
	}

	# reverse if any of the two letters is capital
	for key, val in sort_dict.items():
		for key, is_upper in ((key.lower(), False), (key.upper(), True)):
			bind('o' + key, fm.sort(func=val, reverse=is_upper))
			bind('O' + key, fm.sort(func=val, reverse=True))

	bind('or', 'Or', 'oR', 'OR', lambda arg: \
			arg.fm.sort(reverse=not arg.fm.settings.reverse))

	hint('o', 'O', "//s//ize //b//ase//n//ame //m//time //t//ype //r//everse")

	def edit_name(arg):
		cf = arg.fm.env.cf
		if cf:
			arg.fm.open_console(cmode.COMMAND, 'rename ' + cf.basename)

	bind('i', fm.display_file())

	bind('A', edit_name)
	bind('cw', fm.open_console(cmode.COMMAND, 'rename '))
	bind('cd', fm.open_console(cmode.COMMAND, 'cd '))
	bind('f', fm.open_console(cmode.COMMAND_QUICK, 'find '))

	bind('term', fm.execute_command('x-terminal-emulator', flags='d'))
	bind('du', fm.execute_command('du --max-depth=1 -h | less'))
	bind('tf', fm.open_console(cmode.COMMAND, 'filter '))
	hint('d', 'd//u// (disk usage) d//d// (cut)')

	# key combinations which change the current directory
	bind('gh', fm.enter_dir('~'))
	bind('ge', fm.enter_dir('etc'))
	bind('gu', fm.enter_dir('/usr'))
	bind('gr', fm.enter_dir('/'))
	bind('gm', fm.enter_dir('/media'))
	bind('gn', fm.enter_dir('/mnt'))
	bind('gt', fm.enter_dir('~/.trash'))
	bind('gs', fm.enter_dir('/srv'))
	bind('gR', fm.enter_dir(RANGERDIR))

	bind('n', fm.search())
	bind('N', fm.search(forward=False))

	bind('cc', fm.search(order='ctime'))
	bind('cm', fm.search(order='mimetype'))
	bind('cs', fm.search(order='size'))
	hint('c', '//c//time //m//imetype //s//ize')

	# bookmarks
	for key in ALLOWED_BOOKMARK_KEYS:
		bind("`" + key, "'" + key, fm.enter_bookmark(key))
		bind("m" + key, fm.set_bookmark(key))
		bind("um" + key, fm.unset_bookmark(key))

	# system functions
	system_functions(command_list)
	bind('Q', 'ZZ', fm.exit())
	bind(ctrl('R'), fm.reset())
	bind(ctrl('C'), fm.interrupt())
	bind(':', ';', fm.open_console(cmode.COMMAND))
	bind('>', fm.open_console(cmode.COMMAND_QUICK))
	bind('/', fm.open_console(cmode.SEARCH))
	bind('?', fm.open_console(cmode.SEARCH))
	bind('!', fm.open_console(cmode.OPEN))
	bind('r', fm.open_console(cmode.OPEN_QUICK))

	def test(arg):
		arg.fm.notify(str(arg.n))
	bind('x', test)

	# definitions which require their own function:
	def ggG(default):
		# moves to an absolute point, or to a predefined default
		# if no number is specified.
		return lambda arg: \
				arg.fm.move_pointer(absolute=(arg.n or default)-1)

	bind('gg', ggG(1))
	bind('G', ggG(0))

	bind('%', lambda arg: \
			arg.fm.move_pointer_by_percentage(absolute=arg.n or 50))

	def jk(direction):
		# moves up or down by the specified number or one, in
		# the predefined direction
		return lambda arg: \
				arg.fm.move_pointer(relative=(arg.n or 1) * direction)

	bind('j', KEY_DOWN, jk(1))
	bind('k', KEY_UP, jk(-1))

	bind('h', KEY_LEFT, KEY_BACKSPACE, DEL, lambda arg: \
			arg.fm.move_left(arg.n or 1))

	bind('w', lambda arg: arg.fm.ui.open_taskview())

	command_list.rebuild_paths()


def initialize_console_commands(command_list):
	"""Initialize the commands for the console widget only"""

	bind, hint = make_abbreviations(command_list)

	# movement
	bind(KEY_UP, wdg.history_move(-1))
	bind(KEY_DOWN, wdg.history_move(1))
	bind(ctrl('b'), KEY_LEFT, wdg.move(relative = -1))
	bind(ctrl('f'), KEY_RIGHT, wdg.move(relative = 1))
	bind(ctrl('a'), KEY_HOME, wdg.move(absolute = 0))
	bind(ctrl('e'), KEY_END, wdg.move(absolute = -1))
	bind(ctrl('d'), KEY_DC, wdg.delete(0))
	bind(ctrl('h'), KEY_BACKSPACE, DEL, wdg.delete(-1))
	bind(ctrl('w'), wdg.delete_word())
	bind(ctrl('k'), wdg.delete_rest(1))
	bind(ctrl('u'), wdg.delete_rest(-1))
	bind(ctrl('y'), wdg.paste())
	bind(KEY_F1, lambda arg: arg.fm.display_command_help(arg.wdg))

	# system functions
	system_functions(command_list)
	bind(ctrl('c'), ESC, wdg.close())
	bind(ctrl('j'), KEY_ENTER, wdg.execute())
	bind(TAB, wdg.tab())
	bind(KEY_BTAB, wdg.tab(-1))

	# type keys
	def type_key(arg):
		arg.wdg.type_key(arg.keys)

	for i in range(ord(' '), ord('~')+1):
		bind(i, type_key)

	command_list.rebuild_paths()

def initialize_taskview_commands(command_list):
	"""Initialize the commands for the TaskView widget"""

	system_functions(command_list)
	bind, hint = make_abbreviations(command_list)

	bind('j', KEY_DOWN, nwrap.move(relative=1))
	bind('k', KEY_UP, nwrap.move(relative=-1))
	bind('gg', nwrap.move(absolute=0))
	bind('G', nwrap.move(absolute=-1))
	bind('K', wdg.task_move(0))
	bind('J', wdg.task_move(-1))

	bind('dd', wdg.task_remove())
	bind('w', ESC, ctrl('d'), ctrl('c'),
			lambda arg: arg.fm.ui.close_taskview())

	command_list.rebuild_paths()

def initialize_pager_commands(command_list):
	bind, hint = make_abbreviations(command_list)
	initialize_embedded_pager_commands(command_list)

	bind('q', 'i', ESC, KEY_F1, lambda arg: arg.fm.ui.close_pager())
	command_list.rebuild_paths()

def initialize_embedded_pager_commands(command_list):
	system_functions(command_list)
	bind, hint = make_abbreviations(command_list)

	bind('j', KEY_DOWN, nwrap.move(relative=1))
	bind('k', KEY_UP, nwrap.move(relative=-1))
	bind('gg', KEY_HOME, nwrap.move(absolute=0))
	bind('G', KEY_END, nwrap.move(absolute=-1))
	bind('J', ctrl('d'), nwrap.move(relative=0.5, pages=True))
	bind('K', ctrl('u'), nwrap.move(relative=-0.5, pages=True))
	bind(KEY_NPAGE, ctrl('f'), nwrap.move(relative=1, pages=True))
	bind(KEY_PPAGE, ctrl('b'), nwrap.move(relative=-1, pages=True))
	bind('E', fm.edit_file())

	bind('h', wdg.move_horizontal(relative=-4))
	bind('l', wdg.move_horizontal(relative=4))

	bind('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager())
	command_list.rebuild_paths()