@@ -3,13 +3,15 @@ use std::path::PathBuf;
33
44/// Locate the configuration file following XDG Base Directory specification
55///
6+ /// Supports both rb.kdl and rb.toml (preferring .kdl)
7+ ///
68/// Priority order:
79/// 1. Explicit override path (if provided)
810/// 2. $RB_CONFIG environment variable
9- /// 3. $XDG_CONFIG_HOME/rb/rb.toml (Unix/Linux)
10- /// 4. ~/.config/rb/rb.toml (Unix/Linux fallback)
11- /// 5. %APPDATA%/rb/rb.toml (Windows)
12- /// 6. ~/.rb.toml (cross-platform fallback)
11+ /// 3. $XDG_CONFIG_HOME/rb/rb.kdl or rb. toml (Unix/Linux)
12+ /// 4. ~/.config/rb/rb.kdl or rb. toml (Unix/Linux fallback)
13+ /// 5. %APPDATA%/rb/rb.kdl or rb. toml (Windows)
14+ /// 6. ~/.rb.kdl or ~/.rb. toml (cross-platform fallback)
1315pub fn locate_config_file ( override_path : Option < PathBuf > ) -> Option < PathBuf > {
1416 debug ! ( "Searching for configuration file..." ) ;
1517
@@ -34,49 +36,58 @@ pub fn locate_config_file(override_path: Option<PathBuf>) -> Option<PathBuf> {
3436
3537 // 3. Try XDG_CONFIG_HOME (Unix/Linux)
3638 if let Ok ( xdg_config) = std:: env:: var ( "XDG_CONFIG_HOME" ) {
37- let config_path = PathBuf :: from ( xdg_config) . join ( "rb" ) . join ( "rb.toml" ) ;
38- debug ! ( " Checking XDG_CONFIG_HOME: {}" , config_path. display( ) ) ;
39- if config_path. exists ( ) {
40- debug ! ( " Found configuration file in XDG_CONFIG_HOME" ) ;
41- return Some ( config_path) ;
39+ let base_path = PathBuf :: from ( xdg_config) . join ( "rb" ) ;
40+ // Try .kdl first, then .toml
41+ for ext in & [ "rb.kdl" , "rb.toml" ] {
42+ let config_path = base_path. join ( ext) ;
43+ debug ! ( " Checking XDG_CONFIG_HOME: {}" , config_path. display( ) ) ;
44+ if config_path. exists ( ) {
45+ debug ! ( " Found configuration file in XDG_CONFIG_HOME" ) ;
46+ return Some ( config_path) ;
47+ }
4248 }
4349 }
4450
4551 // Try home directory based paths
4652 if let Some ( home_dir) = home:: home_dir ( ) {
47- // Unix/Linux: ~/.config/rb/rb.toml
53+ // Unix/Linux: ~/.config/rb/rb.kdl or rb. toml
4854 #[ cfg( not( target_os = "windows" ) ) ]
4955 {
50- let config_path = home_dir. join ( ".config" ) . join ( "rb" ) . join ( "rb.toml" ) ;
51- debug ! ( " Checking ~/.config/rb/rb.toml: {}" , config_path. display( ) ) ;
52- if config_path. exists ( ) {
53- debug ! ( " Found configuration file in ~/.config/rb/" ) ;
54- return Some ( config_path) ;
56+ let base_path = home_dir. join ( ".config" ) . join ( "rb" ) ;
57+ for ext in & [ "rb.kdl" , "rb.toml" ] {
58+ let config_path = base_path. join ( ext) ;
59+ debug ! ( " Checking ~/.config/rb/{}: {}" , ext, config_path. display( ) ) ;
60+ if config_path. exists ( ) {
61+ debug ! ( " Found configuration file in ~/.config/rb/" ) ;
62+ return Some ( config_path) ;
63+ }
5564 }
5665 }
5766
58- // Windows: %APPDATA%/rb/rb.toml
67+ // Windows: %APPDATA%/rb/rb.kdl or rb. toml
5968 #[ cfg( target_os = "windows" ) ]
6069 {
6170 if let Ok ( appdata) = std:: env:: var ( "APPDATA" ) {
62- let config_path = PathBuf :: from ( appdata) . join ( "rb" ) . join ( "rb.toml" ) ;
63- debug ! ( " Checking %APPDATA%/rb/rb.toml: {}" , config_path. display( ) ) ;
64- if config_path. exists ( ) {
65- debug ! ( " Found configuration file in %APPDATA%/rb/" ) ;
66- return Some ( config_path) ;
71+ let base_path = PathBuf :: from ( appdata) . join ( "rb" ) ;
72+ for ext in & [ "rb.kdl" , "rb.toml" ] {
73+ let config_path = base_path. join ( ext) ;
74+ debug ! ( " Checking %APPDATA%/rb/{}: {}" , ext, config_path. display( ) ) ;
75+ if config_path. exists ( ) {
76+ debug ! ( " Found configuration file in %APPDATA%/rb/" ) ;
77+ return Some ( config_path) ;
78+ }
6779 }
6880 }
6981 }
7082
71- // Cross-platform fallback: ~/.rb.toml
72- let fallback_path = home_dir. join ( ".rb.toml" ) ;
73- debug ! (
74- " Checking fallback ~/.rb.toml: {}" ,
75- fallback_path. display( )
76- ) ;
77- if fallback_path. exists ( ) {
78- debug ! ( " Found configuration file at ~/.rb.toml" ) ;
79- return Some ( fallback_path) ;
83+ // Cross-platform fallback: ~/.rb.kdl or ~/.rb.toml
84+ for ext in & [ ".rb.kdl" , ".rb.toml" ] {
85+ let fallback_path = home_dir. join ( ext) ;
86+ debug ! ( " Checking fallback ~/{}: {}" , ext, fallback_path. display( ) ) ;
87+ if fallback_path. exists ( ) {
88+ debug ! ( " Found configuration file at ~/{}" , ext) ;
89+ return Some ( fallback_path) ;
90+ }
8091 }
8192 }
8293
0 commit comments