mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 00:41:15 -03:00
Extract function for program name
This commit is contained in:
@@ -11,7 +11,8 @@
|
|||||||
use super::prelude::*;
|
use super::prelude::*;
|
||||||
use crate::ast::{self, Ast, Kind, Leaf, Node, NodeVisitor, SourceRangeList, Traversal};
|
use crate::ast::{self, Ast, Kind, Leaf, Node, NodeVisitor, SourceRangeList, Traversal};
|
||||||
use crate::common::{
|
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::EnvStack;
|
||||||
use crate::env::env_init;
|
use crate::env::env_init;
|
||||||
@@ -960,7 +961,7 @@ enum OutputType {
|
|||||||
'v' => {
|
'v' => {
|
||||||
streams.out.appendln(wgettext_fmt!(
|
streams.out.appendln(wgettext_fmt!(
|
||||||
"%s, version %s",
|
"%s, version %s",
|
||||||
PROGRAM_NAME.get().unwrap(),
|
get_program_name(),
|
||||||
crate::BUILD_VERSION
|
crate::BUILD_VERSION
|
||||||
));
|
));
|
||||||
return Ok(SUCCESS);
|
return Ok(SUCCESS);
|
||||||
@@ -988,7 +989,7 @@ enum OutputType {
|
|||||||
if output_type == OutputType::File {
|
if output_type == OutputType::File {
|
||||||
streams.err.appendln(wgettext_fmt!(
|
streams.err.appendln(wgettext_fmt!(
|
||||||
"Expected file path to read/write for -w:\n\n $ %s -w foo.fish",
|
"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);
|
return Err(STATUS_CMD_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
builtins::shared::BUILTIN_ERR_UNKNOWN,
|
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},
|
env::{EnvStack, Environment, env_init},
|
||||||
future_feature_flags,
|
future_feature_flags,
|
||||||
input_common::{
|
input_common::{
|
||||||
@@ -199,7 +199,7 @@ fn parse_flags(
|
|||||||
'v' => {
|
'v' => {
|
||||||
streams.out.appendln(wgettext_fmt!(
|
streams.out.appendln(wgettext_fmt!(
|
||||||
"%s, version %s",
|
"%s, version %s",
|
||||||
PROGRAM_NAME.get().unwrap(),
|
get_program_name(),
|
||||||
crate::BUILD_VERSION
|
crate::BUILD_VERSION
|
||||||
));
|
));
|
||||||
return ControlFlow::Break(Ok(SUCCESS));
|
return ControlFlow::Break(Ok(SUCCESS));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::os::unix::prelude::*;
|
use std::os::unix::prelude::*;
|
||||||
|
|
||||||
use super::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::env::config_paths::get_fish_path;
|
||||||
use crate::future_feature_flags::{self as features, feature_test};
|
use crate::future_feature_flags::{self as features, feature_test};
|
||||||
use crate::proc::{
|
use crate::proc::{
|
||||||
@@ -708,7 +708,7 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
|||||||
if !command.is_empty() {
|
if !command.is_empty() {
|
||||||
streams.out.appendln(command);
|
streams.out.appendln(command);
|
||||||
} else {
|
} else {
|
||||||
streams.out.appendln(*PROGRAM_NAME.get().unwrap());
|
streams.out.appendln(get_program_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STATUS_CURRENT_COMMANDLINE => {
|
STATUS_CURRENT_COMMANDLINE => {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use super::prelude::*;
|
use super::prelude::*;
|
||||||
use crate::common;
|
|
||||||
use crate::future_feature_flags::{FeatureFlag, feature_test};
|
use crate::future_feature_flags::{FeatureFlag, feature_test};
|
||||||
use crate::should_flog;
|
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.
|
/// 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 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
|
/// 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.
|
/// 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
|
/// 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 crate::{FLOG, FLOGF};
|
||||||
use fish_build_helper::workspace_root;
|
use fish_build_helper::workspace_root;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -152,7 +152,7 @@ pub fn get_fish_path() -> &'static PathBuf {
|
|||||||
|
|
||||||
fn compute_fish_path() -> PathBuf {
|
fn compute_fish_path() -> PathBuf {
|
||||||
let Ok(path) = std::env::current_exe() else {
|
let Ok(path) = std::env::current_exe() else {
|
||||||
assert!(PROGRAM_NAME.get().unwrap() == "fish");
|
assert!(get_program_name() == "fish");
|
||||||
return PathBuf::from("fish");
|
return PathBuf::from("fish");
|
||||||
};
|
};
|
||||||
assert!(path.is_absolute());
|
assert!(path.is_absolute());
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{PROGRAM_NAME, read_blocked},
|
common::{get_program_name, read_blocked},
|
||||||
nix::isatty,
|
nix::isatty,
|
||||||
threads::{asan_maybe_exit, is_main_thread},
|
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() {
|
if let Some(at_exit) = AT_EXIT.get() {
|
||||||
(at_exit)();
|
(at_exit)();
|
||||||
}
|
}
|
||||||
eprintf!(
|
eprintf!("%s crashed, please report a bug.", get_program_name());
|
||||||
"%s crashed, please report a bug.",
|
|
||||||
PROGRAM_NAME.get().unwrap(),
|
|
||||||
);
|
|
||||||
if !is_main_thread() {
|
if !is_main_thread() {
|
||||||
eprintf!("\n");
|
eprintf!("\n");
|
||||||
std::thread::sleep(Duration::from_secs(1));
|
std::thread::sleep(Duration::from_secs(1));
|
||||||
|
|||||||
@@ -54,9 +54,9 @@
|
|||||||
use crate::builtins::shared::STATUS_CMD_OK;
|
use crate::builtins::shared::STATUS_CMD_OK;
|
||||||
use crate::common::ScopeGuarding;
|
use crate::common::ScopeGuarding;
|
||||||
use crate::common::{
|
use crate::common::{
|
||||||
EscapeFlags, EscapeStringStyle, PROGRAM_NAME, ScopeGuard, UTF8_BOM_WCHAR, bytes2wcstring,
|
EscapeFlags, EscapeStringStyle, ScopeGuard, UTF8_BOM_WCHAR, bytes2wcstring, escape,
|
||||||
escape, escape_string, exit_without_destructors, get_ellipsis_char, get_obfuscation_read_char,
|
escape_string, exit_without_destructors, get_ellipsis_char, get_obfuscation_read_char,
|
||||||
restore_term_foreground_process_group_for_exit, shell_modes, write_loop,
|
get_program_name, restore_term_foreground_process_group_for_exit, shell_modes, write_loop,
|
||||||
};
|
};
|
||||||
use crate::complete::{
|
use crate::complete::{
|
||||||
CompleteFlags, Completion, CompletionList, CompletionRequestOptions, complete, complete_load,
|
CompleteFlags, Completion, CompletionList, CompletionRequestOptions, complete, complete_load,
|
||||||
@@ -306,7 +306,7 @@ pub fn terminal_init(vars: &dyn Environment, inputfd: RawFd) -> InputEventQueue
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CharEvent::QueryResult(Timeout) => {
|
CharEvent::QueryResult(Timeout) => {
|
||||||
let program = PROGRAM_NAME.get().unwrap();
|
let program = get_program_name();
|
||||||
FLOG!(
|
FLOG!(
|
||||||
warning,
|
warning,
|
||||||
wgettext_fmt!(
|
wgettext_fmt!(
|
||||||
@@ -5875,13 +5875,11 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes {
|
|||||||
term_steal(eval_res.status.is_success());
|
term_steal(eval_res.status.is_success());
|
||||||
|
|
||||||
// Provide value for `status current-command`
|
// 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
|
// Also provide a value for the deprecated fish 2.0 $_ variable
|
||||||
parser.vars().set_one(
|
parser
|
||||||
L!("_"),
|
.vars()
|
||||||
EnvMode::GLOBAL,
|
.set_one(L!("_"), EnvMode::GLOBAL, get_program_name().to_owned());
|
||||||
(*PROGRAM_NAME.get().unwrap()).to_owned(),
|
|
||||||
);
|
|
||||||
// Provide value for `status current-commandline`
|
// Provide value for `status current-commandline`
|
||||||
parser.libdata_mut().status_vars.commandline = L!("").to_owned();
|
parser.libdata_mut().status_vars.commandline = L!("").to_owned();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user