diff options
| author | Moritz Meißelbach <arbelzapf@gmail.com> | 2019-11-30 00:38:56 +0100 |
|---|---|---|
| committer | Moritz Meißelbach <arbelzapf@gmail.com> | 2019-11-30 00:38:56 +0100 |
| commit | 3429a175db5eb6a9ca9ab93c808b6ed102ab7393 (patch) | |
| tree | d8017c71b6bb46628a507c1487deb15dac4d7db8 | |
| parent | 9827852e967849714b9497c74543eb14a17606d3 (diff) | |
| download | sway-launcher-desktop-3429a175db5eb6a9ca9ab93c808b6ed102ab7393.tar.gz sway-launcher-desktop-3429a175db5eb6a9ca9ab93c808b6ed102ab7393.zip | |
Fix and improve usage of launch_cmd in providers
| -rw-r--r-- | README.md | 8 | ||||
| -rwxr-xr-x | sway-launcher-desktop.sh | 18 |
2 files changed, 14 insertions, 12 deletions
@@ -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() { $@ </dev/null # the empty stdin is needed in case no *.desktop files } - +function run-desktop() { + bash -c "$("${0}" generate-command "$@")" +} function generate-command() { # Define the search pattern that specifies the block to search for within the .desktop file PATTERN="^\\\\[Desktop Entry\\\\]" @@ -196,7 +198,7 @@ function generate-command() { } case "$1" in -describe | describe-desktop | describe-command | entries | list-entries | list-commands | command-line | generate-command | provide) +describe | describe-desktop | describe-command | entries | list-entries | list-commands | command-line | generate-command | run-desktop | provide) "$@" exit ;; @@ -238,15 +240,11 @@ fi printf '%s' "${HIST_LINES[@]}" | sort -nr >"$HIST_FILE" -command='echo "nope"' # shellcheck disable=SC2086 readarray -d $'\034' -t PARAMS <<<${COMMAND_STR} -# COMMAND_STR is "<string>\034<type>" # 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}" &) |
