summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/widgets/console.py36
-rw-r--r--ranger/help/console.py6
2 files changed, 41 insertions, 1 deletions
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 1ee7ebc0..f02a4b01 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -44,7 +44,7 @@ OPEN_HISTORY = 3
 class _CustomTemplate(string.Template):
 	"""A string.Template subclass for use in the OpenConsole"""
 	delimiter = '%'
-	idpattern = '[a-z]'
+	idpattern = '\d?[a-z]'
 
 
 class Console(Widget):
@@ -489,6 +489,40 @@ class OpenConsole(ConsoleWithTab):
 		else:
 			macros['d'] = '.'
 
+		# define d/f/s macros for each tab
+		for i in range(1,10):
+			try:
+				tab_dir_path = self.fm.tabs[i]
+			except:
+				continue
+			tab_dir = self.fm.env.get_directory(tab_dir_path)
+			i = str(i)
+			macros[i + 'd'] = shell_quote(tab_dir_path)
+			macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
+			macros[i + 's'] = ' '.join(shell_quote(fl.path)
+				for fl in tab_dir.get_selection())
+
+		# define D/F/S for the next tab
+		found_current_tab = False
+		next_tab_path = None
+		first_tab = None
+		for tab in self.fm.tabs:
+			if not first_tab:
+				first_tab = tab
+			if found_current_tab:
+				next_tab_path = self.fm.tabs[tab]
+				break
+			if self.fm.current_tab == tab:
+				found_current_tab = True
+		if found_current_tab and not next_tab_path:
+			next_tab_path = self.fm.tabs[first_tab]
+		next_tab = self.fm.env.get_directory(next_tab_path)
+
+		macros['D'] = shell_quote(next_tab)
+		macros['F'] = shell_quote(next_tab.pointed_obj.path)
+		macros['S'] = ' '.join(shell_quote(fl.path)
+			for fl in next_tab.get_selection())
+
 		return _CustomTemplate(command).safe_substitute(macros)
 
 	def _parse(self):
diff --git a/ranger/help/console.py b/ranger/help/console.py
index 3768a79a..c830abfc 100644
--- a/ranger/help/console.py
+++ b/ranger/help/console.py
@@ -173,6 +173,12 @@ commands and they will be replaced with a list of files.
 	%t	all tagged files in the current directory
 	%c	the full paths of the currently copied/cut files
 
+The macros %f, %d and %s also have upper case variants, %F, %D and %S,
+which refer to the next tab.  To refer to specific tabs, add a number in
+between. Examples:
+	%D	The path of the directory in the next tab
+	%7s	The selection of the seventh tab
+
 %c is the only macro which ranges out of the current directory. So you may
 "abuse" the copying function for other purposes, like diffing two files which
 are in different directories: