@@ -334,11 +334,11 @@ pub enum Message {
334334 ProfileName ( ProfileId , String ) ,
335335 ProfileNew ,
336336 ProfileOpen ( ProfileId ) ,
337+ ProfileOpenInCWD ( ProfileId , bool ) ,
337338 ProfileRemove ( ProfileId ) ,
338339 ProfileSyntaxTheme ( ProfileId , ColorSchemeKind , usize ) ,
339340 ProfileTabTitle ( ProfileId , String ) ,
340341 SelectAll ( Option < segmented_button:: Entity > ) ,
341- SetOpenInCWD ( bool ) ,
342342 ShowAdvancedFontSettings ( bool ) ,
343343 ShowHeaderBar ( bool ) ,
344344 SyntaxTheme ( ColorSchemeKind , usize ) ,
@@ -995,6 +995,13 @@ impl App {
995995 ] )
996996 . align_items ( Alignment :: Center )
997997 . padding ( [ 0 , space_s] ) ,
998+ )
999+ . add (
1000+ widget:: settings:: item:: builder ( fl ! ( "open-in-cwd" ) )
1001+ . description ( fl ! ( "open-in-cwd-description" ) )
1002+ . toggler ( profile. open_in_cwd , move |open_in_cwd| {
1003+ Message :: ProfileOpenInCWD ( profile_id, open_in_cwd)
1004+ } ) ,
9981005 ) ;
9991006
10001007 let padding = Padding {
@@ -1200,17 +1207,11 @@ impl App {
12001207 . toggler ( self . config . focus_follow_mouse , Message :: FocusFollowMouse ) ,
12011208 ) ;
12021209
1203- let advanced_section = widget:: settings:: view_section ( fl ! ( "advanced" ) )
1204- . add (
1205- widget:: settings:: item:: builder ( fl ! ( "show-headerbar" ) )
1206- . description ( fl ! ( "show-header-description" ) )
1207- . toggler ( self . config . show_headerbar , Message :: ShowHeaderBar ) ,
1208- )
1209- . add (
1210- widget:: settings:: item:: builder ( fl ! ( "open-in-cwd" ) )
1211- . description ( fl ! ( "open-in-cwd-description" ) )
1212- . toggler ( self . config . open_in_cwd , Message :: SetOpenInCWD ) ,
1213- ) ;
1210+ let advanced_section = widget:: settings:: view_section ( fl ! ( "advanced" ) ) . add (
1211+ widget:: settings:: item:: builder ( fl ! ( "show-headerbar" ) )
1212+ . description ( fl ! ( "show-header-description" ) )
1213+ . toggler ( self . config . show_headerbar , Message :: ShowHeaderBar ) ,
1214+ ) ;
12141215
12151216 widget:: settings:: view_column ( vec ! [
12161217 appearance_section. into( ) ,
@@ -1248,22 +1249,6 @@ impl App {
12481249 Some ( colors) => {
12491250 let current_pane = self . pane_model . focus ;
12501251 if let Some ( tab_model) = self . pane_model . active_mut ( ) {
1251- // Current working directory of the selected tab/terminal
1252- #[ cfg( not( windows) ) ]
1253- let cwd = self
1254- . config
1255- . open_in_cwd
1256- . then ( || {
1257- tab_model. active_data :: < Mutex < Terminal > > ( ) . and_then (
1258- |terminal| {
1259- terminal. lock ( ) . unwrap ( ) . current_working_directory ( )
1260- } ,
1261- )
1262- } )
1263- . flatten ( ) ;
1264- #[ cfg( windows) ]
1265- let cwd: Option < std:: path:: PathBuf > = None ;
1266-
12671252 // Use the profile options, startup options, or defaults
12681253 let ( options, tab_title_override) = match profile_id_opt
12691254 . and_then ( |profile_id| self . config . profiles . get ( & profile_id) )
@@ -1276,8 +1261,27 @@ impl App {
12761261 shell = Some ( tty:: Shell :: new ( command, args) ) ;
12771262 }
12781263 }
1279- let working_directory = cwd
1264+
1265+ #[ cfg( not( windows) ) ]
1266+ let working_directory = profile
1267+ . open_in_cwd
1268+ // Evaluate current working working directory based on
1269+ // selected tab/terminal
1270+ . then ( || {
1271+ tab_model. active_data :: < Mutex < Terminal > > ( ) . and_then (
1272+ |terminal| {
1273+ terminal
1274+ . lock ( )
1275+ . unwrap ( )
1276+ . current_working_directory ( )
1277+ } ,
1278+ )
1279+ } )
1280+ . flatten ( )
12801281 . or_else ( || Some ( profile. working_directory . clone ( ) . into ( ) ) ) ;
1282+ #[ cfg( windows) ]
1283+ let working_directory = ( !profile. working_directory . is_empty ( ) )
1284+ . then ( || profile. working_directory . clone ( ) . into ( ) ) ;
12811285
12821286 let options = tty:: Options {
12831287 shell,
@@ -1295,7 +1299,15 @@ impl App {
12951299 None => {
12961300 let mut options =
12971301 self . startup_options . take ( ) . unwrap_or_default ( ) ;
1298- options. working_directory = cwd;
1302+ #[ cfg( not( windows) ) ]
1303+ {
1304+ // Eval CWD since it's the default option
1305+ options. working_directory = tab_model
1306+ . active_data :: < Mutex < Terminal > > ( )
1307+ . and_then ( |terminal| {
1308+ terminal. lock ( ) . unwrap ( ) . current_working_directory ( )
1309+ } ) ;
1310+ }
12991311 ( options, None )
13001312 }
13011313 } ;
@@ -2181,6 +2193,13 @@ impl Application for App {
21812193 Message :: ProfileOpen ( profile_id) => {
21822194 return self . create_and_focus_new_terminal ( self . pane_model . focus , Some ( profile_id) ) ;
21832195 }
2196+ Message :: ProfileOpenInCWD ( profile_id, open_in_cwd) => {
2197+ #[ cfg( not( windows) ) ]
2198+ if let Some ( profile) = self . config . profiles . get_mut ( & profile_id) {
2199+ profile. open_in_cwd = open_in_cwd;
2200+ return self . save_profiles ( ) ;
2201+ }
2202+ }
21842203 Message :: ProfileRemove ( profile_id) => {
21852204 // Reset matching terminals to default profile
21862205 for ( _pane, tab_model) in self . pane_model . panes . iter ( ) {
@@ -2239,12 +2258,6 @@ impl Application for App {
22392258 }
22402259 return self . update_focus ( ) ;
22412260 }
2242- Message :: SetOpenInCWD ( open_in_cwd) => {
2243- if open_in_cwd != self . config . open_in_cwd {
2244- self . config . open_in_cwd = open_in_cwd;
2245- return self . update_config ( ) ;
2246- }
2247- }
22482261 Message :: ShowHeaderBar ( show_headerbar) => {
22492262 if show_headerbar != self . config . show_headerbar {
22502263 config_set ! ( show_headerbar, show_headerbar) ;
0 commit comments