diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index bb48c7617..5d921d7c6 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -11,7 +11,8 @@ use super::prelude::*; use crate::ast::{self, Ast, Kind, Leaf, Node, NodeVisitor, SourceRangeList, Traversal}; use crate::common::{ - PROGRAM_NAME, UnescapeFlags, UnescapeStringStyle, bytes2wcstring, unescape_string, wcs2bytes, + PROGRAM_NAME, UnescapeFlags, UnescapeStringStyle, bytes2wcstring, get_program_name, + unescape_string, wcs2bytes, }; use crate::env::EnvStack; use crate::env::env_init; @@ -960,7 +961,7 @@ enum OutputType { 'v' => { streams.out.appendln(wgettext_fmt!( "%s, version %s", - PROGRAM_NAME.get().unwrap(), + get_program_name(), crate::BUILD_VERSION )); return Ok(SUCCESS); @@ -988,7 +989,7 @@ enum OutputType { if output_type == OutputType::File { streams.err.appendln(wgettext_fmt!( "Expected file path to read/write for -w:\n\n $ %s -w foo.fish", - PROGRAM_NAME.get().unwrap() + get_program_name() )); return Err(STATUS_CMD_ERROR); } diff --git a/src/builtins/fish_key_reader.rs b/src/builtins/fish_key_reader.rs index 8bfde4593..94f017352 100644 --- a/src/builtins/fish_key_reader.rs +++ b/src/builtins/fish_key_reader.rs @@ -13,7 +13,7 @@ use crate::{ builtins::shared::BUILTIN_ERR_UNKNOWN, - common::{PROGRAM_NAME, bytes2wcstring, shell_modes}, + common::{PROGRAM_NAME, bytes2wcstring, get_program_name, shell_modes}, env::{EnvStack, Environment, env_init}, future_feature_flags, input_common::{ @@ -199,7 +199,7 @@ fn parse_flags( 'v' => { streams.out.appendln(wgettext_fmt!( "%s, version %s", - PROGRAM_NAME.get().unwrap(), + get_program_name(), crate::BUILD_VERSION )); return ControlFlow::Break(Ok(SUCCESS)); diff --git a/src/builtins/status.rs b/src/builtins/status.rs index 26481784a..40c565a32 100644 --- a/src/builtins/status.rs +++ b/src/builtins/status.rs @@ -1,7 +1,7 @@ use std::os::unix::prelude::*; use super::prelude::*; -use crate::common::{PROGRAM_NAME, bytes2wcstring}; +use crate::common::{bytes2wcstring, get_program_name}; use crate::env::config_paths::get_fish_path; use crate::future_feature_flags::{self as features, feature_test}; use crate::proc::{ @@ -708,7 +708,7 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B if !command.is_empty() { streams.out.appendln(command); } else { - streams.out.appendln(*PROGRAM_NAME.get().unwrap()); + streams.out.appendln(get_program_name()); } } STATUS_CURRENT_COMMANDLINE => { diff --git a/src/builtins/test.rs b/src/builtins/test.rs index 9d8a544be..5834e1f70 100644 --- a/src/builtins/test.rs +++ b/src/builtins/test.rs @@ -1,5 +1,4 @@ use super::prelude::*; -use crate::common; use crate::future_feature_flags::{FeatureFlag, feature_test}; use crate::should_flog; diff --git a/src/common.rs b/src/common.rs index 90d2b7c9d..d8637c826 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1062,6 +1062,10 @@ pub fn get_obfuscation_read_char() -> char { /// Name of the current program. Should be set at startup. Used by the debug function. pub static PROGRAM_NAME: OnceCell<&'static wstr> = OnceCell::new(); +pub fn get_program_name() -> &'static wstr { + PROGRAM_NAME.get().unwrap() +} + /// MS Windows tty devices do not currently have either a read or write timestamp - those respective /// fields of `struct stat` are always set to the current time, which means we can't rely on them. /// In this case, we assume no external program has written to the terminal behind our back, making diff --git a/src/env/config_paths.rs b/src/env/config_paths.rs index 7776a97cc..45ed91542 100644 --- a/src/env/config_paths.rs +++ b/src/env/config_paths.rs @@ -1,4 +1,4 @@ -use crate::common::{BUILD_DIR, PROGRAM_NAME}; +use crate::common::{BUILD_DIR, get_program_name}; use crate::{FLOG, FLOGF}; use fish_build_helper::workspace_root; use once_cell::sync::OnceCell; @@ -152,7 +152,7 @@ pub fn get_fish_path() -> &'static PathBuf { fn compute_fish_path() -> PathBuf { let Ok(path) = std::env::current_exe() else { - assert!(PROGRAM_NAME.get().unwrap() == "fish"); + assert!(get_program_name() == "fish"); return PathBuf::from("fish"); }; assert!(path.is_absolute()); diff --git a/src/panic.rs b/src/panic.rs index e0638fb4b..f0b76927e 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -8,7 +8,7 @@ use once_cell::sync::OnceCell; use crate::{ - common::{PROGRAM_NAME, read_blocked}, + common::{get_program_name, read_blocked}, nix::isatty, threads::{asan_maybe_exit, is_main_thread}, }; @@ -34,10 +34,7 @@ pub fn panic_handler(main: impl FnOnce() -> i32 + UnwindSafe) -> ! { if let Some(at_exit) = AT_EXIT.get() { (at_exit)(); } - eprintf!( - "%s crashed, please report a bug.", - PROGRAM_NAME.get().unwrap(), - ); + eprintf!("%s crashed, please report a bug.", get_program_name()); if !is_main_thread() { eprintf!("\n"); std::thread::sleep(Duration::from_secs(1)); diff --git a/src/reader.rs b/src/reader.rs index c5c58a9e2..0a1a9f2b2 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -54,9 +54,9 @@ use crate::builtins::shared::STATUS_CMD_OK; use crate::common::ScopeGuarding; use crate::common::{ - EscapeFlags, EscapeStringStyle, PROGRAM_NAME, ScopeGuard, UTF8_BOM_WCHAR, bytes2wcstring, - escape, escape_string, exit_without_destructors, get_ellipsis_char, get_obfuscation_read_char, - restore_term_foreground_process_group_for_exit, shell_modes, write_loop, + EscapeFlags, EscapeStringStyle, ScopeGuard, UTF8_BOM_WCHAR, bytes2wcstring, escape, + escape_string, exit_without_destructors, get_ellipsis_char, get_obfuscation_read_char, + get_program_name, restore_term_foreground_process_group_for_exit, shell_modes, write_loop, }; use crate::complete::{ CompleteFlags, Completion, CompletionList, CompletionRequestOptions, complete, complete_load, @@ -306,7 +306,7 @@ pub fn terminal_init(vars: &dyn Environment, inputfd: RawFd) -> InputEventQueue break; } CharEvent::QueryResult(Timeout) => { - let program = PROGRAM_NAME.get().unwrap(); + let program = get_program_name(); FLOG!( warning, wgettext_fmt!( @@ -5875,13 +5875,11 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes { term_steal(eval_res.status.is_success()); // Provide value for `status current-command` - parser.libdata_mut().status_vars.command = (*PROGRAM_NAME.get().unwrap()).to_owned(); + parser.libdata_mut().status_vars.command = get_program_name().to_owned(); // Also provide a value for the deprecated fish 2.0 $_ variable - parser.vars().set_one( - L!("_"), - EnvMode::GLOBAL, - (*PROGRAM_NAME.get().unwrap()).to_owned(), - ); + parser + .vars() + .set_one(L!("_"), EnvMode::GLOBAL, get_program_name().to_owned()); // Provide value for `status current-commandline` parser.libdata_mut().status_vars.commandline = L!("").to_owned();