Biont / sway-launcher-desktop

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

feature request: fall back to use default list/launch/preview if not specified in custom provider #51

Closed bdefore closed 2 years ago

bdefore commented 2 years ago

I'd like to have my launcher focus on an already opened instance of an application or run a new one if one isn't running. This library works in the fashion I'd like when run from terminal: https://gitlab.com/wef/dotfiles/-/blob/master/bin/sway-run-or-raise. Stretch goal: shift-enter overrides this behavior and opens a new instance anyway (useful for say terminals)

I've authored the following custom provider in ~/.config/sway-launcher-desktop/providers.conf:

[my-provider]
launch_cmd=$HOME/.config/sway-launcher-desktop/scripts/sway-run-or-raise ${1}

When i run sway-launcher-desktop I see what looks like the launcher is broken. Output of 0/0 and nothing I type matches. From what I gather in this conversation https://github.com/Biont/sway-launcher-desktop/issues/41 all three items are required to be specified in provider configs. But it's not clear to me what I should specify in a provider if I want default behavior.

Currently it looks like https://github.com/Biont/sway-launcher-desktop/blob/master/sway-launcher-desktop.sh#L35-L37 bails on setting up the provider unless all three are provided. Perhaps this could be modified to fallback to default behavior per-item instead?

Biont commented 2 years ago

Yeah, the structure of a custom provider is described in the readme and all 3 need to be present. Fallbacks or inheritance are difficult since as you have noticed, the script currently ignores the builtin providers if custom ones are specified.

I actually think what would work for you is a way to execute run-or-raise instead of setsid /bin/sh -c. This would catch any provider. Maybe a new environment variable could be introduced for this.

The other way would in fact be to make your provider complete, which would probably look similar to this: (I really just pieced this together in the browser to give you an idea. I'd be surprised if it actually works, but it should help you get there)

[xdg-run-or-raise]
list_cmd=$HOME/sway-launcher-desktop.sh list-entries
preview_cmd=$HOME/sway-launcher-desktop.sh describe-desktop {1}
launch_cmd=$HOME/.config/sway-launcher-desktop/scripts/sway-run-or-raise $($HOME/sway-launcher-desktop.sh generate-command {1} {2})

Does this help you?

bdefore commented 2 years ago

i didn't think to have sway-launcher execute itself for the two command i'm not interested in overriding. i'll give this a shot and report back if it doesn't work. thanks.

bdefore commented 2 years ago

I can confirm that this appears to work, although at the top of the launcher I see:

/usr/bin/sway-launcher-desktop: Error on line
  240: [ --n "${PROVIDER_ARGS[1]}"  ]

My provider config:

[my-provider]
list_cmd=sway-launcher-desktop list-entries
preview_cmd=sway-launcher-desktop describe-desktop {1}
launch_cmd=$HOME/.config/sway-launcher-desktop/scripts/sway-run-or-raise ${1}

Same behavior if pointing the top two lines to a clone of this repo at $HOME/code/sway-launcher-desktop/sway-launcher-desktop.sh

Unrelated to this library, but as I've configured the sway-run-or-raise only raises if opening something in the same workspace.

In my Manjaro Sway edition, I've changed /etc/sway/definitions to specify my provider:

set $menu exec $term_float_portrait sway-launcher-desktop provider my-provider