mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 12:45:13 +00:00
Shorthand for escaping with default options
Should probably do this on the C++ side too.
This commit is contained in:
parent
19fe0f6a91
commit
6c07af9343
3 changed files with 9 additions and 4 deletions
|
@ -4,7 +4,7 @@ use crate::builtins::shared::{
|
||||||
builtin_unknown_option, io_streams_t, BUILTIN_ERR_TOO_MANY_ARGUMENTS, STATUS_CMD_ERROR,
|
builtin_unknown_option, io_streams_t, BUILTIN_ERR_TOO_MANY_ARGUMENTS, STATUS_CMD_ERROR,
|
||||||
STATUS_CMD_OK, STATUS_INVALID_ARGS,
|
STATUS_CMD_OK, STATUS_INVALID_ARGS,
|
||||||
};
|
};
|
||||||
use crate::common::{escape_string, valid_func_name, EscapeStringStyle};
|
use crate::common::{escape, escape_string, valid_func_name, EscapeStringStyle};
|
||||||
use crate::env::status::{ENV_NOT_FOUND, ENV_OK};
|
use crate::env::status::{ENV_NOT_FOUND, ENV_OK};
|
||||||
use crate::env::EnvMode;
|
use crate::env::EnvMode;
|
||||||
use crate::ffi::parser_t;
|
use crate::ffi::parser_t;
|
||||||
|
@ -415,7 +415,7 @@ fn abbr_erase(opts: &Options, parser: &mut parser_t) -> Option<c_int> {
|
||||||
result = Some(ENV_NOT_FOUND);
|
result = Some(ENV_NOT_FOUND);
|
||||||
}
|
}
|
||||||
// Erase the old uvar - this makes `abbr -e` work.
|
// Erase the old uvar - this makes `abbr -e` work.
|
||||||
let esc_src = escape_string(arg, EscapeStringStyle::Script(Default::default()));
|
let esc_src = escape(arg);
|
||||||
if !esc_src.is_empty() {
|
if !esc_src.is_empty() {
|
||||||
let var_name = WString::from_str("_fish_abbr_") + esc_src.as_utfstr();
|
let var_name = WString::from_str("_fish_abbr_") + esc_src.as_utfstr();
|
||||||
let ret = parser.remove_var(&var_name, EnvMode::UNIVERSAL.into());
|
let ret = parser.remove_var(&var_name, EnvMode::UNIVERSAL.into());
|
||||||
|
|
|
@ -140,6 +140,11 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replace special characters with backslash escape sequences. Newline is replaced with `\n`, etc.
|
||||||
|
pub fn escape(s: &wstr) -> WString {
|
||||||
|
escape_string(s, EscapeStringStyle::Script(EscapeFlags::default()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Replace special characters with backslash escape sequences. Newline is replaced with `\n`, etc.
|
/// Replace special characters with backslash escape sequences. Newline is replaced with `\n`, etc.
|
||||||
pub fn escape_string(s: &wstr, style: EscapeStringStyle) -> WString {
|
pub fn escape_string(s: &wstr, style: EscapeStringStyle) -> WString {
|
||||||
match style {
|
match style {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{escape_string, EscapeStringStyle},
|
common::escape,
|
||||||
ffi::{self, parser_t, wcharz_t, wcstring_list_ffi_t},
|
ffi::{self, parser_t, wcharz_t, wcstring_list_ffi_t},
|
||||||
global_safety::RelaxedAtomicBool,
|
global_safety::RelaxedAtomicBool,
|
||||||
wchar::{self, wstr, L},
|
wchar::{self, wstr, L},
|
||||||
|
@ -61,7 +61,7 @@ pub fn trace_argv(parser: &parser_t, command: &wstr, args: &[&wstr]) {
|
||||||
}
|
}
|
||||||
for arg in args {
|
for arg in args {
|
||||||
trace_text.push(' ');
|
trace_text.push(' ');
|
||||||
trace_text.push_utfstr(&escape_string(arg, EscapeStringStyle::default()));
|
trace_text.push_utfstr(&escape(arg));
|
||||||
}
|
}
|
||||||
trace_text.push('\n');
|
trace_text.push('\n');
|
||||||
ffi::log_extra_to_flog_file(&trace_text.to_ffi());
|
ffi::log_extra_to_flog_file(&trace_text.to_ffi());
|
||||||
|
|
Loading…
Reference in a new issue