summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/fm.py46
-rw-r--r--ranger/core/helper.py5
-rw-r--r--ranger/core/main.py6
3 files changed, 30 insertions, 27 deletions
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index f51a7834..314127ca 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -122,35 +122,35 @@ class FM(Actions, SignalDispatcher):
 			self.input_blocked = False
 		return self.input_blocked
 
-	def _copy_config_files(self):
+	def copy_config_files(self, which):
 		if ranger.arg.clean:
+			sys.stderr.write("refusing to copy config files in clean mode\n")
 			return
 		import shutil
-		files = {'data/apps.py': 'apps.py',
-				'data/rc.conf': 'rc.conf',
-				'data/commands.py': 'commands.py',
-				'data/options.py': 'options.py',
-				'data/scope.sh': 'scope.sh'}
-		copied_any = False
-		for fname, target in files.items():
-			if not os.path.exists(self.confpath(target)):
-				if not copied_any:
-					copied_any = True
-					try:
-						os.makedirs(self.confpath())
-					except:
-						pass
-				sys.stderr.write("creating: %s\n" % self.confpath(target))
+		def copy(_from, to):
+			if os.path.exists(self.confpath(to)):
+				sys.stderr.write("already exists: %s\n" % self.confpath(to))
+			else:
+				sys.stderr.write("creating: %s\n" % self.confpath(to))
 				try:
-					shutil.copy(self.relpath(fname), self.confpath(target))
+					shutil.copy(self.relpath(_from), self.confpath(to))
 				except Exception as e:
 					sys.stderr.write("  ERROR: %s\n" % str(e))
-				if target == 'scope.sh':
-					os.chmod(self.confpath('scope.sh'), os.stat(
-						self.confpath('scope.sh')).st_mode | stat.S_IXUSR)
-		if copied_any:
-			sys.stderr.write("Use --dont-copy-config to disable "
-					"automatic copying of example config files.\n")
+		if which == 'apps' or which == 'all':
+			copy('defaults/apps.py', 'apps.py')
+		if which == 'commands' or which == 'all':
+			copy('defaults/commands.py', 'commands.py')
+		if which == 'rc' or which == 'all':
+			copy('defaults/rc.conf', 'rc.conf')
+		if which == 'options' or which == 'all':
+			copy('defaults/options.py', 'options.py')
+		if which == 'scope' or which == 'all':
+			copy('data/scope.sh', 'scope.sh')
+			os.chmod(self.confpath('scope.sh'),
+				os.stat(self.confpath('scope.sh')).st_mode | stat.S_IXUSR)
+		if which not in \
+				('all', 'apps', 'scope', 'commands', 'rc', 'options'):
+			sys.stderr.write("Unknown config file `%s'\n" % which)
 
 	def confpath(self, *paths):
 		"""returns the path relative to rangers configuration directory"""
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index e95c0752..a4c56712 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -38,8 +38,9 @@ def parse_arguments():
 			help="activate debug mode")
 	parser.add_option('-c', '--clean', action='store_true',
 			help="don't touch/require any config files. ")
-	parser.add_option('--dont-copy-config', action='store_true',
-			help="dont copy the sample configs if they're not found")
+	parser.add_option('--copy-config', type='string', metavar='which',
+			help="copy the default configs to the local config directory. "
+			"Possible values: all, apps, commands, keys, options, scope")
 	parser.add_option('--fail-unless-cd', action='store_true',
 			help="experimental: return the exit code 1 if ranger is" \
 					"used to run a file (with `ranger filename`)")
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 5fe93d61..abb1d469 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -42,6 +42,10 @@ def main():
 		os.environ['SHELL'] = 'bash'
 
 	ranger.arg = arg = parse_arguments()
+	if arg.copy_config is not None:
+		fm = FM()
+		fm.copy_config_files(arg.copy_config)
+		return 1 if arg.fail_unless_cd else 0
 
 	SettingsAware._setup(clean=arg.clean)
 
@@ -68,8 +72,6 @@ def main():
 		# Initialize objects
 		from ranger.core.environment import Environment
 		fm = FM()
-		if not arg.dont_copy_config and not arg.clean:
-			fm._copy_config_files()
 		FileManagerAware.fm = fm
 		EnvironmentAware.env = Environment(target)
 		fm.tabs = dict((n+1, os.path.abspath(path)) for n, path \
p;id=535fe9ac96dba0950efd1bfe6788801f6197971f'>535fe9ac ^
3350c34a ^
535fe9ac ^








3350c34a ^
535fe9ac ^











4254408a ^
535fe9ac ^
3350c34a ^
535fe9ac ^













7b109ab6 ^



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