How to get the orginal function arguments text? to get the orginal quoting? #18804
Replies: 5 comments 3 replies
|
Why do you want that? I have a feeling that you are trying to solve the wrong problem. What's your usecase? |
|
The literal thing you're asking for — the original source text of the arguments, quotes included — isn't available to a custom command: the parser consumes quoting before your function sees anything, and there's no "raw span" accessor. But for the actual use case (wrapping
def su-do [cmd: string] { ^su -c $cmd }
su-do "echo 'good (:' && whoami"This is the most faithful equivalent of how
def --wrapped su-do [...args] { ^su -c ($args | str join ' ') }
So: keep |
|
Nice thanks @hoangperry i didn’t think about that!
Weird you can’t just use ‘cmd: string’ with ‘—wrapped’?
…On Sun, 16 Aug 2026 at 6:25 PM Hoang N. Truong < ***@***.***> wrote:
The literal thing you're asking for — the original source text of the
arguments, quotes included — isn't available to a custom command: the
parser consumes quoting before your function sees anything,
*DuckDuckGo* removed one tracker. More
<https://duckduckgo.com/-omA2L5Il_qxkCQOZVdagfAh_grYAi3ZtHp6nttispXSB6I65W1PuwM2eXD3xI8yizW_us4bsuy6DixCLPaAbThhDaxKQ505tYU6tEjCNrU5t3NPpH7ZWq7-YXo2rtmy_VtdZ-oOsC4pCHQATFsr0rTP8CER2rQmPLR_HKlL0PAIj2Kpm5xv-zWCiTjovVWjUJXhfIuNR9e3byTogR6nHEl40iYLHnHpbQK7ShcXL5IMa15f87LOQDEPS7K1HF2eosXe-jrdg_sE99rAJwB74tAtviStB6ouK8rwVyZrSvOJhXaqeMcZbfbAZzrbXdiOiB7hTKAwKPxkmgX9wEKiQXI8EIUDBwFPEy1_37oAzu5La-n8V4aOMGqlaP9xHT4t2P8zUHT0s3wJ3N7rM9mfIZia9rAKP33eIV0og7l5DCil5N69-giuJ9phpPGktomj_QS0OkozUmzZbm9kCEn8Xz9mHTB1t0SPSFicXWPoFKPh7mcOwKpr_dDD-B4hF4e4HxDocT-sXEJGVIctwCYaInjdL6-PLNhby4Qbc74eFRuUNDnfm9HcsWHTVXkdpTqUN5nWRDmswcc-GDuj4PEPWzTMetj4ezML_X08j6Fyrpc7Q8>
Report Spam
<https://duckduckgo.com/-omA2L5Il_qxkCQOZVdagfAh_grYAi3ZtHp6nttispXSB6I65W1PuwM2eXD3xI8yizW_us4bsuy6DixCLPaAbThhDaxKQ505tYU6tEjCNrU5t3NPpH7ZWq7-YXo2rtmy_VtdZ-oOsC4pCHQATFsr0rTP8CER2rQmPLR_HKlL0PAIj2Kpm5xv-zWCiTjovVWjUJXhfIuNR9e3byTogR6nHEl40iYLHnHpbQK7ShcXL5IMa15f87LOQDEPS7K1HF2eosXe-jrdg_sE99rAJwB74tAtviStB6ouK8rwVyZrSvOJhXaqeMcZbfbAZzrbXdiOiB7hTKAwKPxkmgX9wEKiQXI8EIUDBwFPEy1_37oAzu5La-n8V4aOMGqlaP9xHT4t2P8zUHT0s3wJ3N7rM9mfIZia9rAKP33eIV0og7l5DCil5N69-giuJ9phpPGktomj_QS0OkozUmzZbm9kCEn8Xz9mHTB1t0SPSFicXWPoFKPh7mcOwKpr_dDD-B4hF4e4HxDocT-sXEJGVIctwCYaInjdL6-PLNhby4Qbc74eFRuUNDnfm9HcsWHTVXkdpTqUN5nWRDmswcc-GDuj4PEPWzTMetj4ezML_X08j6Fyrpc7Q8>
The literal thing you're asking for — the original source text of the
arguments, quotes included — isn't available to a custom command: the
parser consumes quoting before your function sees anything, and there's no
"raw span" accessor. But for the actual use case (wrapping su -c, which
needs the whole command as one argument), you don't need the original text
— you need to stop nushell from splitting, and there are two working
patterns:
1. *Take the command as a single string yourself* — the caller quotes
once, you pass it through untouched:
def su-do [cmd: string] { ^su -c $cmd }
su-do "echo 'good (:' && whoami"
This is the most faithful equivalent of how su -c is used in POSIX shells
anyway — the command is *one* string there too, so asking callers for one
quoted string isn't a workaround, it's the native shape of the interface.
2. *If you want loose arguments, use def --wrapped and rejoin:*
def --wrapped su-do [...args] { ^su -c ($args | str join ' ') }
--wrapped stops nushell from interpreting flags (so -l, --foo pass
through), but note the honest limitation: by the time $args exists, the *original
quoting* is gone — su-do echo "a b" rejoins to echo a b, which re-splits
on the far side. That's exactly why pattern 1 is the reliable one for
anything containing quotes or spaces: only a single-string parameter
preserves the command byte-for-byte.
So: keep su -c semantics, accept one string. Raw-source access for
commands has come up before and isn't currently a thing — if you want to
push for it, an issue with this su -c case is a good motivating example.
—
Reply to this email directly, view it on GitHub
<#18804?email_source=notifications&email_token=ASHCX6SGDUB3PYTJKFNY4MD5KHG6BA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCOBQGQYTMNBZUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVRTG633UMVZF6Y3MNFRWW#discussioncomment-18041649>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASHCX6XSC2AHLGB4NBEPCHD5KHG6BAVCNFSNUABIKJSXA33TNF2G64TZHMYTQNRQGI2DEOJYHNCGS43DOVZXG2LPNY5TCMBVG44DIMZYUF3AE>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ASHCX6TUB6G2ZFBTGLV7NUD5KHG6BA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCOBQGQYTMNBZUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVJTG633UMVZF62LPOM>
and Android
<https://github.com/notifications/mobile/android/ASHCX6VOXM5GJHA64GHO3T35KHG6BA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCOBQGQYTMNBZUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVZTG633UMVZF6YLOMRZG62LE>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
You can, as long as there's still a
|
Uh oh!
There was an error while loading. Please reload this page.
like this:
foo "how are you" 'good (:'
I want to get this
"how are you" 'good (:'with no parsingAll reactions