summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-16 18:50:07 +0200
committerhut <hut@lavabit.com>2011-10-16 18:50:07 +0200
commit26ebd92b2867cfdcfdb55877e6c4918c2ac686b5 (patch)
tree93f267ca7bb8c501156f218c0d7bac67568909f8
parent9c37875e4cf983ec4dece175728d78350b7737c6 (diff)
downloadranger-26ebd92b2867cfdcfdb55877e6c4918c2ac686b5.tar.gz
core.actions: Safer _get_macros()
-rw-r--r--ranger/core/actions.py39
1 files changed, 29 insertions, 10 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index e9d89061..0961c3bd 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -152,19 +152,27 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		else:
 			macros['f'] = MACRO_FAIL
 
-		macros['s'] = [fl.basename for fl in self.fm.env.get_selection()]
+		if self.fm.env.get_selection:
+			macros['s'] = [fl.basename for fl in self.fm.env.get_selection()]
+		else:
+			macros['s'] = MACRO_FAIL
 
-		macros['c'] = [fl.path for fl in self.fm.env.copy]
+		if self.fm.env.copy:
+			macros['c'] = [fl.path for fl in self.fm.env.copy]
+		else:
+			macros['c'] = MACRO_FAIL
 
-		macros['t'] = [fl.basename for fl in self.fm.env.cwd.files
-				if fl.realpath in (self.fm.tags or [])]
+		if self.fm.env.cwd.files:
+			macros['t'] = [fl.basename for fl in self.fm.env.cwd.files
+					if fl.realpath in (self.fm.tags or [])]
+		else:
+			macros['t'] = MACRO_FAIL
 
 		if self.fm.env.cwd:
 			macros['d'] = self.fm.env.cwd.path
 		else:
 			macros['d'] = '.'
 
-
 		# define d/f/s macros for each tab
 		for i in range(1,10):
 			try:
@@ -174,7 +182,10 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 			tab_dir = self.fm.env.get_directory(tab_dir_path)
 			i = str(i)
 			macros[i + 'd'] = tab_dir_path
-			macros[i + 's'] = [fl.path for fl in tab_dir.get_selection()]
+			if tab_dir.get_selection():
+				macros[i + 's'] = [fl.path for fl in tab_dir.get_selection()]
+			else:
+				macros[i + 's'] = MACRO_FAIL
 			if tab_dir.pointed_obj:
 				macros[i + 'f'] = tab_dir.pointed_obj.path
 			else:
@@ -196,12 +207,20 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 			next_tab_path = self.fm.tabs[first_tab]
 		next_tab = self.fm.env.get_directory(next_tab_path)
 
-		macros['D'] = next_tab
-		if next_tab.pointed_obj:
-			macros['F'] = next_tab.pointed_obj.path
+		if next_tab:
+			macros['D'] = str(next_tab.path)
+			if next_tab.pointed_obj:
+				macros['F'] = next_tab.pointed_obj.path
+			else:
+				macros['F'] = MACRO_FAIL
+			if next_tab.get_selection():
+				macros['S'] = [fl.path for fl in next_tab.get_selection()]
+			except:
+				macros['S'] = MACRO_FAIL
 		else:
+			macros['D'] = MACRO_FAIL
 			macros['F'] = MACRO_FAIL
-		macros['S'] = [fl.path for fl in next_tab.get_selection()]
+			macros['S'] = MACRO_FAIL
 
 		return macros