Biont / sway-launcher-desktop

TUI Application launcher with Desktop Entry support. Made for SwayWM, but runs anywhere
GNU General Public License v3.0
607 stars 28 forks source link

Allow arbitrary Command input #28

Closed jhbruhn closed 3 years ago

jhbruhn commented 3 years ago

Regarding #27, I implemented this first (dirty, see code) version of executing arbitrary commands. It works by parsing the output of fzf with --print-query enabled. If there is only one line (the query), it constructs a synthetic command-entry and launches that.

Please critique this code heavily as I am not a regular shell programmer.

Biont commented 3 years ago

Thanks! What bothers me a bit is that

  1. There's a little too much process substitution and piping going on here when pure bash (using readarray and the array-based parameter expansion methods) would probably work a lot faster
  2. this solution relies on the command provider being present. Maybe this kind of fallback behaviour can/should actually be something hardcoded into the launcher (->as a mandatory provider that's always present).

Side note: I've been wondering if it would be possible to use this approach as an alternative to inspecting the number of returned lines. But the way it's currently written requires us to pass the fzf result into one of the available providers and I see no way to format the query in a compatible fashion using the tools provided by fzf.

I feel like this would really benefit from a little extra legwork, but I need to think it through for a bit...

jhbruhn commented 3 years ago

An alternative to formatting the pseudo-query for the command-provider would be to add a plan-command provider which does not list anything and, if enabled, is only used as a fallback provider and then match the plain-text query. I will have a look as soon as I find the time to do so.

Biont commented 3 years ago

1ac6d76

Thank you for the discussion and putting putting in the work for this PR. I have implemented a solution that addresses the concerns in the above commit