mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-04 07:21:14 -03:00
Extract function for program name
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use super::prelude::*;
|
||||
use crate::common;
|
||||
use crate::future_feature_flags::{FeatureFlag, feature_test};
|
||||
use crate::should_flog;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
4
src/env/config_paths.rs
vendored
4
src/env/config_paths.rs
vendored
@@ -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());
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user