From a3ba320016e86b4df198e7b43acd77657b9a2a1a Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 15 Apr 2023 16:20:07 -0400 Subject: [PATCH 1/6] changed themes directory to $XDG_DATA_HOME and config directory to $XDG_CONFIG_HOME --- src/config.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index dcdba06..bd0cc5d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,11 +46,19 @@ impl Default for Config { /// Gets the configuration directory. Panics if unavailable. pub fn get_config_dir() -> PathBuf { - std::env::var_os("HOME") + std::env::var_os("XDG_CONFIG_HOME") .map(PathBuf::try_from) - .expect("$HOME is unset") + .expect("$XDG_CONFIG_HOME is unset") .unwrap() - .join(".config/breed") + .join("breed") +} + +pub fn get_data_dir() -> PathBuf { + std::env::var_os("XDG_DATA_HOME") + .map(PathBuf::try_from) + .expect("$XDG_DATA_HOME is unset") + .unwrap() + .join("breed") } /// Watches a theme file and automatically reloads it into a [StyleStore]. @@ -65,7 +73,8 @@ pub struct ThemeWatcher { impl ThemeWatcher { pub fn spawn(styles: Arc>) -> Sender { - let themes_dir = get_config_dir().join("themes"); + let themes_dir = get_data_dir().join("themes"); + println!("{:?}", themes_dir); let default_path = themes_dir.join("default.toml"); let (fs_tx, fs_rx) = unbounded(); let (command_tx, command_rx) = unbounded(); From 70f242f8f66ec3072c84c7882fb20b09c6293e6b Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 15 Apr 2023 16:25:20 -0400 Subject: [PATCH 2/6] fall back to $HOME/.config and $HOME/.local/share --- src/config.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index bd0cc5d..38e89f6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,16 +48,28 @@ impl Default for Config { pub fn get_config_dir() -> PathBuf { std::env::var_os("XDG_CONFIG_HOME") .map(PathBuf::try_from) - .expect("$XDG_CONFIG_HOME is unset") - .unwrap() + .expect("$XDG_CONFIG_HOME is unset.") + .unwrap_or_else(|_| { + std::env::var_os("HOME") + .map(PathBuf::try_from) + .expect("User has no $HOME.") + .unwrap() + .join(".config") + }) .join("breed") } pub fn get_data_dir() -> PathBuf { std::env::var_os("XDG_DATA_HOME") .map(PathBuf::try_from) - .expect("$XDG_DATA_HOME is unset") - .unwrap() + .expect("$XDG_DATA_HOME is unset.") + .unwrap_or_else(|_| { + std::env::var_os("HOME") + .map(PathBuf::try_from) + .expect("User has no $HOME.") + .unwrap() + .join(".local/share") + }) .join("breed") } From ddbdc3f7a7dd1ebe9a1c6a98b204e6995b731747 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 15 Apr 2023 17:21:17 -0400 Subject: [PATCH 3/6] removed println macro used for testing --- src/config.rs | 1 - src/keybinds.rs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 38e89f6..35fe0fb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -86,7 +86,6 @@ pub struct ThemeWatcher { impl ThemeWatcher { pub fn spawn(styles: Arc>) -> Sender { let themes_dir = get_data_dir().join("themes"); - println!("{:?}", themes_dir); let default_path = themes_dir.join("default.toml"); let (fs_tx, fs_rx) = unbounded(); let (command_tx, command_rx) = unbounded(); diff --git a/src/keybinds.rs b/src/keybinds.rs index c9f993b..2c8a5d3 100644 --- a/src/keybinds.rs +++ b/src/keybinds.rs @@ -60,6 +60,8 @@ impl Default for Keybinds { let normalish_keys = [ (Char(':'), command_mode as Action), + (Char('$'), goto_line_end), + (Char('0'), goto_line_start), (Char('h'), move_char_left), (Char('j'), move_line_down), (Char('k'), move_line_up), From 4b6e5edbd301ba5a7d13dbab5836e3469fab1d44 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 15 Apr 2023 17:21:55 -0400 Subject: [PATCH 4/6] Revert "removed println macro used for testing" This reverts commit ddbdc3f7a7dd1ebe9a1c6a98b204e6995b731747. --- src/config.rs | 1 + src/keybinds.rs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 35fe0fb..38e89f6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -86,6 +86,7 @@ pub struct ThemeWatcher { impl ThemeWatcher { pub fn spawn(styles: Arc>) -> Sender { let themes_dir = get_data_dir().join("themes"); + println!("{:?}", themes_dir); let default_path = themes_dir.join("default.toml"); let (fs_tx, fs_rx) = unbounded(); let (command_tx, command_rx) = unbounded(); diff --git a/src/keybinds.rs b/src/keybinds.rs index 2c8a5d3..c9f993b 100644 --- a/src/keybinds.rs +++ b/src/keybinds.rs @@ -60,8 +60,6 @@ impl Default for Keybinds { let normalish_keys = [ (Char(':'), command_mode as Action), - (Char('$'), goto_line_end), - (Char('0'), goto_line_start), (Char('h'), move_char_left), (Char('j'), move_line_down), (Char('k'), move_line_up), From 487b8e458000911c9a82376a5848f73c50d1daff Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 15 Apr 2023 17:22:32 -0400 Subject: [PATCH 5/6] removed println macro used for testing --- src/config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 38e89f6..35fe0fb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -86,7 +86,6 @@ pub struct ThemeWatcher { impl ThemeWatcher { pub fn spawn(styles: Arc>) -> Sender { let themes_dir = get_data_dir().join("themes"); - println!("{:?}", themes_dir); let default_path = themes_dir.join("default.toml"); let (fs_tx, fs_rx) = unbounded(); let (command_tx, command_rx) = unbounded(); From d6138d5986016c72f6caeafce4696f38df48e504 Mon Sep 17 00:00:00 2001 From: mars Date: Wed, 19 Apr 2023 23:46:08 -0400 Subject: [PATCH 6/6] Fixed get_*_dir() result handling --- src/config.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 35fe0fb..819f96f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,13 +47,12 @@ impl Default for Config { /// Gets the configuration directory. Panics if unavailable. pub fn get_config_dir() -> PathBuf { std::env::var_os("XDG_CONFIG_HOME") - .map(PathBuf::try_from) - .expect("$XDG_CONFIG_HOME is unset.") - .unwrap_or_else(|_| { + .map(|p| PathBuf::try_from(p).expect("$XDG_CONFIG_HOME is not a valid path.")) + .unwrap_or_else(|| { std::env::var_os("HOME") .map(PathBuf::try_from) - .expect("User has no $HOME.") - .unwrap() + .expect("$HOME is not a valid path.") + .expect("User has no $HOME or $XDG_CONFIG_HOME.") .join(".config") }) .join("breed") @@ -61,13 +60,12 @@ pub fn get_config_dir() -> PathBuf { pub fn get_data_dir() -> PathBuf { std::env::var_os("XDG_DATA_HOME") - .map(PathBuf::try_from) - .expect("$XDG_DATA_HOME is unset.") - .unwrap_or_else(|_| { + .map(|p| PathBuf::try_from(p).expect("$XDG_DATA_HOME is not a valid path.")) + .unwrap_or_else(|| { std::env::var_os("HOME") .map(PathBuf::try_from) - .expect("User has no $HOME.") - .unwrap() + .expect("$HOME is not a valid path.") + .expect("User has no $HOME or $XDG_DATA_HOME.") .join(".local/share") }) .join("breed")