From a07ab883af3aa9c43525dae108c136bfca07c6f7 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 22 Jul 2023 10:31:03 -0700 Subject: [PATCH] persist charselect, repl history and others in data dir We were using the runtime dir with a fallback to a directory that was equivalent to the data dir on !xdg systems. That meant that the state in the runtime dir was often scrubbed around a reboot. refs: https://github.com/wez/wezterm/discussions/4019 refs: https://github.com/wez/wezterm/issues/4047 --- config/src/config.rs | 8 ++++++++ config/src/lib.rs | 1 + config/src/lua.rs | 2 +- docs/changelog.md | 1 + lua-api-crates/plugin/src/lib.rs | 2 +- wezterm-gui/src/overlay/debug.rs | 2 +- wezterm-gui/src/termwindow/charselect.rs | 2 +- wezterm-gui/src/termwindow/palette.rs | 2 +- wezterm-gui/src/update.rs | 4 ++-- 9 files changed, 17 insertions(+), 7 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index ef889f87a..0b2e0d680 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -1643,6 +1643,14 @@ fn default_font_size() -> f64 { 12.0 } +pub(crate) fn compute_data_dir() -> anyhow::Result { + if let Some(runtime) = dirs_next::data_dir() { + return Ok(runtime.join("wezterm")); + } + + Ok(crate::HOME_DIR.join(".local/share/wezterm")) +} + pub(crate) fn compute_runtime_dir() -> anyhow::Result { if let Some(runtime) = dirs_next::runtime_dir() { return Ok(runtime.join("wezterm")); diff --git a/config/src/lib.rs b/config/src/lib.rs index 6932b479b..9b1e5f071 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -65,6 +65,7 @@ lazy_static! { pub static ref HOME_DIR: PathBuf = dirs_next::home_dir().expect("can't find HOME dir"); pub static ref CONFIG_DIRS: Vec = config_dirs(); pub static ref RUNTIME_DIR: PathBuf = compute_runtime_dir().unwrap(); + pub static ref DATA_DIR: PathBuf = compute_data_dir().unwrap(); static ref CONFIG: Configuration = Configuration::new(); static ref CONFIG_FILE_OVERRIDE: Mutex> = Mutex::new(None); static ref CONFIG_SKIP: AtomicBool = AtomicBool::new(false); diff --git a/config/src/lua.rs b/config/src/lua.rs index 9c97c6cad..ecc22432a 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -233,7 +233,7 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result { } path_array.insert( 2, - format!("{}/plugins/?/plugin/init.lua", crate::RUNTIME_DIR.display()), + format!("{}/plugins/?/plugin/init.lua", crate::DATA_DIR.display()), ); if let Ok(exe) = std::env::current_exe() { diff --git a/docs/changelog.md b/docs/changelog.md index 5c602e871..3dbca374a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -68,6 +68,7 @@ As features stabilize some brief notes about them will accumulate here. * Windows: couldn't use shifted keys like `(` in the Debug Overlay. #3999 * X11: fd leak on each call to [wezterm.gui.enumerate_gpus](config/lua/wezterm.gui/enumerate_gpus.md). #3612 +* Charselect and repl recency/history were not persisted across restarts. #4047 ?4019 ### 20230712-072601-f4abf8fd diff --git a/lua-api-crates/plugin/src/lib.rs b/lua-api-crates/plugin/src/lib.rs index 7676537cd..42639c880 100644 --- a/lua-api-crates/plugin/src/lib.rs +++ b/lua-api-crates/plugin/src/lib.rs @@ -90,7 +90,7 @@ impl RepoSpec { } fn plugins_dir() -> PathBuf { - config::RUNTIME_DIR.join("plugins") + config::DATA_DIR.join("plugins") } fn checkout_path(&self) -> PathBuf { diff --git a/wezterm-gui/src/overlay/debug.rs b/wezterm-gui/src/overlay/debug.rs index e1846814a..6c09b5af0 100644 --- a/wezterm-gui/src/overlay/debug.rs +++ b/wezterm-gui/src/overlay/debug.rs @@ -25,7 +25,7 @@ struct LuaReplHost { } fn history_file_name() -> PathBuf { - config::RUNTIME_DIR.join("repl-history") + config::DATA_DIR.join("repl-history") } impl LuaReplHost { diff --git a/wezterm-gui/src/termwindow/charselect.rs b/wezterm-gui/src/termwindow/charselect.rs index 4153e21b5..a00396634 100644 --- a/wezterm-gui/src/termwindow/charselect.rs +++ b/wezterm-gui/src/termwindow/charselect.rs @@ -95,7 +95,7 @@ struct Recent { } fn recent_file_name() -> PathBuf { - config::RUNTIME_DIR.join("recent-emoji.json") + config::DATA_DIR.join("recent-emoji.json") } fn load_recents() -> anyhow::Result> { diff --git a/wezterm-gui/src/termwindow/palette.rs b/wezterm-gui/src/termwindow/palette.rs index b656440d4..5a2867dbe 100644 --- a/wezterm-gui/src/termwindow/palette.rs +++ b/wezterm-gui/src/termwindow/palette.rs @@ -48,7 +48,7 @@ struct Recent { } fn recent_file_name() -> PathBuf { - config::RUNTIME_DIR.join("recent-commands.json") + config::DATA_DIR.join("recent-commands.json") } fn load_recents() -> anyhow::Result> { diff --git a/wezterm-gui/src/update.rs b/wezterm-gui/src/update.rs index ed6c6f63f..970c34739 100644 --- a/wezterm-gui/src/update.rs +++ b/wezterm-gui/src/update.rs @@ -265,7 +265,7 @@ pub fn load_last_release_info_and_set_banner() { return; } - let update_file_name = config::RUNTIME_DIR.join("check_update"); + let update_file_name = config::DATA_DIR.join("check_update"); if let Ok(data) = std::fs::read(update_file_name) { let latest: Release = match serde_json::from_slice(&data) { Ok(d) => d, @@ -351,7 +351,7 @@ fn update_checker() { let force_ui = std::env::var_os("WEZTERM_ALWAYS_SHOW_UPDATE_UI").is_some(); - let update_file_name = config::RUNTIME_DIR.join("check_update"); + let update_file_name = config::DATA_DIR.join("check_update"); let delay = update_file_name .metadata() .and_then(|metadata| metadata.modified())