swiftbar / SwiftBar

Powerful macOS menu bar customization tool
https://swiftbar.app
MIT License
2.93k stars 92 forks source link

Shell calls are limited to 10 parameters #219

Closed shassard closed 3 years ago

shassard commented 3 years ago

SwiftBar is currently limited to processing a maximum of 10 parameters for a shell call:

https://github.com/swiftbar/SwiftBar/blob/4e6f77e176f42745a56047013bf0bc7d0d4f56a3/SwiftBar/MenuBar/MenuLineParameters.swift#L56

xbar will process an unlimited number scanning for keys prefixed with param: https://github.com/matryer/xbar/blob/3e6f4a0b9a3a526a86779f4080beb5cacb3c9d0f/pkg/plugins/item_params.go#L255-L269

This results in some compatibility issues with xbar when using > 10 arguments for a shell call.

It seems easy enough to change 10 to 20 to increase this limit and make this less common, but that doesn't seem like a great solution.

shassard commented 3 years ago

You might be able to do something like this (mind that I don't have xcode available at the moment to test this):


diff --git a/SwiftBar/MenuBar/MenuLineParameters.swift b/SwiftBar/MenuBar/MenuLineParameters.swift
index b1ecfda..b87d145 100644
--- a/SwiftBar/MenuBar/MenuLineParameters.swift
+++ b/SwiftBar/MenuBar/MenuLineParameters.swift
@@ -53,7 +53,8 @@ struct MenuLineParameters {

     var bashParams: [String] {
         var out: [String] = []
-        for i in 0 ... 10 {
+        let sortedParams = Array(params.keys).sorted {(s1, s2) -> Bool in return s1.localizedStandardCompare(s2) == .orderedAscending}
+        for i in sortedParams {
             guard let param = params["param\(i)"] else { continue }
             out.append(param.escaped())
         }
melonamin commented 3 years ago

@shassard thank you both for suggestion and the code snippet!