@@ -28,6 +28,14 @@ impl fmt::Display for UnixUser {
28
28
#[ serde( deny_unknown_fields) ]
29
29
pub struct SymbolicTarget {
30
30
pub target : PathBuf ,
31
+ /// If supplied it replaces the source file deduced from the TOML section header/given as key.
32
+ /// ```toml
33
+ /// [sway.files.fish]
34
+ /// file = "fish/conf.d/sway.fish"
35
+ /// target = "~/.config/fish/conf.d/sway.fish"
36
+ /// type = "symbolic"
37
+ /// ````
38
+ pub file : Option < PathBuf > ,
31
39
pub owner : Option < UnixUser > ,
32
40
pub recurse : Option < bool > ,
33
41
#[ serde( rename = "if" ) ]
@@ -38,6 +46,14 @@ pub struct SymbolicTarget {
38
46
#[ serde( deny_unknown_fields) ]
39
47
pub struct TemplateTarget {
40
48
pub target : PathBuf ,
49
+ /// If supplied it replaces the source file deduced from the TOML section header/given as key.
50
+ /// ```toml
51
+ /// [sway.files.fish]
52
+ /// file = "fish/conf.d/sway.fish"
53
+ /// target = "~/.config/fish/conf.d/sway.fish"
54
+ /// type = "symbolic"
55
+ /// ````
56
+ pub file : Option < PathBuf > ,
41
57
pub owner : Option < UnixUser > ,
42
58
pub append : Option < String > ,
43
59
pub prepend : Option < String > ,
@@ -159,6 +175,10 @@ pub fn load_configuration(
159
175
merge_configuration_files ( global, local, patch) . context ( "merge configuration files" ) ?;
160
176
trace ! ( "Merged config: {:#?}" , merged_config) ;
161
177
178
+ debug ! ( "Replacing source by the file key indicated in complex targets" ) ;
179
+ merged_config. files =
180
+ replace_source ( & merged_config) . context ( "replace source for complex targets" ) ?;
181
+
162
182
debug ! ( "Expanding files which are directories..." ) ;
163
183
merged_config. files =
164
184
expand_directories ( & merged_config) . context ( "expand files that are directories" ) ?;
@@ -451,6 +471,7 @@ impl<T: Into<PathBuf>> From<T> for SymbolicTarget {
451
471
fn from ( input : T ) -> Self {
452
472
SymbolicTarget {
453
473
target : input. into ( ) ,
474
+ file : None ,
454
475
owner : None ,
455
476
condition : None ,
456
477
recurse : None ,
@@ -462,6 +483,7 @@ impl<T: Into<PathBuf>> From<T> for TemplateTarget {
462
483
fn from ( input : T ) -> Self {
463
484
TemplateTarget {
464
485
target : input. into ( ) ,
486
+ file : None ,
465
487
owner : None ,
466
488
append : None ,
467
489
prepend : None ,
@@ -476,6 +498,7 @@ impl SymbolicTarget {
476
498
target : self . target ,
477
499
owner : self . owner ,
478
500
condition : self . condition ,
501
+ file : self . file ,
479
502
prepend : None ,
480
503
append : None ,
481
504
}
@@ -517,6 +540,7 @@ fn expand_directory(source: &Path, target: &FileTarget, config: &Configuration)
517
540
let recurse = match target {
518
541
FileTarget :: Symbolic ( SymbolicTarget {
519
542
target : _,
543
+ file : _,
520
544
owner : _,
521
545
condition : _,
522
546
recurse : Some ( rec) ,
@@ -546,6 +570,36 @@ fn expand_directory(source: &Path, target: &FileTarget, config: &Configuration)
546
570
}
547
571
}
548
572
573
+ fn replace_source ( config : & Configuration ) -> Result < Files > {
574
+ let expanded = config
575
+ . files
576
+ . iter ( )
577
+ . map ( |( source, target) | {
578
+ let mut map = Files :: new ( ) ;
579
+
580
+ match target {
581
+ FileTarget :: Symbolic ( t) => {
582
+ map. insert (
583
+ t. file . clone ( ) . unwrap_or ( source. clone ( ) ) . into ( ) ,
584
+ target. clone ( ) ,
585
+ ) ;
586
+ }
587
+ FileTarget :: ComplexTemplate ( t) => {
588
+ map. insert (
589
+ t. file . clone ( ) . unwrap_or ( source. clone ( ) ) . into ( ) ,
590
+ target. clone ( ) ,
591
+ ) ;
592
+ }
593
+ FileTarget :: Automatic ( _) => {
594
+ map. insert ( source. clone ( ) , target. clone ( ) ) ;
595
+ }
596
+ } ;
597
+ Ok ( map)
598
+ } )
599
+ . collect :: < Result < Vec < Files > > > ( ) ?;
600
+ Ok ( expanded. into_iter ( ) . flatten ( ) . collect :: < Files > ( ) )
601
+ }
602
+
549
603
#[ cfg( unix) ]
550
604
impl UnixUser {
551
605
pub fn as_sudo_arg ( & self ) -> String {
0 commit comments