Closed futurist closed 11 months ago
Added simple escaping (take args in quotes), this will work almost for every case, but would fail if the argument contains a single quote.
@melonamin FYI single-quoting all args seems to break a few things in my experience - in prior versions, it's valid to specify a param containing spaces by encapsulating it in quotes. But now, it causes the param to get double quoted, and breaks it. The most obvious example is when plugins use another bash subshell to run something more complicated:
Copy hostname | shell=bash param0=-c param1="hostname | pbcopy"
That's a trivial example, but the bitbar/xbar plugin libraries contain real examples just like this, and I've run into this issue with my own plugins as well. I don't have a workaround at the moment - it's either impractical or impossible to break down these things to individual params (e.g. the above wouldn't work, you can't quote an individual pipe character). Unfortunately I don't think quoting all params is a workable solution
Ok, broke faster than I expected... I'll take another go
If you could avoid the double quoting (i.e. don't quote an already-quoted string, so that params containing spaces can still be used), it might work. There's varying degrees of sophistication you could apply - from full on shell lexical parsing (a bit like python's shlex
module), to just testing if the string is already surrounded by quotes.
Maybe something like:
let quotedStringRegex = #/^(?:'.*'|".*")$/#
return out.map {
if $0.firstMatch(of: quotedStringRegex) == nil {
"'\($0)'"
} else {
$0
}
}
(My swift is terrible, but you get the idea)
I've updated the logic a bit, check it out in the latest public release
Probably related to: https://github.com/swiftbar/SwiftBar/issues/308
Describe the bug
If plugin contains below line:
The terminal will show
syntax error
if$name
isabc(123)
To Reproduce Steps to reproduce the behavior:
Expected behavior
params should be passed to bash script correctly (in quote?)
Environment:
Plugin Example:
Additional Context:
when
name='abc (123)'
(a space in it), the code works, but not whenabc(123)