2023-12-22 19:27:01 +08:00
|
|
|
mod abbrs;
|
2023-07-04 03:19:40 +08:00
|
|
|
mod common;
|
2023-10-09 05:22:27 +08:00
|
|
|
mod complete;
|
2023-12-09 23:48:02 +08:00
|
|
|
mod debounce;
|
2023-12-03 01:20:40 +08:00
|
|
|
mod editable_line;
|
2023-12-10 04:20:38 +08:00
|
|
|
mod encoding;
|
2023-10-09 05:22:27 +08:00
|
|
|
mod env;
|
|
|
|
mod env_universal_common;
|
|
|
|
mod expand;
|
2023-03-05 13:49:17 +08:00
|
|
|
mod fd_monitor;
|
2023-10-09 05:22:27 +08:00
|
|
|
mod highlight;
|
|
|
|
mod history;
|
2024-01-22 04:40:43 +08:00
|
|
|
mod input;
|
|
|
|
mod input_common;
|
2023-12-02 23:26:45 +08:00
|
|
|
mod pager;
|
2023-12-10 03:47:43 +08:00
|
|
|
mod parse_util;
|
2023-10-09 05:22:27 +08:00
|
|
|
mod parser;
|
2023-12-22 19:27:01 +08:00
|
|
|
mod reader;
|
2023-10-09 05:22:27 +08:00
|
|
|
mod redirection;
|
2023-11-26 02:40:31 +08:00
|
|
|
mod screen;
|
2024-03-10 12:05:23 +08:00
|
|
|
mod std;
|
2023-07-04 03:19:40 +08:00
|
|
|
mod string_escape;
|
2023-12-10 17:38:06 +08:00
|
|
|
mod threads;
|
2023-09-17 19:42:24 +08:00
|
|
|
mod tokenizer;
|
2023-10-09 05:22:27 +08:00
|
|
|
mod topic_monitor;
|
2023-12-10 00:10:36 +08:00
|
|
|
mod wgetopt;
|
2023-10-09 05:22:27 +08:00
|
|
|
|
2024-01-04 03:57:28 +08:00
|
|
|
pub mod prelude {
|
|
|
|
use crate::env::{env_init, misc_init};
|
|
|
|
use crate::reader::reader_init;
|
|
|
|
use crate::signal::signal_reset_handlers;
|
2023-10-09 05:22:27 +08:00
|
|
|
pub use crate::tests::env::{PwdEnvironment, TestEnvironment};
|
2024-01-04 03:57:28 +08:00
|
|
|
use crate::topic_monitor::topic_monitor_init;
|
2023-10-09 05:22:27 +08:00
|
|
|
use crate::wutil::wgetcwd;
|
2024-01-04 03:57:28 +08:00
|
|
|
use crate::{env::EnvStack, proc::proc_init};
|
2023-10-09 05:22:27 +08:00
|
|
|
use once_cell::sync::Lazy;
|
2024-01-04 03:57:28 +08:00
|
|
|
use once_cell::sync::OnceCell;
|
2024-01-12 16:11:56 +08:00
|
|
|
use std::env::set_current_dir;
|
2024-01-04 03:57:28 +08:00
|
|
|
use std::ffi::CString;
|
2023-10-09 05:22:27 +08:00
|
|
|
use std::sync::Mutex;
|
|
|
|
|
|
|
|
static PUSHED_DIRS: Lazy<Mutex<Vec<String>>> = Lazy::new(Mutex::default);
|
|
|
|
/// Helper to chdir and then update $PWD.
|
|
|
|
pub fn pushd(path: &str) {
|
|
|
|
let cwd = wgetcwd();
|
|
|
|
PUSHED_DIRS.lock().unwrap().push(cwd.to_string());
|
|
|
|
|
|
|
|
// We might need to create the directory. We don't care if this fails due to the directory
|
|
|
|
// already being present.
|
|
|
|
std::fs::create_dir_all(path).unwrap();
|
|
|
|
|
|
|
|
std::env::set_current_dir(path).unwrap();
|
|
|
|
EnvStack::principal().set_pwd_from_getcwd();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn popd() {
|
|
|
|
let old_cwd = PUSHED_DIRS.lock().unwrap().pop().unwrap();
|
|
|
|
std::env::set_current_dir(old_cwd).unwrap();
|
|
|
|
EnvStack::principal().set_pwd_from_getcwd();
|
|
|
|
}
|
2024-01-04 03:57:28 +08:00
|
|
|
|
|
|
|
pub fn test_init() {
|
|
|
|
static DONE: OnceCell<()> = OnceCell::new();
|
|
|
|
DONE.get_or_init(|| {
|
2024-01-12 16:11:56 +08:00
|
|
|
set_current_dir(env!("FISH_BUILD_DIR")).unwrap();
|
2024-01-04 03:57:28 +08:00
|
|
|
{
|
|
|
|
let s = CString::new("").unwrap();
|
|
|
|
unsafe {
|
|
|
|
libc::setlocale(libc::LC_ALL, s.as_ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
topic_monitor_init();
|
|
|
|
crate::threads::init();
|
|
|
|
proc_init();
|
|
|
|
env_init(None, true, false);
|
|
|
|
misc_init();
|
|
|
|
reader_init();
|
|
|
|
|
|
|
|
// Set default signal handlers, so we can ctrl-C out of this.
|
|
|
|
signal_reset_handlers();
|
|
|
|
|
|
|
|
// Set PWD from getcwd - fixes #5599
|
|
|
|
EnvStack::principal().set_pwd_from_getcwd();
|
|
|
|
});
|
|
|
|
}
|
2024-01-04 03:57:28 +08:00
|
|
|
|
|
|
|
pub use serial_test::serial;
|
2023-10-09 05:22:27 +08:00
|
|
|
}
|