File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
9595
9696 log:: debug!( "Using config file path: {:#?}" , config_file_path) ;
9797
98+ // If no config is present
99+ // Creates a default config at location (read man 5 swhkd)
100+
101+ if !Path :: new ( & config_file_path) . exists ( ) {
102+ log:: warn!( "No config found at path: {:#?}" , config_file_path) ;
103+ create_default_config ( invoking_uid, & config_file_path) ;
104+ }
105+
98106 match config:: load ( & config_file_path) {
99107 Err ( e) => {
100108 log:: error!( "Config Error: {}" , e) ;
@@ -494,6 +502,23 @@ pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) {
494502 }
495503}
496504
505+ pub fn create_default_config ( invoking_uid : u32 , config_file_path : & PathBuf ) {
506+ // Initializes a default SWHKD config at specific config path
507+
508+ perms:: raise_privileges ( ) ;
509+ _ = match fs:: File :: create ( & config_file_path) {
510+ Ok ( mut file) => {
511+ log:: debug!( "Created default SWHKD config at: {:#?}" , config_file_path) ;
512+ _ = file. write_all ( b"# Comments start with #, uncomment to use \n #start a terminal\n #super + return\n #\t alacritty # replace with terminal of your choice" ) ;
513+ }
514+ Err ( err) => {
515+ log:: error!( "Error creating config file: {}" , err) ;
516+ exit ( 1 ) ;
517+ }
518+ } ;
519+ perms:: drop_privileges ( invoking_uid) ;
520+ }
521+
497522pub fn send_command (
498523 hotkey : Hotkey ,
499524 socket_path : & Path ,
You can’t perform that action at this time.
0 commit comments