summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-19 21:18:53 +0100
committerhut <hut@lavabit.com>2010-01-19 21:18:53 +0100
commitaf6658b377d145529e0b9304247ed3b9b6e40856 (patch)
tree2c283f89f634e9bfb841a10d8e2c49a137846e9d /ranger
parent33cb688a37d07e0cc8c4053be46ac3605235468e (diff)
downloadranger-af6658b377d145529e0b9304247ed3b9b6e40856.tar.gz
implemented #48: abbreviate commands
Diffstat (limited to 'ranger')
-rw-r--r--ranger/commands.py16
-rw-r--r--ranger/gui/widgets/console.py6
2 files changed, 19 insertions, 3 deletions
diff --git a/ranger/commands.py b/ranger/commands.py
index ea8e41f4..0cfe78b6 100644
--- a/ranger/commands.py
+++ b/ranger/commands.py
@@ -404,11 +404,23 @@ del varname
 del var
 
 def alias(**kw):
+	"""Create an alias for commands, eg: alias(quit=exit)"""
 	for key, value in kw.items():
 		by_name[key] = value
 
-alias(q=quit)
-alias(e=edit)
+def get_command(name, abbrev=True):
+	if abbrev:
+		lst = [cls for cmd, cls in by_name.items() if cmd.startswith(name)]
+		if len(lst) == 0:
+			raise KeyError
+		if len(lst) == 1:
+			return lst[0]
+		raise ValueError("Ambiguous command")
+	else:
+		try:
+			return by_name[name]
+		except KeyError:
+			return None
 
 def command_generator(start):
 	return (cmd + ' ' for cmd in by_name if cmd.startswith(start))
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 0da0480b..5c888da5 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -292,8 +292,12 @@ class CommandConsole(ConsoleWithTab):
 			return None
 
 		try:
-			return commands.by_name[command_name]
+			return commands.get_command(command_name)
 		except KeyError:
+			self.fm.notify("Invalid command! Press ? for help.", bad=True)
+			return None
+		except ValueError as e:
+			self.fm.notify(e)
 			return None
 	
 	def _get_tab(self):
6926e2594156219c1caaf4729c5d86498a5'>^
c09bf8d ^
29355bd ^

c09bf8d ^
4881857 ^
2e834e9 ^


9833610 ^
2e834e9 ^
c73d5cb ^
2e834e9 ^
b55bd70 ^
2e834e9 ^
39677ec ^
8a34fa5 ^
4250c26 ^
4d67199 ^
61a1910 ^

39677ec ^
8a34fa5 ^
650a1fb ^


8a34fa5 ^
9e8b325 ^
8a34fa5 ^
4d67199 ^
28a5219 ^



4d67199 ^
28a5219 ^
4d67199 ^
650a1fb ^
8a34fa5 ^
b55bd70 ^
9833610 ^
b55bd70 ^
7e597ae ^
9833610 ^
8a34fa5 ^
9833610 ^
b55bd70 ^
7e597ae ^

c73d5cb ^
4881857 ^
7739e6b ^


6458803 ^
8a34fa5 ^
4881857 ^
7739e6b ^

c73d5cb ^








6e72d78 ^

8a34fa5 ^
bf35794 ^
c09bf8d ^

6b25d06 ^
c09bf8d ^

937cabf ^
184471b ^
c09bf8d ^



6b25d06 ^
4688ad1 ^
c09bf8d ^

b355755 ^
c09bf8d ^
b55bd70 ^
78f4b51 ^
c09bf8d ^
78f4b51 ^
e995c1b ^
c09bf8d ^
e995c1b ^
78f4b51 ^
e369292 ^
c09bf8d ^
931e712 ^
7e597ae ^



78f4b51 ^
2dd5212 ^
7e597ae ^
78f4b51 ^
4688ad1 ^
c09bf8d ^
e6cbe9c ^
c09bf8d ^

adaa28a ^
184471b ^
fde45eb ^
adaa28a ^
7e597ae ^
b55bd70 ^
adaa28a ^

b55bd70 ^
7e597ae ^


78f4b51 ^
7e597ae ^
e6cbe9c ^
adaa28a ^

9e8b325 ^
ca65478 ^
9e8b325 ^
dc5d967 ^
9e8b325 ^
e81eb46 ^

8a34fa5 ^


8a34fa5 ^
ca65478 ^
d42c3ba ^
d7e1708 ^
8a34fa5 ^
8a8b795 ^
9e8b325 ^


8a34fa5 ^



8a34fa5 ^
9e8b325 ^
8a34fa5 ^


9e8b325 ^







8a34fa5 ^



9e8b325 ^


a308b75 ^
ac6e34e ^
9e8b325 ^

8a34fa5 ^
9e8b325 ^
8a34fa5 ^
adaa28a ^

ca65478 ^
adaa28a ^

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