@@ -124,7 +124,7 @@ def inline(sconf):
124124 return sconf
125125
126126
127- def expand (sconf ):
127+ def expand (sconf , cwd = None ):
128128 """Return config with shorthand and inline properties expanded.
129129
130130 This is necessary to keep the code in the :class:`WorkspaceBuilder` clean
@@ -142,12 +142,22 @@ def expand(sconf):
142142 Kaptan will load JSON/YAML/INI files into python dicts for you.
143143 :param sconf: the configuration for the session
144144 :type sconf: dict
145+ :param cwd: directory to expand relative paths against. should be the dir of
146+ the config directory.
145147 :rtype: dict
146148
147149 """
148150
151+ if not cwd :
152+ cwd = os .getcwd ()
153+
149154 # Any config section, session, window, pane that can contain the
150155 # 'shell_command' value
156+ if 'start_directory' in sconf :
157+ if any (sconf ['start_directory' ].startswith (a ) for a in ['.' , './' ]):
158+ sconf ['start_directory' ] = os .path .normpath (os .path .join (cwd , sconf ['start_directory' ]))
159+ elif any (sconf ['start_directory' ] == a for a in ['.' , './' ]):
160+ sconf ['start_directory' ] = os .path .normpath (os .path .join (cwd , sconf ['start_directory' ]))
151161
152162 if ('shell_command' in sconf and isinstance (sconf ['shell_command' ], basestring )):
153163 sconf ['shell_command' ] = [sconf ['shell_command' ]]
@@ -202,13 +212,10 @@ def trickle(sconf):
202212
203213 # Prepend start_directory to relative window commands
204214 if session_start_directory :
205-
206215 if not 'start_directory' in windowconfig :
207216 windowconfig ['start_directory' ] = session_start_directory
208217 else :
209- if any (windowconfig ['start_directory' ] == a for a in ['.' , './' ]):
210- windowconfig ['start_directory' ] = os .getcwd ()
211- elif not any (windowconfig ['start_directory' ].startswith (a ) for a in ['~' , '/' ]):
218+ if not any (windowconfig ['start_directory' ].startswith (a ) for a in ['~' , '/' ]):
212219 windowconfig ['start_directory' ] = os .path .join (
213220 session_start_directory , windowconfig ['start_directory' ])
214221
0 commit comments