Session file: Allow specifying multiple cd directives per tab to have different windows launched with different working directories

This commit is contained in:
Kovid Goyal 2018-01-08 12:38:01 +05:30
parent ce230b071b
commit c551384369
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 9 deletions

View File

@ -286,7 +286,7 @@ command line flag. For example:
.... ....
# Set the window layout for the current tab # Set the window layout for the current tab
layout tall layout tall
# Set the working directory for the current tab # Set the working directory for windows in the current tab
cd ~ cd ~
# Create a window and run the specified command in it # Create a window and run the specified command in it
launch zsh launch zsh

View File

@ -41,7 +41,8 @@ class Session:
cmd = shlex.split(cmd) if isinstance(cmd, str) else cmd cmd = shlex.split(cmd) if isinstance(cmd, str) else cmd
else: else:
cmd = None cmd = None
self.tabs[-1].windows.append(cmd) from .tabs import SpecialWindow
self.tabs[-1].windows.append(SpecialWindow(cmd, cwd=self.tabs[-1].cwd))
def add_special_window(self, sw): def add_special_window(self, sw):
self.tabs[-1].windows.append(sw) self.tabs[-1].windows.append(sw)

View File

@ -22,11 +22,11 @@ from .utils import color_as_int
from .window import Window, calculate_gl_geometry from .window import Window, calculate_gl_geometry
TabbarData = namedtuple('TabbarData', 'title is_active is_last') TabbarData = namedtuple('TabbarData', 'title is_active is_last')
SpecialWindowInstance = namedtuple('SpecialWindow', 'cmd stdin override_title cwd_from') SpecialWindowInstance = namedtuple('SpecialWindow', 'cmd stdin override_title cwd_from cwd')
def SpecialWindow(cmd, stdin=None, override_title=None, cwd_from=None): def SpecialWindow(cmd, stdin=None, override_title=None, cwd_from=None, cwd=None):
return SpecialWindowInstance(cmd, stdin, override_title, cwd_from) return SpecialWindowInstance(cmd, stdin, override_title, cwd_from, cwd)
class Tab: # {{{ class Tab: # {{{
@ -109,7 +109,7 @@ class Tab: # {{{
w.set_visible_in_layout(i, True) w.set_visible_in_layout(i, True)
self.relayout() self.relayout()
def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None): def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None):
if cmd is None: if cmd is None:
if use_shell: if use_shell:
cmd = [shell_path] cmd = [shell_path]
@ -122,12 +122,12 @@ class Tab: # {{{
except Exception: except Exception:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
ans = Child(cmd, self.cwd, self.opts, stdin, env, cwd_from) ans = Child(cmd, cwd or self.cwd, self.opts, stdin, env, cwd_from)
ans.fork() ans.fork()
return ans return ans
def new_window(self, use_shell=True, cmd=None, stdin=None, override_title=None, cwd_from=None): def new_window(self, use_shell=True, cmd=None, stdin=None, override_title=None, cwd_from=None, cwd=None):
child = self.launch_child(use_shell=use_shell, cmd=cmd, stdin=stdin, cwd_from=cwd_from) child = self.launch_child(use_shell=use_shell, cmd=cmd, stdin=stdin, cwd_from=cwd_from, cwd=cwd)
window = Window(self, child, self.opts, self.args, override_title=override_title) window = Window(self, child, self.opts, self.args, override_title=override_title)
# Must add child before laying out so that resize_pty succeeds # Must add child before laying out so that resize_pty succeeds
get_boss().add_child(window) get_boss().add_child(window)