From 3429a175db5eb6a9ca9ab93c808b6ed102ab7393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Mei=C3=9Felbach?= Date: Sat, 30 Nov 2019 00:38:56 +0100 Subject: Fix and improve usage of launch_cmd in providers --- README.md | 8 ++++++-- sway-launcher-desktop.sh | 18 ++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 70fbac9..e92a677 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Some of your desktop entries will probably be TUI programs that expect to be lau ## Extending the launcher In addition to desktop application entries and binaries, you can extend `sway-launcher-desktop` with custom item providers. -If will read the configuration of custom item providers from `$HOME/.config/sway-launcher-desktop/providers.conf` +If will read the configuration of custom item providers from `$HOME/.config/sway-launcher-desktop/providers.conf`. The structure looks like this: ``` @@ -50,4 +50,8 @@ The `list_cmd` generated the list of entries. For each entry, it has to print th 1. The item to launch. This will get passed to `preview_cmd` and `launch_cmd` as `{1}` 2. The name of your provider (the same as what what you put inside the brackets, so `my-provider` in this example) 3. The text that appears in the `fzf` window. You might want to prepend it with a glyph and add some color via ANSI escape codes -4. (optional) Metadata that you can pass to `preview_cmd` and `launch_cmd` as `{2}`. For example, this is used to specify a specific Desktop Action inside a .desktop file \ No newline at end of file +4. (optional) Metadata that you can pass to `preview_cmd` and `launch_cmd` as `{2}`. For example, this is used to specify a specific Desktop Action inside a .desktop file + +The `preview_cmd` renders the contents of the `fzf` preview panel. You can use the template variable `{1}` in your command, which will be substituted with the value of the selected item. + +The `launch_cmd` is fired when the user has selected one of the provider's entries. \ No newline at end of file diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index df538d9..0eb588a 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -22,7 +22,7 @@ CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/sway-launcher-desktop" # list_cmd,preview_cmd,launch_cmd declare -A PROVIDERS if [ -f "${CONFIG_DIR}/providers.conf" ]; then - PARSED=$( awk -F= ' + PARSED=$(awk -F= ' BEGINFILE{ provider=""; } /^\[.*\]/{sub("^\\[", "");sub("\\]$", "");provider=$0} /^(launch|list|preview)_cmd/{st = index($0,"=");providers[provider][$1] = substr($0,st+1)} @@ -39,8 +39,8 @@ if [ -f "${CONFIG_DIR}/providers.conf" ]; then }' "${CONFIG_DIR}/providers.conf") eval "$PARSED" else - PROVIDERS['desktop']="${0} list-entries${DEL}${0} describe-desktop '{1}'${DEL}${0} generate-command {1} {2}" - PROVIDERS['command']="${0} list-commands${DEL}${0} describe-command {1}${DEL}${0} command-line {1}" + PROVIDERS['desktop']="${0} list-entries${DEL}${0} describe-desktop '{1}'${DEL}${0} run-desktop '{1}' {2}" + PROVIDERS['command']="${0} list-commands${DEL}${0} describe-command {1}${DEL}${TERMINAL_COMMAND} {1}" fi touch "$HIST_FILE" @@ -143,7 +143,9 @@ function entries() { $@ "$HIST_FILE" -command='echo "nope"' # shellcheck disable=SC2086 readarray -d $'\034' -t PARAMS <<<${COMMAND_STR} -# COMMAND_STR is "\034" # shellcheck disable=SC2086 readarray -d ${DEL} -t PROVIDER_ARGS <<<${PROVIDERS[${PARAMS[1]}]} # Substitute {1}, {2} etc with the correct values COMMAND=${PROVIDER_ARGS[2]//\{1\}/${PARAMS[0]}} COMMAND=${COMMAND//\{2\}/${PARAMS[3]}} -# shellcheck disable=SC2086 -command=$(bash -c ${COMMAND}) -(exec setsid /bin/sh -c "$command" &) +(exec setsid /bin/sh -c "${COMMAND}" &) -- cgit v1.2.3