Added more accurate logic for @ expansion

This commit is contained in:
2026-02-23 21:16:29 -05:00
parent 9361c561b4
commit 39893b3a1f
2 changed files with 9 additions and 10 deletions

View File

@@ -37,6 +37,8 @@ pub const PROC_SUB_OUT: char = '\u{fdd6}';
/// which breaks some commands /// which breaks some commands
pub const NULL_EXPAND: char = '\u{fdd7}'; pub const NULL_EXPAND: char = '\u{fdd7}';
pub const ARG_SEP: char = '\u{fdd8}';
impl Tk { impl Tk {
/// Create a new expanded token /// Create a new expanded token
pub fn expand(self) -> ShResult<Self> { pub fn expand(self) -> ShResult<Self> {
@@ -104,6 +106,9 @@ impl Expander {
DUB_QUOTE | SNG_QUOTE | SUBSH => { DUB_QUOTE | SNG_QUOTE | SUBSH => {
while let Some(q_ch) = chars.next() { while let Some(q_ch) = chars.next() {
match q_ch { match q_ch {
ARG_SEP if ch == DUB_QUOTE => {
words.push(mem::take(&mut cur_word));
}
_ if q_ch == ch => { _ if q_ch == ch => {
was_quoted = true; was_quoted = true;
continue 'outer; // Isn't rust cool continue 'outer; // Isn't rust cool
@@ -112,7 +117,7 @@ impl Expander {
} }
} }
} }
_ if is_field_sep(ch) => { _ if is_field_sep(ch) || ch == ARG_SEP => {
if cur_word.is_empty() && !was_quoted { if cur_word.is_empty() && !was_quoted {
cur_word.clear(); cur_word.clear();
} else { } else {

View File

@@ -10,16 +10,10 @@ use std::{
use nix::unistd::{User, gethostname, getppid}; use nix::unistd::{User, gethostname, getppid};
use crate::{ use crate::{
builtin::trap::TrapTarget, builtin::trap::TrapTarget, exec_input, expand::ARG_SEP, jobs::JobTab, libsh::{
exec_input,
jobs::JobTab,
libsh::{
error::{ShErr, ShErrKind, ShResult}, error::{ShErr, ShErrKind, ShResult},
utils::VecDequeExt, utils::VecDequeExt,
}, }, parse::{ConjunctNode, NdRule, Node, ParsedSrc}, prelude::*, shopt::ShOpts
parse::{ConjunctNode, NdRule, Node, ParsedSrc},
prelude::*,
shopt::ShOpts,
}; };
pub struct Fern { pub struct Fern {
@@ -603,7 +597,7 @@ impl VarTab {
fn update_arg_params(&mut self) { fn update_arg_params(&mut self) {
self.set_param( self.set_param(
ShellParam::AllArgs, ShellParam::AllArgs,
&self.sh_argv.clone().to_vec()[1..].join(" "), &self.sh_argv.clone().to_vec()[1..].join(&ARG_SEP.to_string()),
); );
self.set_param(ShellParam::ArgCount, &(self.sh_argv.len() - 1).to_string()); self.set_param(ShellParam::ArgCount, &(self.sh_argv.len() - 1).to_string());
} }