summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-12 18:05:41 +0100
committerhut <hut@lavabit.com>2010-03-12 18:05:41 +0100
commit69394f44516db77b126f997ca704bd77a3d76852 (patch)
tree715b5487c21383c8c152f35282b95e56a7797924
parent5ebb8ef628563f33abf6b72b47afe19b8efc0694 (diff)
downloadranger-69394f44516db77b126f997ca704bd77a3d76852.tar.gz
commands.delete: ask for confirmation (in some cases)
-rw-r--r--ranger/defaults/commands.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index 834e358b..c9b3a878 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -255,13 +255,36 @@ class delete(Command):
 	"Selection" is defined as all the "marked files" (by default, you
 	can mark files with space or v). If there are no marked files,
 	use the "current file" (where the cursor is)
+
+	When attempting to delete non-empty directories or multiple
+	marked files, it will require a confirmation: The last word in
+	the line has to start with a 'y'.  This may look like:
+	:delete yes
+	:delete seriously? yeah!
 	"""
 
 	allow_abbrev = False
+	WARNING = 'delete seriously? '
 
 	def execute(self):
-		self.fm.delete()
+		line = parse(self.line)
+		lastword = line.chunk(-1)
 
+		if lastword.startswith('y'):
+			# user confirmed deletion!
+			return self.fm.delete()
+		elif self.line.startswith(delete.WARNING):
+			# user did not confirm deletion
+			return
+
+		if self.fm.env.pwd.marked_items \
+		or (self.fm.env.cf.is_directory and not self.fm.env.cf.empty()):
+			# better ask for a confirmation, when attempting to
+			# delete multiple files or a non-empty directory.
+			return self.fm.open_console(self.mode, delete.WARNING)
+
+		# no need for a confirmation, just delete
+		self.fm.delete()
 
 class mkdir(Command):
 	"""