SwiftBar icon indicating copy to clipboard operation
SwiftBar copied to clipboard

Shell action can't parse element like '&&' correctly

Open jiengup opened this issue 2 years ago • 7 comments

As in https://github.com/matryer/xbar-plugins/blob/main/Dev/Homebrew/brew-updates.1h.rb#L306 if writing in ruby like:

if all_casks.size.positive?
            cmds << '&&' if cmds.size.positive?
            cmds += [brew_path, 'upgrade', '--cask'] +
                    all_casks.map(&:name)
          end

          printer.item(
            "⬆️ Upgrade All (#{all_formulas.size + all_casks.size})",
            terminal: true, refresh: true,
            bash: (cmds + post_commands).flatten
          )

then the shell will run like this:

/opt/homebrew/bin/brew upgrade --formula c-ares cmake coreutils d2 fd
 gawk gcc git-lfs go gperftools lf libpthread-stubs libssh lua mpfr node openssl
@1.1 [email protected] qemu smartmontools texinfo tree typst wimlib yarn '&&' /opt/homebrew/bin/brew upgrade --cask ipatool

however zsh can not accept '&&' as && or ';' as ; and raise an error.

jiengup avatar Jan 04 '24 06:01 jiengup

@jiengup I'm not sure what is the question here.

You can either rewrite the plugin to generate a zsh compatable script, or switch execution in SwiftBar from zsh to bash.

melonamin avatar Jan 04 '24 11:01 melonamin

@jiengup I'm not sure what is the question here.

You can either rewrite the plugin to generate a zsh compatable script, or switch execution in SwiftBar from zsh to bash.

I think it may be that swiftbar's string parser does something like "add quotas between some specific string"? Cause when I choice "run in terminal" and get something like

--⬆️ Upgrade All (26) | terminal="true" refresh="true" bash="/opt/homebrew/bin/brew" param1="upgrade" param2="--formula" param3="c-ares" param4="cmake" param5="coreutils" param6="d2" param7="fd" param8="gawk" param9="gcc" param10="git-lfs" param11="go" param12="gperftools" param13="lf" param14="libpthread-stubs" param15="libssh" param16="lua" param17="mpfr" param18="node" param19="[email protected]" param20="[email protected]" param21="qemu" param22="smartmontools" param23="texinfo" param24="tree" param25="typst" param26="wimlib" param27="yarn" param28="&&" param29="/opt/homebrew/bin/brew" param30="upgrade" param31="--cask" param32="ipatool"

Please notice param28 above But when I click this ⬆️ Upgrade All (26) in menubar, the terminal will run:

/opt/homebrew/bin/brew upgrade --formula c-ares cmake coreutils d2 fd
gawk gcc git-lfs go gperftools lf libpthread-stubs libssh lua mpfr node openssl@
1.1 [email protected] qemu smartmontools texinfo tree typst wimlib yarn '&&' /opt/homebrew/bin/brew upgrade --cask ipatool

Plese notice '&&' above, other params can be parsed without ', which work perfectly. And the shell will not recognize this expression and take '&&' as some kind of parameters then fail to run.

Please tell me if I'm mistaken on this issue and if it's because of some features of zsh or ruby language.

jiengup avatar Jan 04 '24 12:01 jiengup

Ah, got it. Sorry, early morning comment:)

Yeah, you're right, this is might be quating\escaping I've added in the latest release, let me look into it.

melonamin avatar Jan 04 '24 13:01 melonamin

@jiengup can you check if beta build fixes this?

melonamin avatar Jan 04 '24 19:01 melonamin

@melonamin Yep, I just install beta build and test it. It works perfectly. Nice job! I'll keep using this beta version and give feedback. Thank you for getting back to me.

jiengup avatar Jan 05 '24 02:01 jiengup

@melonamin Sorry, I found it will not work perfectly when I write in python like

bash="/usr/bin/vim", param1="~/.vimrc"

Swiftbar will produce output /usr/bin/vim "~/.vimrc" and vim will take it as a directory instead of a normal file. image I think it's related to this issue.

jiengup avatar Jan 07 '24 03:01 jiengup

I came here after digging around with the same issue, formerly-working && in params now not working in 2.0. Using the beta build fixes it for me, too.

incanus avatar Jan 12 '24 17:01 incanus